Skip to content

Commit

Permalink
feat(uwp): 搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
hal-wang committed May 16, 2024
1 parent d6979e5 commit efc4e64
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 215 deletions.
7 changes: 7 additions & 0 deletions src/Lavcode.Uwp/Lavcode.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
<Compile Include="Modules\FirstUse\ProviderSelectButton.xaml.cs">
<DependentUpon>ProviderSelectButton.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\Search\SearchBar.xaml.cs">
<DependentUpon>SearchBar.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\SqliteSync\SqliteSyncConstant.cs" />
<Compile Include="Modules\SqliteSync\Crypto\Aes.cs" />
<Compile Include="Modules\SqliteSync\Crypto\OperationType.cs" />
Expand Down Expand Up @@ -438,6 +441,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\Search\SearchBar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\Shell\BackSvg.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
289 changes: 172 additions & 117 deletions src/Lavcode.Uwp/Modules/PasswordCore/FolderList.xaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Lavcode.Uwp/Modules/PasswordCore/PasswordList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void PasswordList_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs
{
StrongReferenceMessenger.Default.Register<PasswordList, FolderItem, string>(this, "FolderSelected", (_, item) => FolderSelected(item));
StrongReferenceMessenger.Default.Register<PasswordList, FolderItem, string>(this, "PasswordAddOrEdited", (_, item) => PasswordAddOrEdited());
StrongReferenceMessenger.Default.Register<string, string>(this, "Search", async (_, searchText) => await VM.Search(searchText));
}

public PasswordListViewModel VM { get; } = ServiceProvider.Services.GetService<PasswordListViewModel>();
Expand Down
56 changes: 36 additions & 20 deletions src/Lavcode.Uwp/Modules/PasswordCore/PasswordListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,19 @@ public async Task Init(FolderItem folderItem)
{
SelectedPasswordItem = null;
}
PasswordItems.Clear();
if (folderItem == null)
{
PasswordItems.Clear();
return;
}

try
{
await foreach (var password in GetPasswordItems())
var passwords = await _passwordService.GetPasswords(_curFolder.Folder.Id);
PasswordItems.Clear();
foreach (var password in passwords)
{
PasswordItems.Add(password);
PasswordItems.Add(new PasswordItem(password));
}
}
catch (Exception ex)
Expand All @@ -91,38 +93,52 @@ public async Task Init(FolderItem folderItem)
}
}

private async IAsyncEnumerable<PasswordItem> GetPasswordItems()
public async Task Search(string searchText)
{
var passwords = await _passwordService.GetPasswords(_curFolder.Folder.Id);
foreach (var password in passwords)
if (string.IsNullOrEmpty(searchText))
{
PasswordItem passwordItem = null;
await TaskExtend.Run(() =>
await Init(_curFolder);
return;
}

try
{
var passwords = await _passwordService.GetPasswords();
passwords = passwords
.Where(p =>
p.Title.Contains(searchText)
|| p.Remark.Contains(searchText)
|| p.Value.Contains(searchText)
|| p.KeyValuePairs.Any(kvp => kvp.Key.Contains(searchText) || kvp.Value.Contains(searchText)))
.ToList();
PasswordItems.Clear();
foreach (var password in passwords)
{
passwordItem = new PasswordItem(password);
});
yield return passwordItem;
PasswordItems.Add(new PasswordItem(password));
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex);
}
}

#endregion

private void PasswordAddOrEdited(PasswordModel password)
{
if (_curFolder == null || _curFolder.Folder.Id != password.FolderId)
var existPassword = PasswordItems.Where((item) => item.Password.Id == password.Id).FirstOrDefault();
if (existPassword == null)
{
return;
}
if (_curFolder == null || _curFolder.Folder.Id != password.FolderId)
{
return;
}

var queryResult = PasswordItems.Where((item) => item.Password.Id == password.Id);
if (queryResult.Count() == 0)
{
PasswordItems.Add(new PasswordItem(password));
}
else
{
var existItem = queryResult.First();
existItem.Set(password);
existPassword.Set(password);
}
SelectedPasswordItem = PasswordItems.Where((item) => item.Password == password).First();
}
Expand Down
60 changes: 60 additions & 0 deletions src/Lavcode.Uwp/Modules/Search/SearchBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<UserControl
x:Class="Lavcode.Uwp.Modules.Search.SearchBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Lavcode.Uwp.Modules.Search"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtuc="using:Microsoft.Toolkit.Uwp.UI.Controls"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<Grid Height="48" Background="{ThemeResource PrimaryAcrylicBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>

