mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-03-14 17:00:17 +00:00
Fix SaveManager bug
This commit is contained in:
parent
f4af6c7375
commit
8eb3984981
3 changed files with 135 additions and 83 deletions
112
Ryujinx.Ava/UI/ViewModels/UserSaveManagerViewModel.cs
Normal file
112
Ryujinx.Ava/UI/ViewModels/UserSaveManagerViewModel.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using Ryujinx.Ava.UI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Ryujinx.Ava.UI.ViewModels;
|
||||
|
||||
public class UserSaveManagerViewModel : BaseModel
|
||||
{
|
||||
private int _sortIndex;
|
||||
private int _orderIndex;
|
||||
private string _search;
|
||||
private ObservableCollection<SaveModel> _saves;
|
||||
private ObservableCollection<SaveModel> _views;
|
||||
|
||||
public int SortIndex
|
||||
{
|
||||
get => _sortIndex;
|
||||
set
|
||||
{
|
||||
_sortIndex = value;
|
||||
OnPropertyChanged();
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public int OrderIndex
|
||||
{
|
||||
get => _orderIndex;
|
||||
set
|
||||
{
|
||||
_orderIndex = value;
|
||||
OnPropertyChanged();
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public string Search
|
||||
{
|
||||
get => _search;
|
||||
set
|
||||
{
|
||||
_search = value;
|
||||
OnPropertyChanged();
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<SaveModel> Saves
|
||||
{
|
||||
get => _saves;
|
||||
set
|
||||
{
|
||||
_saves = value;
|
||||
OnPropertyChanged();
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<SaveModel> Views
|
||||
{
|
||||
get => _views;
|
||||
}
|
||||
|
||||
public UserSaveManagerViewModel()
|
||||
{
|
||||
_saves = new ObservableCollection<SaveModel>();
|
||||
_views = new ObservableCollection<SaveModel>();
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
Console.WriteLine("Sorting");
|
||||
Saves.AsObservableChangeSet()
|
||||
.Filter(Filter)
|
||||
.Sort(GetComparer())
|
||||
.Bind(out var view).AsObservableList();
|
||||
|
||||
_views.Clear();
|
||||
_views.AddRange(view);
|
||||
OnPropertyChanged(nameof(Views));
|
||||
}
|
||||
|
||||
private bool Filter(object arg)
|
||||
{
|
||||
if (arg is SaveModel save)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(_search) || save.Title.ToLower().Contains(_search.ToLower());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private IComparer<SaveModel> GetComparer()
|
||||
{
|
||||
switch (SortIndex)
|
||||
{
|
||||
case 0:
|
||||
return OrderIndex == 0
|
||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Title)
|
||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Title);
|
||||
case 1:
|
||||
return OrderIndex == 0
|
||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Size)
|
||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Size);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,13 +7,19 @@
|
|||
xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale"
|
||||
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
||||
xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models"
|
||||
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
Height="400"
|
||||
Width="550"
|
||||
x:Class="Ryujinx.Ava.UI.Views.User.UserSaveManager"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="viewModels:UserSaveManagerViewModel"
|
||||
Focusable="True">
|
||||
<Design.DataContext>
|
||||
<viewModels:UserSaveManagerViewModel />
|
||||
</Design.DataContext>
|
||||
<UserControl.Resources>
|
||||
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
|
||||
</UserControl.Resources>
|
||||
|
@ -96,7 +102,7 @@
|
|||
VerticalAlignment="Stretch">
|
||||
<ListBox
|
||||
Name="SaveList"
|
||||
Items="{Binding View}"
|
||||
Items="{Binding Views}"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<ListBox.Styles>
|
||||
|
@ -156,7 +162,7 @@
|
|||
MinWidth="0"
|
||||
MinHeight="0"
|
||||
Name="OpenLocation"
|
||||
Command="{Binding OpenLocation}">
|
||||
Click="OpenLocation">
|
||||
<ui:SymbolIcon
|
||||
Symbol="OpenFolder"
|
||||
HorizontalAlignment="Center"
|
||||
|
@ -169,7 +175,7 @@
|
|||
MinWidth="0"
|
||||
MinHeight="0"
|
||||
Name="Delete"
|
||||
Command="{Binding Delete}">
|
||||
Click="Delete">
|
||||
<ui:SymbolIcon
|
||||
Symbol="Delete"
|
||||
HorizontalAlignment="Center"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using FluentAvalonia.UI.Navigation;
|
||||
using LibHac;
|
||||
|
@ -10,11 +8,10 @@ using LibHac.Fs;
|
|||
using LibHac.Fs.Shim;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.Models;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using UserId = LibHac.Fs.UserId;
|
||||
|
||||
|
@ -22,54 +19,13 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
{
|
||||
public partial class UserSaveManager : UserControl
|
||||
{
|
||||
internal UserSaveManagerViewModel ViewModel { get; private set; }
|
||||
|
||||
private AccountManager _accountManager;
|
||||
private HorizonClient _horizonClient;
|
||||
private VirtualFileSystem _virtualFileSystem;
|
||||
private int _sortIndex;
|
||||
private int _orderIndex;
|
||||
private ObservableCollection<SaveModel> _view = new();
|
||||
private string _search;
|
||||
|
||||
private NavigationDialogHost _parent;
|
||||
|
||||
public ObservableCollection<SaveModel> Saves { get; set; } = new();
|
||||
|
||||
public ObservableCollection<SaveModel> View
|
||||
{
|
||||
get => _view;
|
||||
set => _view = value;
|
||||
}
|
||||
|
||||
public int SortIndex
|
||||
{
|
||||
get => _sortIndex;
|
||||
set
|
||||
{
|
||||
_sortIndex = value;
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public int OrderIndex
|
||||
{
|
||||
get => _orderIndex;
|
||||
set
|
||||
{
|
||||
_orderIndex = value;
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public string Search
|
||||
{
|
||||
get => _search;
|
||||
set
|
||||
{
|
||||
_search = value;
|
||||
Sort();
|
||||
}
|
||||
}
|
||||
|
||||
public UserSaveManager()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -97,14 +53,14 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
break;
|
||||
}
|
||||
|
||||
DataContext = this;
|
||||
DataContext = ViewModel = new UserSaveManagerViewModel();
|
||||
Task.Run(LoadSaves);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadSaves()
|
||||
{
|
||||
Saves.Clear();
|
||||
ViewModel.Saves.Clear();
|
||||
var saveDataFilter = SaveDataFilter.Make(programId: default, saveType: SaveDataType.Account,
|
||||
new UserId((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low), saveDataId: default, index: default);
|
||||
|
||||
|
@ -129,11 +85,11 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
if (save.ProgramId.Value != 0)
|
||||
{
|
||||
var saveModel = new SaveModel(save, _horizonClient, _virtualFileSystem);
|
||||
Saves.Add(saveModel);
|
||||
saveModel.DeleteAction = () => { Saves.Remove(saveModel); };
|
||||
ViewModel.Saves.Add(saveModel);
|
||||
saveModel.DeleteAction = () => { ViewModel.Saves.Remove(saveModel); };
|
||||
}
|
||||
|
||||
Sort();
|
||||
ViewModel.Sort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,42 +99,20 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
_parent?.GoBack();
|
||||
}
|
||||
|
||||
private void Sort()
|
||||
private void OpenLocation(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Saves.AsObservableChangeSet()
|
||||
.Filter(Filter)
|
||||
.Sort(GetComparer())
|
||||
.Bind(out var view).AsObservableList();
|
||||
|
||||
_view.Clear();
|
||||
_view.AddRange(view);
|
||||
}
|
||||
|
||||
private IComparer<SaveModel> GetComparer()
|
||||
{
|
||||
switch (SortIndex)
|
||||
if (sender is Avalonia.Controls.Button button)
|
||||
{
|
||||
case 0:
|
||||
return OrderIndex == 0
|
||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Title)
|
||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Title);
|
||||
case 1:
|
||||
return OrderIndex == 0
|
||||
? SortExpressionComparer<SaveModel>.Ascending(save => save.Size)
|
||||
: SortExpressionComparer<SaveModel>.Descending(save => save.Size);
|
||||
default:
|
||||
return null;
|
||||
(button.DataContext as SaveModel).OpenLocation();
|
||||
}
|
||||
}
|
||||
|
||||
private bool Filter(object arg)
|
||||
private void Delete(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (arg is SaveModel save)
|
||||
if (sender is Avalonia.Controls.Button button)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(_search) || save.Title.ToLower().Contains(_search.ToLower());
|
||||
(button.DataContext as SaveModel).Delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue