Added a view model.
This commit is contained in:
parent
24856a0967
commit
2cc8c2d574
@ -6,6 +6,7 @@ using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Ava.UI.ViewModels.Input;
|
||||
using Ryujinx.Ava.UI.Windows;
|
||||
using Ryujinx.Ava.Utilities.Configuration;
|
||||
using Ryujinx.Common;
|
||||
@ -278,9 +279,11 @@ namespace Ryujinx.Ava.UI.Applet
|
||||
.ForEach(profile => profiles.Add(new Models.UserProfile(profile, nav)));
|
||||
|
||||
profiles.Add(new Models.UserProfile(guest, nav));
|
||||
|
||||
UserSelectorDialog content = new(profiles);
|
||||
(UserId id, _) = await UserSelectorDialog.ShowInputDialog(content, _parent.AccountManager.LastOpenedUser);
|
||||
UserSelectorDialogViewModel ViewModel = new();
|
||||
ViewModel.Profiles = profiles;
|
||||
ViewModel.SelectedUserId = _parent.AccountManager.LastOpenedUser.UserId;
|
||||
UserSelectorDialog content = new(ViewModel);
|
||||
(UserId id, _) = await UserSelectorDialog.ShowInputDialog(content);
|
||||
|
||||
selected = id;
|
||||
|
||||
|
@ -2,27 +2,24 @@
|
||||
x:Class="Ryujinx.Ava.UI.Applet.UserSelectorDialog"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
||||
xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models"
|
||||
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
|
||||
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:applet="clr-namespace:Ryujinx.Ava.UI.Applet"
|
||||
d:DesignHeight="450"
|
||||
MinWidth="500"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d"
|
||||
Focusable="True"
|
||||
x:DataType="applet:UserSelectorDialog">
|
||||
x:DataType="viewModels:UserSelectorDialogViewModel">
|
||||
|
||||
<UserControl.Resources>
|
||||
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
|
||||
</UserControl.Resources>
|
||||
|
||||
<Design.DataContext>
|
||||
<applet:UserSelectorDialog />
|
||||
<viewModels:UserSelectorDialogViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
|
@ -6,6 +6,7 @@ using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Ava.UI.ViewModels.Input;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using System.Collections.ObjectModel;
|
||||
@ -19,36 +20,15 @@ namespace Ryujinx.Ava.UI.Applet
|
||||
{
|
||||
public partial class UserSelectorDialog : UserControl, INotifyPropertyChanged
|
||||
{
|
||||
public new event PropertyChangedEventHandler PropertyChanged;
|
||||
public UserSelectorDialogViewModel ViewModel { get; set; }
|
||||
|
||||
private UserId _selectedUserId;
|
||||
private ObservableCollection<BaseModel> _profiles;
|
||||
|
||||
public ObservableCollection<BaseModel> Profiles
|
||||
{
|
||||
get => _profiles;
|
||||
set
|
||||
{
|
||||
if (_profiles != value)
|
||||
{
|
||||
_profiles = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UserSelectorDialog(ObservableCollection<BaseModel> profiles)
|
||||
public UserSelectorDialog(UserSelectorDialogViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
Profiles = profiles;
|
||||
DataContext = this;
|
||||
ViewModel = viewModel;
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
private void Grid_PointerEntered(object sender, PointerEventArgs e)
|
||||
{
|
||||
if (sender is Grid { DataContext: UserProfile profile })
|
||||
@ -71,22 +51,22 @@ namespace Ryujinx.Ava.UI.Applet
|
||||
{
|
||||
int selectedIndex = listBox.SelectedIndex;
|
||||
|
||||
if (selectedIndex >= 0 && selectedIndex < Profiles.Count)
|
||||
if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
|
||||
{
|
||||
if (Profiles[selectedIndex] is UserProfile userProfile)
|
||||
if (ViewModel.Profiles[selectedIndex] is UserProfile userProfile)
|
||||
{
|
||||
_selectedUserId = userProfile.UserId;
|
||||
ViewModel.SelectedUserId = userProfile.UserId;
|
||||
Logger.Info?.Print(LogClass.UI, $"Selected user: {userProfile.UserId}");
|
||||
|
||||
ObservableCollection<BaseModel> newProfiles = [];
|
||||
|
||||
foreach (var item in Profiles)
|
||||
foreach (var item in ViewModel.Profiles)
|
||||
{
|
||||
if (item is UserProfile originalItem)
|
||||
{
|
||||
var profile = new UserProfileSft(originalItem.UserId, originalItem.Name, originalItem.Image);
|
||||
|
||||
if (profile.UserId == _selectedUserId)
|
||||
if (profile.UserId == ViewModel.SelectedUserId)
|
||||
{
|
||||
profile.AccountState = AccountState.Open;
|
||||
}
|
||||
@ -95,16 +75,14 @@ namespace Ryujinx.Ava.UI.Applet
|
||||
}
|
||||
}
|
||||
|
||||
Profiles = newProfiles;
|
||||
ViewModel.Profiles = newProfiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<(UserId Id, bool Result)> ShowInputDialog(UserSelectorDialog content, UserProfileSft accountManagerLastOpenedUser)
|
||||
public static async Task<(UserId Id, bool Result)> ShowInputDialog(UserSelectorDialog content)
|
||||
{
|
||||
content._selectedUserId = accountManagerLastOpenedUser.UserId;
|
||||
|
||||
ContentDialog contentDialog = new()
|
||||
{
|
||||
Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle],
|
||||
@ -124,7 +102,7 @@ namespace Ryujinx.Ava.UI.Applet
|
||||
{
|
||||
if (contentDialog.Content is UserSelectorDialog view)
|
||||
{
|
||||
result = view._selectedUserId;
|
||||
result = view.ViewModel.SelectedUserId;
|
||||
input = true;
|
||||
}
|
||||
}
|
||||
|
43
src/Ryujinx/UI/ViewModels/UserSelectorDialogViewModel.cs
Normal file
43
src/Ryujinx/UI/ViewModels/UserSelectorDialogViewModel.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Ryujinx.Ava.UI.ViewModels
|
||||
{
|
||||
public partial class UserSelectorDialogViewModel : BaseModel
|
||||
{
|
||||
private UserId _selectedUserId;
|
||||
private ObservableCollection<BaseModel> _profiles;
|
||||
|
||||
public UserId SelectedUserId
|
||||
{
|
||||
get => _selectedUserId;
|
||||
set
|
||||
{
|
||||
if (_selectedUserId != value)
|
||||
{
|
||||
_selectedUserId = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<BaseModel> Profiles
|
||||
{
|
||||
get => _profiles;
|
||||
set
|
||||
{
|
||||
if (_profiles != value)
|
||||
{
|
||||
_profiles = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UserSelectorDialogViewModel()
|
||||
{
|
||||
Profiles = new ObservableCollection<BaseModel>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user