<TextBox
x:Name="SearchTextBox"
Width="240"
Margin="20,0,0,5"
VerticalAlignment="Bottom"
CornerRadius="0"
Foreground="{ThemeResource ThemeForegroundBrush}"
PlaceholderText="搜索"
PreviewKeyDown="TextBox_PreviewKeyDown"
Text="{x:Bind SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Button
Grid.Column="1"
Height="48"
Margin="4,4,0,-4"
VerticalAlignment="Bottom"
Click="{x:Bind Search}"
Style="{ThemeResource EllipsisButton}">
<SymbolIcon Symbol="Find" />
</Button>
<Button
Grid.Column="2"
Height="48"
Margin="0,4,0,-4"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Click="{x:Bind Exit}"
Style="{ThemeResource EllipsisButton}">
<SymbolIcon Symbol="Cancel" />
</Button>
<Button
Grid.Column="3"
Height="48"
Margin="0,4,0,-4"
VerticalAlignment="Bottom"
Click="{x:Bind Search}"
Style="{ThemeResource EllipsisButton}">
<SymbolIcon Symbol="Refresh" />
</Button>
</Grid>
</UserControl>
67 changes: 67 additions & 0 deletions src/Lavcode.Uwp/Modules/Search/SearchBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Microsoft.Toolkit.Mvvm.Messaging;
using System;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Lavcode.Uwp.Modules.Search
{
public sealed partial class SearchBar : UserControl
{
public SearchBar()
{
this.InitializeComponent();
}

public bool IsSearchOpen
{
get { return (bool)GetValue(IsSearchOpenProperty); }
set { SetValue(IsSearchOpenProperty, value); }
}

// Using a DependencyProperty as the backing store for IsSearchOpen. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsSearchOpenProperty =
DependencyProperty.Register("IsSearchOpen", typeof(bool), typeof(SearchBar), new PropertyMetadata(false, OnIsSearchOpenChanged));

private static async void OnIsSearchOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
await Task.Delay(200);
(d as SearchBar)!.SearchTextBox.Focus(FocusState.Pointer);
}
}

public string SearchText
{
get { return (string)GetValue(SearchTextProperty); }
set { SetValue(SearchTextProperty, value); }
}

// Using a DependencyProperty as the backing store for SearchText. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SearchTextProperty =
DependencyProperty.Register("SearchText", typeof(string), typeof(SearchBar), new PropertyMetadata(string.Empty));


private void TextBox_PreviewKeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
switch (e.Key)
{
case Windows.System.VirtualKey.Enter:
Search();
break;
}
}

private void Exit()
{
IsSearchOpen = false;
StrongReferenceMessenger.Default.Send("", "Search");
}

private void Search()
{
StrongReferenceMessenger.Default.Send(SearchText, "Search");
}
}
}
59 changes: 33 additions & 26 deletions src/Lavcode.Uwp/Modules/Shell/Commands.xaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
<!--
顶部的菜单
-->
-->

<UserControl
x:Class="Lavcode.Uwp.Modules.Shell.Commands"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:huc="using:HTools.Uwp.Controls"
xmlns:lumg="using:Lavcode.Uwp.Modules.Git"
mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400">

