Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public sealed partial class PlatformAccount
public PlatformAccount(ThirdpartyPlatform platform)
{
Accounts = new ObservableCollection<IAccount>();
FilteredAccounts = new ObservableCollection<IAccount>();

this.WhenAnyValue(x => x.SearchText)
.Subscribe(_ => ApplySearchFilter());
var platformSwitchers = Ioc.Get<IEnumerable<IPlatformSwitcher>>();

FullName = platform.ToString();
Expand All @@ -37,7 +41,15 @@ public PlatformAccount(ThirdpartyPlatform platform)
DeleteAccountCommand = ReactiveCommand.Create<IAccount>(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<IAccount>(async acc =>
Expand Down Expand Up @@ -66,6 +78,7 @@ await FilePicker2.PickAsync((path) =>
return;
acc.AliasName = text;
platformSwitcher.ChangeUserRemark(acc);
ApplySearchFilter();
});

CopyCommand = ReactiveCommand.Create<string>(async text => await Clipboard2.SetTextAsync(text));
Expand All @@ -80,6 +93,35 @@ await FilePicker2.PickAsync((path) =>
//LoadUsers();
}

void ApplySearchFilter()
{
var searchText = SearchText?.Trim();

IEnumerable<IAccount> 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 () =>
Expand All @@ -89,6 +131,7 @@ public void LoadUsers()
try
{
Accounts.Clear();
ApplySearchFilter();
var users = await platformSwitcher.GetUsers(this, () =>
{
if (Accounts.Any_Nullable())
Expand All @@ -103,7 +146,12 @@ public void LoadUsers()
});

if (users.Any_Nullable())
Accounts = new ObservableCollection<IAccount>(users.OrderByDescending(x => x.LastLoginTime));
{
Accounts = new ObservableCollection<IAccount>(
users.OrderByDescending(x => x.LastLoginTime));
}

ApplySearchFilter();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public sealed partial class PlatformAccount : ReactiveObject
[Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore]
public ObservableCollection<IAccount> Accounts { get; set; }

[Reactive, S_JsonIgnore, MP2Ignore, N_JsonIgnore]
public ObservableCollection<IAccount> 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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@
Text="{Binding Path=Res.Delete, Mode=OneWay, Source={x:Static s:ResourceService.Current}}" />
</ui:FAMenuFlyout>
</UserControl.Resources>
<ScrollViewer>
<ScrollViewer Margin="0,8,0,0">
<ScrollViewer.GestureRecognizers>
<ScrollGestureRecognizer CanHorizontallyScroll="True" CanVerticallyScroll="True" />
</ScrollViewer.GestureRecognizers>
<spp:ContentLoader
IsLoading="{Binding IsLoading}"
IsShowNoResultText="{Binding !!!Accounts.Count, Mode=OneWay}"
IsShowNoResultText="{Binding !!!FilteredAccounts.Count, Mode=OneWay}"
NoResultMessage="{Binding Path=Res.UserChange_NoUserTip, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<ItemsControl Grid.Row="1" ItemsSource="{Binding Accounts}">
<ItemsControl ItemsSource="{Binding FilteredAccounts}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,78 +165,90 @@
TabWidthMode="Equal"
VerticalAlignment="Stretch">
<ui:FATabView.TabStripFooter>
<Button
Content="&#xE710;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
HorizontalAlignment="Left"
Theme="{StaticResource TabViewButtonStyle}"
VerticalAlignment="Center">
<Button.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedLeft">
<MenuItem
Header="{Binding Path=Res.AddPlatform, Mode=OneWay, Source={x:Static s:ResourceService.Current}}"
IsVisible="{Binding !!AddGamePlatforms.Count}"
ItemsSource="{Binding AddGamePlatforms}">
<MenuItem.Styles>
<Style Selector="MenuItem" x:DataType="spp:PlatformAccount">
<Setter Property="Header" Value="{Binding FullName}" />
<Setter Property="Icon">
<Setter.Value>
<Template>
<Grid ColumnDefinitions="Auto,*,Auto">
<Button
Grid.Column="0"
Content="&#xE710;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
HorizontalAlignment="Left"
Theme="{StaticResource TabViewButtonStyle}"
VerticalAlignment="Center">
<Button.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedLeft">
<MenuItem
Header="{Binding Path=Res.AddPlatform, Mode=OneWay, Source={x:Static s:ResourceService.Current}}"
IsVisible="{Binding !!AddGamePlatforms.Count}"
ItemsSource="{Binding AddGamePlatforms}">
<MenuItem.Styles>
<Style Selector="MenuItem" x:DataType="spp:PlatformAccount">
<Setter Property="Header" Value="{Binding FullName}" />
<Setter Property="Icon">
<Setter.Value>
<Template>
<PathIcon Data="{Binding Icon, Converter={StaticResource ResourceKeyValueConverter}}" />
</Template>
</Setter.Value>
</Setter>
<Setter Property="Command" Value="{Binding $parent[spp:PageBase].((spp:GameAccountPageViewModel)DataContext).AddPlatformCommand}" />
<Setter Property="CommandParameter" Value="{Binding}" />
</Style>
</MenuItem.Styles>
<!--<MenuItem.DataTemplates>
<DataTemplate DataType="{x:Type spp:PlatformAccount}">
<MenuItem
Command="{Binding $parent[spp:PageBase].((spp:GameAccountPageViewModel)DataContext).AddPlatformCommand}"
CommandParameter="{Binding}"
Header="{Binding FullName}">
<MenuItem.Icon>
<PathIcon Data="{Binding Icon, Converter={StaticResource ResourceKeyValueConverter}}" />
</Template>
</Setter.Value>
</Setter>
<Setter Property="Command" Value="{Binding $parent[spp:PageBase].((spp:GameAccountPageViewModel)DataContext).AddPlatformCommand}" />
<Setter Property="CommandParameter" Value="{Binding}" />
</Style>
</MenuItem.Styles>
<!--<MenuItem.DataTemplates>
<DataTemplate DataType="{x:Type spp:PlatformAccount}">
<MenuItem
Command="{Binding $parent[spp:PageBase].((spp:GameAccountPageViewModel)DataContext).AddPlatformCommand}"
CommandParameter="{Binding}"
Header="{Binding FullName}">
<MenuItem.Icon>
<PathIcon Data="{Binding Icon, Converter={StaticResource ResourceKeyValueConverter}}" />
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</MenuItem.DataTemplates>-->
</MenuItem>
<MenuItem Header="-" IsVisible="{Binding !!AddGamePlatforms.Count}" />
<MenuItem Command="{Binding LoginNewCommand}" Header="{Binding Path=Res.UserChange_LoginNewAccount, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<MenuItem.Icon>
<ui:FASymbolIcon Symbol="Add" />
</MenuItem.Icon>
</MenuItem>
<!--<ui:FAMenuFlyoutSeparator />
<ui:FAMenuFlyoutSubItem Text="{Binding Path=Res.GameAccount_EndProcessWay, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<ui:FARadioMenuFlyoutItem
GroupName="KillMethond"
IconSource="Games"
Text="TaskKill" />
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</MenuItem.DataTemplates>-->
</MenuItem>
<MenuItem Header="-" IsVisible="{Binding !!AddGamePlatforms.Count}" />
<MenuItem Command="{Binding LoginNewCommand}" Header="{Binding Path=Res.UserChange_LoginNewAccount, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<MenuItem.Icon>
<ui:FASymbolIcon Symbol="Add" />
</MenuItem.Icon>
</MenuItem>
<!--<ui:FAMenuFlyoutSeparator />
<ui:FAMenuFlyoutSubItem Text="{Binding Path=Res.GameAccount_EndProcessWay, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<ui:FARadioMenuFlyoutItem
GroupName="KillMethond"
IconSource="Games"
Text="TaskKill" />

<ui:FARadioMenuFlyoutItem
GroupName="KillMethond"
IconSource="Icons"
Text="Direct" />
</ui:FAMenuFlyoutSubItem>
<ui:FAMenuFlyoutSubItem Text="{Binding Path=Res.GameAccount_StartProcessWay, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<ui:FARadioMenuFlyoutItem
GroupName="StartMethond"
IconSource="Games"
Text="Explorer" />
<ui:FARadioMenuFlyoutItem
GroupName="Test Group"
IconSource="Icons"
Text="Direct" />
</ui:FAMenuFlyoutSubItem>
<ui:FAMenuFlyoutSeparator />
<ui:FAToggleMenuFlyoutItem IconSource="Safe" Text="{Binding Path=Res.AdministratorStartup, Mode=OneWay, Source={x:Static s:ResourceService.Current}}" />-->
</MenuFlyout>
</Button.Flyout>
</Button>
<ui:FARadioMenuFlyoutItem
GroupName="KillMethond"
IconSource="Icons"
Text="Direct" />
</ui:FAMenuFlyoutSubItem>
<ui:FAMenuFlyoutSubItem Text="{Binding Path=Res.GameAccount_StartProcessWay, Mode=OneWay, Source={x:Static s:ResourceService.Current}}">
<ui:FARadioMenuFlyoutItem
GroupName="StartMethond"
IconSource="Games"
Text="Explorer" />
<ui:FARadioMenuFlyoutItem
GroupName="Test Group"
IconSource="Icons"
Text="Direct" />
</ui:FAMenuFlyoutSubItem>
<ui:FAMenuFlyoutSeparator />
<ui:FAToggleMenuFlyoutItem IconSource="Safe" Text="{Binding Path=Res.AdministratorStartup, Mode=OneWay, Source={x:Static s:ResourceService.Current}}" />-->
</MenuFlyout>
</Button.Flyout>
</Button>
<AutoCompleteBox
Grid.Column="2"
Width="280"
MaxWidth="320"
Margin="12,0,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Classes="Search"
Text="{Binding SelectedPlatform.SearchText, Mode=TwoWay}" />
</Grid>
</ui:FATabView.TabStripFooter>
<ui:FATabView.Styles>
<Style Selector="ui|FATabViewItem" x:DataType="spp:PlatformAccount">
Expand Down Expand Up @@ -265,4 +277,4 @@
</DataTemplate>
</ui:FATabView.TabItemTemplate>
</ui:FATabView>
</spp:PageBase>
</spp:PageBase>