Skip to content

Commit

Permalink
✨ 令牌搜索功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Nov 15, 2023
1 parent a69d97f commit 3fe8f93
Show file tree
Hide file tree
Showing 8 changed files with 1,229 additions and 1,115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,23 +20,56 @@ public sealed partial class AuthenticatorHomePageViewModel : ViewModelBase
string? _currentPassword;

//DateTime _initializeTime;
readonly Dictionary<string, string[]> dictPinYinArray = new();

Func<AuthenticatorItemModel, bool> 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<AuthenticatorItemModel>.Ascending(x => x.AuthData.Index).ThenBy(x => x.AuthName))
.Bind(out _Auths)
.Subscribe();
}

public async void Initialize()
Expand All @@ -50,7 +86,7 @@ public async void Initialize()

//_initializeTime = DateTime.Now;

Auths.Clear();
AuthSource.Clear();

var sourceList = await AuthenticatorHelper.GetAllSourceAuthenticatorAsync();
if (sourceList.Any_Nullable())
Expand Down Expand Up @@ -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 () =>
Expand Down Expand Up @@ -234,7 +270,7 @@ public void ReLockAuthenticator()
return;
}

Auths.Clear();
AuthSource.Clear();
IsVerificationPass = false;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ public partial class AuthenticatorHomePageViewModel
[Reactive]
public bool IsLoading { get; set; }

[Reactive]
public ObservableCollection<AuthenticatorItemModel> Auths { get; set; }
private SourceCache<AuthenticatorItemModel, ushort> AuthSource;

[Reactive]
public AuthenticatorItemModel? SelectedAuth { get; set; }
private readonly ReadOnlyObservableCollection<AuthenticatorItemModel>? _Auths;

public ReadOnlyObservableCollection<AuthenticatorItemModel>? Auths => _Auths;

//[Reactive]
//public ObservableCollection<AuthenticatorItemModel> Auths { get; set; } = [];

//[Reactive]
//public AuthenticatorItemModel? SelectedAuth { get; set; }

[Reactive]
public bool HasPasswordEncrypt { get; set; } = false;
Expand All @@ -21,4 +27,7 @@ public partial class AuthenticatorHomePageViewModel

[Reactive]
public bool IsVerificationPass { get; set; }

[Reactive]
public string? SearchText { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@

<spp:PageBase.PaneContent>
<StackPanel Margin="15,20" Spacing="10">
<TextBlock
Grid.Row="2"
VerticalAlignment="Center"
Text="{Binding Path=Res.Filter, Mode=OneWay, Source={x:Static s:ResourceService.Current}}"
Theme="{StaticResource CaptionTextBlockStyle}" />

<AutoCompleteBox
MinWidth="280"
VerticalAlignment="Center"
Classes="Search"
Text="{Binding SearchText}" />

<TextBlock
Text="{Binding Path=Res.EncryptSettings, Mode=OneWay, Source={x:Static s:ResourceService.Current}}"
Theme="{StaticResource BodyStrongTextBlockStyle}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ private async Task SteamAppsSort()
}

Badges.Clear();

TotalCardsRemaining = 0;
TotalCardsAvgPrice = 0;
foreach (var b in badges)
{
if (b.CardsRemaining != 0)// 过滤可掉落卡片的游戏
{
TotalCardsAvgPrice += b.RegularAvgPrice * b.CardsRemaining;
TotalCardsRemaining += b.CardsRemaining;
Badges.Add(b);
}
}
Expand All @@ -181,25 +184,23 @@ private async Task SteamAppsSort()
}

var appid_sorts = Enumerable.Empty<int>();
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public sealed partial class IdleCardPageViewModel
/// 用户徽章和卡片数据
/// </summary>
[Reactive]
private ObservableCollection<Badge> Badges { get; set; } = new();
public ObservableCollection<Badge> Badges { get; set; } = new();

[Reactive]
public int TotalCardsRemaining { get; set; }

[Reactive]
public decimal TotalCardsAvgPrice { get; set; }

/// <summary>
/// 当前挂卡游戏
Expand Down
Loading

0 comments on commit 3fe8f93

Please sign in to comment.