<StackPanel Grid.Column="2"
Orientation="Horizontal">
<huc:PathButton Data="M881 512c0-52.4 32.9-96.8 79-114.5-11-43.2-28-83.9-50.2-121.3C864.6 296.3 810 288.1 773 251c-37-37-45.2-91.7-25.1-136.8C710.4 92 669.7 75 626.5 64c-17.8 46.1-62.2 79-114.5 79-52.4 0-96.8-32.9-114.5-79-43.2 11-83.9 28-121.3 50.2 20.1 45.2 11.9 99.8-25.1 136.8-37 37-91.7 45.2-136.8 25.2C92 313.6 75 354.3 64 397.5c46.1 17.8 79 62.2 79 114.5 0 52.4-32.9 96.8-79 114.5 11 43.2 28 83.9 50.2 121.3C159.4 727.7 214 735.9 251 773c37 37 45.2 91.7 25.1 136.8C313.6 932 354.3 949 397.5 960c17.8-46.1 62.2-79 114.5-79 52.4 0 96.8 32.9 114.5 79 43.2-11 83.9-28 121.3-50.2-20.1-45.2-11.9-99.8 25.1-136.8 37-37 91.7-45.2 136.8-25.2C932 710.4 949 669.7 960 626.5c-46.1-17.7-79-62.1-79-114.5zM512 635c-67.9 0-123-55.1-123-123s55.1-123 123-123 123 55.1 123 123-55.1 123-123 123z"
Visibility="{x:Bind IsLaunchFile,Mode=OneTime,Converter={StaticResource BooleanConverter},ConverterParameter=T}"
ToolTipService.ToolTip="设置"
Click="SettingBtn_Click"/>
d:DesignWidth="400"
mc:Ignorable="d">

<huc:PathButton Data="M524.8 122.368c-58.88 48.128-182.272 115.2-270.848 179.712-1.024 0.512-2.048 4.096-3.072 5.12-10.752 6.144-15.36 22.528-72.192 22.528h-111.104c-28.672 0-46.08 13.824-46.08 44.544v273.92c0 30.72 16.384 46.08 46.08 46.08h111.616c56.832 0 61.44 16.896 71.68 22.528 1.024 0.512 2.048 4.096 3.072 4.608 86.016 64.512 209.92 137.216 270.848 183.296 18.432 13.824 79.36 38.4 79.36-47.616v-691.712c0-84.992-61.44-57.856-79.36-43.008zM932.352 558.592h-195.072c-25.6 0-46.08-20.48-46.08-46.08s20.48-46.08 46.08-46.08h195.072c25.6 0 46.08 20.48 46.08 46.08s-20.48 46.08-46.08 46.08zM904.704 248.832l-179.2 77.312c-23.552 10.24-50.688-0.512-60.416-24.064s0.512-50.688 24.064-60.416l179.2-77.312c23.552-10.24 50.688 0.512 60.416 24.064 10.24 23.552-0.512 50.688-24.064 60.416zM904.704 776.704l-179.2-77.312c-23.552-10.24-50.688 0.512-60.416 24.064-10.24 23.552 0.512 50.688 24.064 60.416l179.2 77.312c23.552 10.24 50.688-0.512 60.416-24.064s-0.512-50.688-24.064-60.416z"
Margin="16 0 0 0"
ToolTipService.ToolTip="通知"
Click="NoticeBtn_Click"/>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<huc:PathButton
Click="SearchBtn_Click"
Data="M930.56 749.44l-160-103.36A400.96 400.96 0 1 0 646.08 768l103.36 160a133.44 133.44 0 0 0 39.36 39.36 130.88 130.88 0 0 0 141.76-220.48zM432 704a272 272 0 1 1 272-272 272 272 0 0 1-272 272z"
ToolTipService.ToolTip="搜索"
Visibility="{x:Bind IsSearchVisible, Mode=OneWay, Converter={StaticResource BooleanConverter}}" />
<huc:PathButton
Margin="16,0,0,0"
Click="SettingBtn_Click"
Data="M881 512c0-52.4 32.9-96.8 79-114.5-11-43.2-28-83.9-50.2-121.3C864.6 296.3 810 288.1 773 251c-37-37-45.2-91.7-25.1-136.8C710.4 92 669.7 75 626.5 64c-17.8 46.1-62.2 79-114.5 79-52.4 0-96.8-32.9-114.5-79-43.2 11-83.9 28-121.3 50.2 20.1 45.2 11.9 99.8-25.1 136.8-37 37-91.7 45.2-136.8 25.2C92 313.6 75 354.3 64 397.5c46.1 17.8 79 62.2 79 114.5 0 52.4-32.9 96.8-79 114.5 11 43.2 28 83.9 50.2 121.3C159.4 727.7 214 735.9 251 773c37 37 45.2 91.7 25.1 136.8C313.6 932 354.3 949 397.5 960c17.8-46.1 62.2-79 114.5-79 52.4 0 96.8 32.9 114.5 79 43.2-11 83.9-28 121.3-50.2-20.1-45.2-11.9-99.8 25.1-136.8 37-37 91.7-45.2 136.8-25.2C932 710.4 949 669.7 960 626.5c-46.1-17.7-79-62.1-79-114.5zM512 635c-67.9 0-123-55.1-123-123s55.1-123 123-123 123 55.1 123 123-55.1 123-123 123z"
ToolTipService.ToolTip="设置"
Visibility="{x:Bind IsLaunchFile, Mode=OneTime, Converter={StaticResource BooleanConverter}, ConverterParameter=T}" />
<huc:PathButton
Margin="16,0,0,0"
Click="NoticeBtn_Click"
Data="M524.8 122.368c-58.88 48.128-182.272 115.2-270.848 179.712-1.024 0.512-2.048 4.096-3.072 5.12-10.752 6.144-15.36 22.528-72.192 22.528h-111.104c-28.672 0-46.08 13.824-46.08 44.544v273.92c0 30.72 16.384 46.08 46.08 46.08h111.616c56.832 0 61.44 16.896 71.68 22.528 1.024 0.512 2.048 4.096 3.072 4.608 86.016 64.512 209.92 137.216 270.848 183.296 18.432 13.824 79.36 38.4 79.36-47.616v-691.712c0-84.992-61.44-57.856-79.36-43.008zM932.352 558.592h-195.072c-25.6 0-46.08-20.48-46.08-46.08s20.48-46.08 46.08-46.08h195.072c25.6 0 46.08 20.48 46.08 46.08s-20.48 46.08-46.08 46.08zM904.704 248.832l-179.2 77.312c-23.552 10.24-50.688-0.512-60.416-24.064s0.512-50.688 24.064-60.416l179.2-77.312c23.552-10.24 50.688 0.512 60.416 24.064 10.24 23.552-0.512 50.688-24.064 60.416zM904.704 776.704l-179.2-77.312c-23.552-10.24-50.688 0.512-60.416 24.064-10.24 23.552 0.512 50.688 24.064 60.416l179.2 77.312c23.552 10.24 50.688-0.512 60.416-24.064s-0.512-50.688-24.064-60.416z"
ToolTipService.ToolTip="通知" />

