Skip to content

Commit

Permalink
optimize ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Jan 5, 2024
1 parent af62589 commit 9b041f2
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 105 deletions.
17 changes: 16 additions & 1 deletion src/LipUI/Language/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<value>组件</value>
</data>
<data name="modules$title$propertiesEditor" xml:space="preserve">
<value>properties editor</value>
<value>服务器配置</value>
</data>
<data name="navigationView$home.Content" xml:space="preserve">
<value>主页</value>
Expand Down Expand Up @@ -204,6 +204,21 @@
<data name="server$editor$confirm" xml:space="preserve">
<value>确认</value>
</data>
<data name="serverEditView$placeholder$desc.PlaceholderText" xml:space="preserve">
<value>描述</value>
</data>
<data name="serverEditView$placeholder$name.PlaceholderText" xml:space="preserve">
<value>名称</value>
</data>
<data name="serverEditView$placeholder$version.PlaceholderText" xml:space="preserve">
<value>版本</value>
</data>
<data name="serverEditView$placeholder$workingDir.PlaceholderText" xml:space="preserve">
<value>工作目录</value>
</data>
<data name="serverSelection$existed" xml:space="preserve">
<value>服务器路径已存在!</value>
</data>
<data name="startServer.Text" xml:space="preserve">
<value>启动服务器</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/LipUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ void task(object? sender, object e)
mre.Reset();
DispatcherQueue.TryEnqueue(() =>
{
GlobalInfoBar.IsOpen = false;
InfoBarPopOutStoryboard.Begin();

void task(object? sender, object e)
{
InfoBarPopOutStoryboard.Completed -= task;
GlobalInfoBar.IsOpen = false;
mre.Set();
}
InfoBarPopOutStoryboard.Completed += task;
Expand Down
3 changes: 3 additions & 0 deletions src/LipUI/Pages/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static async ValueTask ShowInfoBarAsync(
TimeSpan interval = default,
UIElement? barContent = null)
{
if (interval == default)
interval = TimeSpan.FromSeconds(3);

if (MainWindow is not null)
await MainWindow.ShowInfoBarAsync(title, message, severity, interval, barContent);
}
Expand Down
6 changes: 3 additions & 3 deletions src/LipUI/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@

<StackPanel
Grid.Row="0"
Spacing="8"
Spacing="16"
HorizontalAlignment="Center"
VerticalAlignment="Center">

<Image
Height="64"
Width="64"
Height="84"
Width="84"
x:Name="ServerIconImage"
Loading="ServerIconImage_Loading"/>

Expand Down
12 changes: 7 additions & 5 deletions src/LipUI/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;

// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -37,7 +38,7 @@ private async void RefreshIcon()
}

private void SelectServerButton_Click(object sender, RoutedEventArgs e)
=> Frame.Navigate(typeof(SelectServerPage), () => { DispatcherQueue.TryEnqueue(() => { RefreshIcon(); }); });
=> Frame.Navigate(typeof(ServerSelectionPage), () => { DispatcherQueue.TryEnqueue(() => { RefreshIcon(); }); });

private void Page_Loaded(object sender, RoutedEventArgs e)
=> ShowLipInstallerPageIfNotExist();
Expand All @@ -55,9 +56,10 @@ private void ShowLipInstallerPageIfNotExist()
Content = new LipInstallerView()
};

DispatcherQueue.TryEnqueue(async () =>
Task.Run(() =>
{
await dialog.ShowAsync();
Task.Delay(100);
DispatcherQueue.TryEnqueue(async () => await dialog.ShowAsync());
});
}

Expand Down Expand Up @@ -102,7 +104,7 @@ private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
BackButton.IsEnabled = ContentFrame.CanGoBack;
var type = e.Content.GetType();

