aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs')
-rw-r--r--Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs95
1 files changed, 33 insertions, 62 deletions
diff --git a/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs
index 66fa7e34..f7a50077 100644
--- a/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs
+++ b/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs
@@ -1,31 +1,27 @@
using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Controls;
-using Ryujinx.Ava.Ui.Windows;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using System;
using System.Collections.ObjectModel;
using System.Linq;
-using System.Threading.Tasks;
using UserProfile = Ryujinx.Ava.Ui.Models.UserProfile;
namespace Ryujinx.Ava.Ui.ViewModels
{
public class UserProfileViewModel : BaseModel, IDisposable
{
- private const uint MaxProfileNameLength = 0x20;
-
- private readonly UserProfileWindow _owner;
+ private readonly NavigationDialogHost _owner;
private UserProfile _selectedProfile;
- private string _tempUserName;
+ private UserProfile _highlightedProfile;
public UserProfileViewModel()
{
Profiles = new ObservableCollection<UserProfile>();
}
- public UserProfileViewModel(UserProfileWindow owner) : this()
+ public UserProfileViewModel(NavigationDialogHost owner) : this()
{
_owner = owner;
@@ -42,12 +38,29 @@ namespace Ryujinx.Ava.Ui.ViewModels
_selectedProfile = value;
OnPropertyChanged(nameof(SelectedProfile));
- OnPropertyChanged(nameof(IsSelectedProfileDeletable));
+ OnPropertyChanged(nameof(IsHighlightedProfileDeletable));
+ OnPropertyChanged(nameof(IsHighlightedProfileEditable));
}
}
- public bool IsSelectedProfileDeletable =>
- _selectedProfile != null && _selectedProfile.UserId != AccountManager.DefaultUserId;
+ public bool IsHighlightedProfileEditable =>
+ _highlightedProfile != null;
+
+ public bool IsHighlightedProfileDeletable =>
+ _highlightedProfile != null && _highlightedProfile.UserId != AccountManager.DefaultUserId;
+
+ public UserProfile HighlightedProfile
+ {
+ get => _highlightedProfile;
+ set
+ {
+ _highlightedProfile = value;
+
+ OnPropertyChanged(nameof(HighlightedProfile));
+ OnPropertyChanged(nameof(IsHighlightedProfileDeletable));
+ OnPropertyChanged(nameof(IsHighlightedProfileEditable));
+ }
+ }
public void Dispose()
{
@@ -78,64 +91,24 @@ namespace Ryujinx.Ava.Ui.ViewModels
}
}
- public async void ChooseProfileImage()
+ public void AddUser()
{
- await SelectProfileImage();
+ UserProfile userProfile = null;
+ _owner.Navigate(typeof(UserEditor), (this._owner, userProfile, true));
}
- public async Task SelectProfileImage(bool isNewUser = false)
+ public void EditUser()
{
- ProfileImageSelectionDialog selectionDialog = new(_owner.ContentManager);
-
- await selectionDialog.ShowDialog(_owner);
-
- if (selectionDialog.BufferImageProfile != null)
- {
- if (isNewUser)
- {
- if (!string.IsNullOrWhiteSpace(_tempUserName))
- {
- _owner.AccountManager.AddUser(_tempUserName, selectionDialog.BufferImageProfile);
- }
- }
- else if (SelectedProfile != null)
- {
- _owner.AccountManager.SetUserImage(SelectedProfile.UserId, selectionDialog.BufferImageProfile);
- SelectedProfile.Image = selectionDialog.BufferImageProfile;
-
- SelectedProfile = null;
- }
-
- LoadProfiles();
- }
- }
-
- public async void AddUser()
- {
- var dlgTitle = LocaleManager.Instance["InputDialogAddNewProfileTitle"];
- var dlgMainText = LocaleManager.Instance["InputDialogAddNewProfileHeader"];
- var dlgSubText = string.Format(LocaleManager.Instance["InputDialogAddNewProfileSubtext"],
- MaxProfileNameLength);
-
- _tempUserName =
- await ContentDialogHelper.CreateInputDialog(dlgTitle, dlgMainText, dlgSubText, _owner,
- MaxProfileNameLength);
-
- if (!string.IsNullOrWhiteSpace(_tempUserName))
- {
- await SelectProfileImage(true);
- }
-
- _tempUserName = String.Empty;
+ _owner.Navigate(typeof(UserEditor), (this._owner, _highlightedProfile ?? SelectedProfile, false));
}
public async void DeleteUser()
{
- if (_selectedProfile != null)
+ if (_highlightedProfile != null)
{
var lastUserId = _owner.AccountManager.LastOpenedUser.UserId;
- if (_selectedProfile.UserId == lastUserId)
+ if (_highlightedProfile.UserId == lastUserId)
{
// If we are deleting the currently open profile, then we must open something else before deleting.
var profile = Profiles.FirstOrDefault(x => x.UserId != lastUserId);
@@ -144,8 +117,7 @@ namespace Ryujinx.Ava.Ui.ViewModels
{
Dispatcher.UIThread.Post(async () =>
{
- await ContentDialogHelper.CreateErrorDialog(_owner,
- LocaleManager.Instance["DialogUserProfileDeletionWarningMessage"]);
+ await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance["DialogUserProfileDeletionWarningMessage"]);
});
return;
@@ -155,13 +127,12 @@ namespace Ryujinx.Ava.Ui.ViewModels
}
var result =
- await ContentDialogHelper.CreateConfirmationDialog(_owner,
- LocaleManager.Instance["DialogUserProfileDeletionConfirmMessage"], "",
+ await ContentDialogHelper.CreateConfirmationDialog(LocaleManager.Instance["DialogUserProfileDeletionConfirmMessage"], "",
LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"], "");
if (result == UserResult.Yes)
{
- _owner.AccountManager.DeleteUser(_selectedProfile.UserId);
+ _owner.AccountManager.DeleteUser(_highlightedProfile.UserId);
}
}