<huc:PathButton Data="M512 12.672c-282.88 0-512 229.248-512 512 0 226.261333 146.688 418.133333 350.08 485.76 25.6 4.821333 34.986667-11.008 34.986667-24.618667 0-12.16-0.426667-44.373333-0.64-87.04-142.421333 30.890667-172.458667-68.693333-172.458667-68.693333C188.672 770.986667 155.008 755.2 155.008 755.2c-46.378667-31.744 3.584-31.104 3.584-31.104 51.413333 3.584 78.421333 52.736 78.421333 52.736 45.653333 78.293333 119.850667 55.68 149.12 42.581333 4.608-33.109333 17.792-55.68 32.426667-68.48-113.706667-12.8-233.216-56.832-233.216-253.013333 0-55.893333 19.84-101.546667 52.693333-137.386667-5.76-12.928-23.04-64.981333 4.48-135.509333 0 0 42.88-13.738667 140.8 52.48 40.96-11.392 84.48-17.024 128-17.28 43.52 0.256 87.04 5.888 128 17.28 97.28-66.218667 140.16-52.48 140.16-52.48 27.52 70.528 10.24 122.581333 5.12 135.509333 32.64 35.84 52.48 81.493333 52.48 137.386667 0 196.693333-119.68 240-233.6 252.586667 17.92 15.36 34.56 46.762667 34.56 94.72 0 68.522667-0.64 123.562667-0.64 140.202666 0 13.44 8.96 29.44 35.2 24.32C877.44 942.592 1024 750.592 1024 524.672c0-282.752-229.248-512-512-512"
Margin="16 0 0 0"
ToolTipService.ToolTip="GitHub">
<huc:PathButton
Margin="16,0,0,0"
Data="M512 12.672c-282.88 0-512 229.248-512 512 0 226.261333 146.688 418.133333 350.08 485.76 25.6 4.821333 34.986667-11.008 34.986667-24.618667 0-12.16-0.426667-44.373333-0.64-87.04-142.421333 30.890667-172.458667-68.693333-172.458667-68.693333C188.672 770.986667 155.008 755.2 155.008 755.2c-46.378667-31.744 3.584-31.104 3.584-31.104 51.413333 3.584 78.421333 52.736 78.421333 52.736 45.653333 78.293333 119.850667 55.68 149.12 42.581333 4.608-33.109333 17.792-55.68 32.426667-68.48-113.706667-12.8-233.216-56.832-233.216-253.013333 0-55.893333 19.84-101.546667 52.693333-137.386667-5.76-12.928-23.04-64.981333 4.48-135.509333 0 0 42.88-13.738667 140.8 52.48 40.96-11.392 84.48-17.024 128-17.28 43.52 0.256 87.04 5.888 128 17.28 97.28-66.218667 140.16-52.48 140.16-52.48 27.52 70.528 10.24 122.581333 5.12 135.509333 32.64 35.84 52.48 81.493333 52.48 137.386667 0 196.693333-119.68 240-233.6 252.586667 17.92 15.36 34.56 46.762667 34.56 94.72 0 68.522667-0.64 123.562667-0.64 140.202666 0 13.44 8.96 29.44 35.2 24.32C877.44 942.592 1024 750.592 1024 524.672c0-282.752-229.248-512-512-512"
ToolTipService.ToolTip="GitHub">
<huc:PathButton.Flyout>
<Flyout Opened="GitFlyout_Opened">
<lumg:GitInfo x:Name="GitInfo"
x:DeferLoadStrategy="Lazy"/>
<lumg:GitInfo x:Name="GitInfo" x:DeferLoadStrategy="Lazy" />
</Flyout>
</huc:PathButton.Flyout>
</huc:PathButton>

