Avalonia - Use content dialog for user profile manager (#3455)
* remove content dialog placeholder from all windows * remove redundant window argument * redesign user profile window * wip * use avalonia auto name generator * add edit and new user options * move profile image selection to content dialog * remove usings * fix updater * address review * adjust avatar dialog size * add validation for user editor * fix typo * Shorten some labels
This commit is contained in:
parent
3a3380fa25
commit
6e02cac952
46 changed files with 968 additions and 953 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue