diff --git a/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.cs b/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.cs index 5fc8ffd0e6a..a6946a3d5eb 100644 --- a/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.cs @@ -5,6 +5,9 @@ using BD.WTTS.UI.Views.Pages; using WinAuth; using AngleSharp.Text; +using Avalonia.Controls; +using SteamKit2.Authentication; +using BD.WTTS.UI.Views.Controls; namespace BD.WTTS.UI.ViewModels; @@ -17,23 +20,56 @@ public sealed partial class AuthenticatorHomePageViewModel : ViewModelBase string? _currentPassword; //DateTime _initializeTime; + readonly Dictionary dictPinYinArray = new(); + + Func PredicateName(string? serachText) + { + return s => + { + if (s == null) + return false; + if (string.IsNullOrEmpty(serachText)) + return true; + if (s.AuthName.Contains(serachText, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + var pinyinArray = Pinyin.GetPinyin(s.AuthName, dictPinYinArray); + if (Pinyin.SearchCompare(serachText, s.AuthName, pinyinArray)) + { + return true; + } + + return false; + }; + } public AuthenticatorHomePageViewModel() { - Auths = new(); - - this.WhenAnyValue(v => v.Auths) - .Subscribe(items => items? - .ToObservableChangeSet() - .AutoRefresh(x => x.IsSelected) - .WhenPropertyChanged(x => x.IsSelected, false) - .Subscribe(s => - { - if (s.Value) - SelectedAuth = s.Sender; - else - SelectedAuth = null; - })); + AuthSource = new(t => t.AuthData.Id); + + //this.WhenAnyValue(v => v.Auths) + // .Subscribe(items => items? + // .ToObservableChangeSet() + // .AutoRefresh(x => x.IsSelected) + // .WhenPropertyChanged(x => x.IsSelected, false) + // .Subscribe(s => + // { + // if (s.Value) + // SelectedAuth = s.Sender; + // else + // SelectedAuth = null; + // })); + + var textFilter = this.WhenAnyValue(x => x.SearchText).Select(PredicateName); + + this.AuthSource + .Connect() + .Filter(textFilter) + .ObserveOn(RxApp.MainThreadScheduler) + .Sort(SortExpressionComparer.Ascending(x => x.AuthData.Index).ThenBy(x => x.AuthName)) + .Bind(out _Auths) + .Subscribe(); } public async void Initialize() @@ -50,7 +86,7 @@ public async void Initialize() //_initializeTime = DateTime.Now; - Auths.Clear(); + AuthSource.Clear(); var sourceList = await AuthenticatorHelper.GetAllSourceAuthenticatorAsync(); if (sourceList.Any_Nullable()) @@ -78,10 +114,10 @@ public async void Initialize() foreach (var item in list) { - Auths.Add(new AuthenticatorItemModel(item)); + AuthSource.AddOrUpdate(new AuthenticatorItemModel(item)); } - var trayMenus = Auths.Select(s => new TrayMenuItem + var trayMenus = AuthSource.Items.Select(s => new TrayMenuItem { Name = s.AuthName, Command = ReactiveCommand.Create(async () => @@ -234,7 +270,7 @@ public void ReLockAuthenticator() return; } - Auths.Clear(); + AuthSource.Clear(); IsVerificationPass = false; } @@ -446,7 +482,7 @@ public async Task DeleteAuthAsync(object sender) Toast.Show(ToastIcon.Warning, AppResources.Error_DelCloudData); } AuthenticatorHelper.DeleteAuth(authenticatorItemModel.AuthData); - Auths.Remove(authenticatorItemModel); + AuthSource.Remove(authenticatorItemModel); Toast.Show(ToastIcon.Success, AppResources.Success_LocalAuthDelSuccessful); } } @@ -569,7 +605,7 @@ public async Task AuthenticatorIndexMoveUp(object sender) Toast.Show(ToastIcon.Error, AppResources.Auth_Sync_MoveError); return; } - Auths.Move(index, index - 1); + //Auths.Move(index, index - 1); } public async Task AuthenticatorIndexMoveDown(object sender) @@ -590,7 +626,7 @@ public async Task AuthenticatorIndexMoveDown(object sender) Toast.Show(ToastIcon.Error, AppResources.Auth_Sync_MoveError); return; } - Auths.Move(index, index + 1); + //Auths.Move(index, index + 1); } public async Task AuthenticatorIndexSticky(object sender) @@ -611,9 +647,8 @@ public async Task AuthenticatorIndexSticky(object sender) return; } var tmp = Auths.OrderBy(a => a.AuthData.Index).ToList(); - Auths.Clear(); - foreach (var item in tmp) - Auths.Add(item); + AuthSource.Clear(); + AuthSource.AddOrUpdate(tmp); } public async Task DefaultExport(object sender) diff --git a/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.props.cs b/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.props.cs index e7f16cad6f4..ef2ea61aba6 100644 --- a/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.props.cs +++ b/src/BD.WTTS.Client.Plugins.Authenticator/UI/ViewModels/AuthenticatorHomePageViewModel.props.cs @@ -7,11 +7,17 @@ public partial class AuthenticatorHomePageViewModel [Reactive] public bool IsLoading { get; set; } - [Reactive] - public ObservableCollection Auths { get; set; } + private SourceCache AuthSource; - [Reactive] - public AuthenticatorItemModel? SelectedAuth { get; set; } + private readonly ReadOnlyObservableCollection? _Auths; + + public ReadOnlyObservableCollection? Auths => _Auths; + + //[Reactive] + //public ObservableCollection Auths { get; set; } = []; + + //[Reactive] + //public AuthenticatorItemModel? SelectedAuth { get; set; } [Reactive] public bool HasPasswordEncrypt { get; set; } = false; @@ -21,4 +27,7 @@ public partial class AuthenticatorHomePageViewModel [Reactive] public bool IsVerificationPass { get; set; } + + [Reactive] + public string? SearchText { get; set; } } \ No newline at end of file diff --git a/src/BD.WTTS.Client.Plugins.Authenticator/UI/Views/Pages/AuthenticatorHomePage.axaml b/src/BD.WTTS.Client.Plugins.Authenticator/UI/Views/Pages/AuthenticatorHomePage.axaml index e6b975e032e..57e009f7b49 100644 --- a/src/BD.WTTS.Client.Plugins.Authenticator/UI/Views/Pages/AuthenticatorHomePage.axaml +++ b/src/BD.WTTS.Client.Plugins.Authenticator/UI/Views/Pages/AuthenticatorHomePage.axaml @@ -161,6 +161,18 @@ + + + + (); - if (IdleSequentital == IdleSequentital.Default) - appid_sorts = Badges.Select(s => s.AppId); - else + switch (IdleSequentital) { - switch (IdleSequentital) - { - case IdleSequentital.LeastCards: - appid_sorts = Badges.OrderBy(o => o.CardsRemaining).Select(s => s.AppId); - break; - case IdleSequentital.Mostcards: - appid_sorts = Badges.OrderByDescending(o => o.CardsRemaining).Select(s => s.AppId); - break; - case IdleSequentital.Mostvalue: - appid_sorts = Badges.OrderByDescending(o => o.RegularAvgPrice).Select(s => s.AppId); - break; - default: - break; - } + case IdleSequentital.LeastCards: + appid_sorts = Badges.OrderBy(o => o.CardsRemaining).Select(s => s.AppId); + break; + case IdleSequentital.Mostcards: + appid_sorts = Badges.OrderByDescending(o => o.CardsRemaining).Select(s => s.AppId); + break; + case IdleSequentital.Mostvalue: + appid_sorts = Badges.OrderByDescending(o => o.RegularAvgPrice).Select(s => s.AppId); + break; + default: + appid_sorts = Badges.Select(s => s.AppId); + break; } + + //不应该使用 SteamConnectService 的 apps var apps = SteamConnectService.Current.SteamApps.Items .Where(x => appid_sorts.Contains((int)x.AppId)) .OrderBy(o => appid_sorts.ToList().FindIndex(x => x == o.AppId)) diff --git a/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.props.cs b/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.props.cs index 21f359395e8..34d3383a730 100644 --- a/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.props.cs +++ b/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.props.cs @@ -37,7 +37,13 @@ public sealed partial class IdleCardPageViewModel /// 用户徽章和卡片数据 /// [Reactive] - private ObservableCollection Badges { get; set; } = new(); + public ObservableCollection Badges { get; set; } = new(); + + [Reactive] + public int TotalCardsRemaining { get; set; } + + [Reactive] + public decimal TotalCardsAvgPrice { get; set; } /// /// 当前挂卡游戏 diff --git a/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/Views/Pages/IdleCardPage.axaml b/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/Views/Pages/IdleCardPage.axaml index bc3fe1afaf5..e49788849d0 100644 --- a/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/Views/Pages/IdleCardPage.axaml +++ b/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/Views/Pages/IdleCardPage.axaml @@ -18,143 +18,174 @@ - + + + + + + + + - --> + + + + - - - - - - - - - - - - - - - - - - -