<huc:PathButton Data="M771.84 296.96a288 288 0 0 0-531.2 31.36 282.24 282.24 0 0 0 48 561.28h448a298.24 298.24 0 0 0 35.84-592zM416 478.08v276.48a22.4 22.4 0 0 1-44.8 0V478.08L297.6 551.68a21.76 21.76 0 1 1-30.72-30.72L384 407.68a18.56 18.56 0 0 1 27.52 0l109.44 113.28a21.76 21.76 0 1 1-30.72 30.72z m341.12 179.84L640 768a18.56 18.56 0 0 1-27.52 0l-109.44-110.72a21.76 21.76 0 1 1 30.72-30.72L608 704V424.32a22.4 22.4 0 1 1 44.8 0V704l74.24-74.24a21.76 21.76 0 1 1 30.72 30.72z"
Visibility="{x:Bind IsSyncVisible,Mode=OneTime,Converter={StaticResource BooleanConverter}}"
Margin="16 0 0 0"
ToolTipService.ToolTip="云同步"
Click="Sync_Click"/>
<huc:PathButton
Margin="16,0,0,0"
Click="Sync_Click"
Data="M771.84 296.96a288 288 0 0 0-531.2 31.36 282.24 282.24 0 0 0 48 561.28h448a298.24 298.24 0 0 0 35.84-592zM416 478.08v276.48a22.4 22.4 0 0 1-44.8 0V478.08L297.6 551.68a21.76 21.76 0 1 1-30.72-30.72L384 407.68a18.56 18.56 0 0 1 27.52 0l109.44 113.28a21.76 21.76 0 1 1-30.72 30.72z m341.12 179.84L640 768a18.56 18.56 0 0 1-27.52 0l-109.44-110.72a21.76 21.76 0 1 1 30.72-30.72L608 704V424.32a22.4 22.4 0 1 1 44.8 0V704l74.24-74.24a21.76 21.76 0 1 1 30.72 30.72z"
ToolTipService.ToolTip="云同步"
Visibility="{x:Bind IsSyncVisible, Mode=OneTime, Converter={StaticResource BooleanConverter}}" />
</StackPanel>
</UserControl>
Loading

0 comments on commit efc4e64

Please sign in to comment.