diff --git a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs index 9181a65a9e5..7580109341b 100644 --- a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs +++ b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs @@ -13,6 +13,10 @@ public sealed partial class PlatformAccount public PlatformAccount(ThirdpartyPlatform platform) { Accounts = new ObservableCollection(); + FilteredAccounts = new ObservableCollection(); + + this.WhenAnyValue(x => x.SearchText) + .Subscribe(_ => ApplySearchFilter()); var platformSwitchers = Ioc.Get>(); FullName = platform.ToString(); @@ -37,7 +41,15 @@ public PlatformAccount(ThirdpartyPlatform platform) DeleteAccountCommand = ReactiveCommand.Create(async acc => { if (await platformSwitcher.DeleteAccountInfo(acc, this)) - Toast.Show(ToastIcon.Success, Strings.Success_DeletePlatformAccount__.Format(FullName, acc.DisplayName)); + { + ApplySearchFilter(); + + Toast.Show( + ToastIcon.Success, + Strings.Success_DeletePlatformAccount__.Format( + FullName, + acc.DisplayName)); + } }); SetAccountAvatarCommand = ReactiveCommand.Create(async acc => @@ -66,6 +78,7 @@ await FilePicker2.PickAsync((path) => return; acc.AliasName = text; platformSwitcher.ChangeUserRemark(acc); + ApplySearchFilter(); }); CopyCommand = ReactiveCommand.Create(async text => await Clipboard2.SetTextAsync(text)); @@ -80,6 +93,35 @@ await FilePicker2.PickAsync((path) => //LoadUsers(); } + void ApplySearchFilter() + { + var searchText = SearchText?.Trim(); + + IEnumerable accounts = Accounts; + + if (!string.IsNullOrWhiteSpace(searchText)) + { + accounts = Accounts.Where(account => + ContainsIgnoreCase(account.DisplayName, searchText) || + ContainsIgnoreCase(account.AccountName, searchText) || + ContainsIgnoreCase(account.AliasName, searchText)); + } + + FilteredAccounts.Clear(); + + foreach (var account in accounts) + { + FilteredAccounts.Add(account); + } + } + + static bool ContainsIgnoreCase(string? value, string searchText) + { + return value?.Contains( + searchText, + StringComparison.OrdinalIgnoreCase) == true; + } + public void LoadUsers() { Task2.InBackground(async () => @@ -89,6 +131,7 @@ public void LoadUsers() try { Accounts.Clear(); + ApplySearchFilter(); var users = await platformSwitcher.GetUsers(this, () => { if (Accounts.Any_Nullable()) @@ -103,7 +146,12 @@ public void LoadUsers() }); if (users.Any_Nullable()) - Accounts = new ObservableCollection(users.OrderByDescending(x => x.LastLoginTime)); + { + Accounts = new ObservableCollection( + users.OrderByDescending(x => x.LastLoginTime)); + } + + ApplySearchFilter(); } catch (Exception ex) { diff --git a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.props.cs b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.props.cs index ee7743fcb6a..22a8d80b752 100644 --- a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.props.cs +++ b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.props.cs @@ -7,6 +7,12 @@ public sealed partial class PlatformAccount : ReactiveObject [Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore] public ObservableCollection Accounts { get; set; } + [Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore] + public ObservableCollection FilteredAccounts { get; set; } + + [Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore] + public string? SearchText { get; set; } + [Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore] public bool IsEnable { get; set; } diff --git a/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Controls/AccountItems.axaml b/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Controls/AccountItems.axaml index 08bb049794a..03ea085f207 100644 --- a/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Controls/AccountItems.axaml +++ b/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Controls/AccountItems.axaml @@ -195,15 +195,15 @@ Text="{Binding Path=Res.Delete, Mode=OneWay, Source={x:Static s:ResourceService.Current}}" /> - + - + diff --git a/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Pages/GameAccountPage.axaml b/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Pages/GameAccountPage.axaml index 3e10d385716..2f730c2636d 100644 --- a/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Pages/GameAccountPage.axaml +++ b/src/BD.WTTS.Client.Plugins.GameAccount/UI/Views/Pages/GameAccountPage.axaml @@ -165,78 +165,90 @@ TabWidthMode="Equal" VerticalAlignment="Stretch"> - + + + + + + + + --> + + + + +