DispatcherQueue.TryEnqueue(() =>
DispatcherQueue.TryEnqueue(async () =>
{
try
{
Expand All @@ -111,7 +113,7 @@ private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
}
catch (Exception ex)
{
Helpers.ShowInfoBar(ex);
await Helpers.ShowInfoBarAsync(ex);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
if (Server is null)
{
await Task.Delay(500);
await ShowInfoBarAsync("propertiesEditor$nullServerPath".GetLocalized(), null, InfoBarSeverity.Error, default, null);
await ShowInfoBarAsync("propertiesEditor$nullServerPath".GetLocalized(), null, InfoBarSeverity.Error);
Frame.GoBack();
return;
};

Expand All @@ -76,7 +77,7 @@ private async ValueTask SaveAsync()
try
{
await ShowInfoBarAsync(
"propertiesEditor$saving",
"propertiesEditor$saving".GetLocalized(),
null,
InfoBarSeverity.Informational,
default,
Expand Down Expand Up @@ -105,11 +106,11 @@ await ShowInfoBarAsync(
}

await Task.Delay(500);
ShowInfoBar("propertiesEditor$saveCompleted".GetLocalized(), null, InfoBarSeverity.Success);
await ShowInfoBarAsync("propertiesEditor$saveCompleted".GetLocalized(), null, InfoBarSeverity.Success);
}
catch (Exception ex)
{
ShowInfoBar(ex);
await ShowInfoBarAsync(ex);
}
}

Expand Down
89 changes: 78 additions & 11 deletions src/LipUI/Pages/IndexPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using static LipUI.Protocol.LipIndex.LipIndexData;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -18,30 +22,41 @@ namespace LipUI.Pages;
public sealed partial class IndexPage : Page
{

private LipIndex? LipIndex { get; set; }
private LipIndex? lipIndex;

public IndexPage()
{
InitializeComponent();
}

private void ReloadLipIndex()
private void ReloadLipIndex(IEnumerable<LipToothItem>? items = null)
{
TeethScrollViewer.Content = new ProgressRing();
ToothListView.Items.Clear();

DispatcherQueue.TryEnqueue(async () =>
{
LipIndex = await RequestLipIndexAsync(Main.Config.Settings.LipIndexApiKey);
TeethScrollViewer.Content = new ProgressRing();
ToothListView.Items.Clear();

if (items is null)
{
lipIndex = await RequestLipIndexAsync(Main.Config.Settings.LipIndexApiKey);
items = lipIndex.Data.Items;
}

foreach (var item in LipIndex.Data.Items)
var handler = AuthorButton_Click;
foreach (var item in items)
{
ToothListView.Items.Add(new LipIndexToothView(item));
ToothListView.Items.Add(new LipIndexToothView(item, handler));
}
TeethScrollViewer.Content = ToothListView;
});
}

private void AuthorButton_Click(string author)
{
DispatcherQueue.TryEnqueue(() => SuggestBox.Text = author);
QuerySubmitted(author);
}

private void IndexPage_Loaded(object sender, RoutedEventArgs e)
=> ReloadLipIndex();

Expand Down Expand Up @@ -75,13 +90,62 @@ private static async ValueTask<LipIndex> RequestLipIndexAsync(string lipApiUrl)

private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason is not AutoSuggestionBoxTextChangeReason.UserInput)
return;

var str = sender.Text.ToLower();

Task.Run(async () =>
{
try
{
lock (lipIndex!.Data.Items)
{
var dataset = from tooth in lipIndex.Data.Items
where tooth.Name.ToLower().Contains(str)
|| tooth.Author.ToLower().Contains(str)
select tooth.Name;

DispatcherQueue.TryEnqueue(() => sender.ItemsSource = dataset);
}
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
}
});
}

private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
=> QuerySubmitted(args.QueryText);

}
private void QuerySubmitted(string queryText)
=> Task.Run(async () =>
{
try
{
var query = queryText.ToLower();

if (string.IsNullOrWhiteSpace(query))
{
ReloadLipIndex();
return;
}
lock (lipIndex!.Data.Items)
{
var selectedTeeth = from tooth in lipIndex.Data.Items
where tooth.Name.ToLower().Contains(query)
|| tooth.Author.ToLower().Contains(query)
select tooth;

ReloadLipIndex(selectedTeeth);
}
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
}
});

private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
Expand All @@ -105,5 +169,8 @@ private void ToothListView_ItemClick(object sender, ItemClickEventArgs e)
}

private void ReloadPackageButton_Click(object sender, RoutedEventArgs e)
=> ReloadLipIndex();
{
SuggestBox.Text = null;
ReloadLipIndex();
}
}
Loading

0 comments on commit 9b041f2

Please sign in to comment.