Skip to content

Commit

Permalink
impl #896
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Apr 28, 2024
1 parent ff2521c commit a7eb914
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void Update(AchievementViewModel viewModel)
throw HutaoException.InvalidCast<IEnumerable<AchievementView>, List<AchievementView>>("AchievementViewModel.Achievements.SourceCollection");
}

Dictionary<AchievementGoalId, AchievementGoalStatistics> counter = achievementGoals.ToDictionary(x => x.Id, AchievementGoalStatistics.From);
Dictionary<AchievementGoalId, AchievementGoalStatistics> counter = achievementGoals.SourceCollection.ToDictionary(x => x.Id, AchievementGoalStatistics.From);

foreach (ref readonly AchievementView achievementView in CollectionsMarshal.AsSpan(list))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public AchievementView(Model.Entity.Achievement entity, Model.Metadata.Achieveme
/// </summary>
public Model.Metadata.Achievement.Achievement Inner { get; }

public uint Order => Inner.Order;

/// <summary>
/// 是否选中
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ namespace Snap.Hutao.ViewModel.Achievement;
[Injection(InjectAs.Scoped)]
internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INavigationRecipient
{
private readonly SortDescription uncompletedItemsFirstSortDescription = new(nameof(AchievementView.IsChecked), SortDirection.Ascending);
private readonly SortDescription completionTimeSortDescription = new(nameof(AchievementView.Time), SortDirection.Descending);
private readonly SortDescription achievementUncompletedItemsFirstSortDescription = new(nameof(AchievementView.IsChecked), SortDirection.Ascending);
private readonly SortDescription achievementCompletionTimeSortDescription = new(nameof(AchievementView.Time), SortDirection.Descending);
private readonly SortDescription achievementGoalUncompletedItemsFirstSortDescription = new(nameof(AchievementGoalView.FinishPercent), SortDirection.Ascending);

private readonly SortDescription achievementDefaultSortDescription = new(nameof(AchievementView.Order), SortDirection.Ascending);
private readonly SortDescription achievementGoalDefaultSortDescription = new(nameof(AchievementGoalView.Order), SortDirection.Ascending);

private readonly AchievementViewModelDependencies dependencies;

private AdvancedCollectionView<AchievementView>? achievements;
private List<AchievementGoalView>? achievementGoals;
private AdvancedCollectionView<AchievementGoalView>? achievementGoals;
private AchievementGoalView? selectedAchievementGoal;
private ObservableCollection<EntityAchievementArchive>? archives;
private EntityAchievementArchive? selectedArchive;
Expand Down Expand Up @@ -67,7 +71,7 @@ public AdvancedCollectionView<AchievementView>? Achievements
set => SetProperty(ref achievements, value);
}

public List<AchievementGoalView>? AchievementGoals
public AdvancedCollectionView<AchievementGoalView>? AchievementGoals
{
get => achievementGoals;
set => SetProperty(ref achievementGoals, value);
Expand Down Expand Up @@ -141,7 +145,7 @@ protected override async ValueTask<bool> InitializeUIAsync()

await dependencies.TaskContext.SwitchToMainThreadAsync();

AchievementGoals = sortedGoals;
AchievementGoals = new(sortedGoals, true);
Archives = archives;
SelectedArchive = dependencies.AchievementService.CurrentArchive;
return true;
Expand Down Expand Up @@ -299,20 +303,23 @@ private bool TryGetAchievements(EntityAchievementArchive archive, AchievementSer
[Command("SortUncompletedSwitchCommand")]
private void UpdateAchievementsSort()
{
if (Achievements is null)
if (Achievements is null || AchievementGoals is null)
{
return;
}

Achievements.SortDescriptions.Clear();
AchievementGoals.SortDescriptions.Clear();

if (IsUncompletedItemsFirst)
{
Achievements.SortDescriptions.Add(uncompletedItemsFirstSortDescription);
Achievements.SortDescriptions.Add(completionTimeSortDescription);
}
else
{
Achievements.SortDescriptions.Clear();
Achievements.SortDescriptions.Add(achievementUncompletedItemsFirstSortDescription);
Achievements.SortDescriptions.Add(achievementCompletionTimeSortDescription);
AchievementGoals.SortDescriptions.Add(achievementGoalUncompletedItemsFirstSortDescription);
}

Achievements.SortDescriptions.Add(achievementDefaultSortDescription);
AchievementGoals.SortDescriptions.Add(achievementGoalDefaultSortDescription);
}

private void UpdateAchievementsFilterByGoal(AchievementGoalView? goal)
Expand Down

0 comments on commit a7eb914

Please sign in to comment.