NavigationDialogHost.axaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using FluentAvalonia.UI.Controls;
  4. using Ryujinx.Ava.Common.Locale;
  5. using Ryujinx.Ava.Ui.ViewModels;
  6. using Ryujinx.HLE.FileSystem;
  7. using Ryujinx.HLE.HOS.Services.Account.Acc;
  8. using System;
  9. using System.Threading.Tasks;
  10. namespace Ryujinx.Ava.Ui.Controls
  11. {
  12. public partial class NavigationDialogHost : UserControl
  13. {
  14. public AccountManager AccountManager { get; }
  15. public ContentManager ContentManager { get; }
  16. public UserProfileViewModel ViewModel { get; set; }
  17. public NavigationDialogHost()
  18. {
  19. InitializeComponent();
  20. }
  21. public NavigationDialogHost(AccountManager accountManager, ContentManager contentManager,
  22. VirtualFileSystem virtualFileSystem)
  23. {
  24. AccountManager = accountManager;
  25. ContentManager = contentManager;
  26. ViewModel = new UserProfileViewModel(this);
  27. if (contentManager.GetCurrentFirmwareVersion() != null)
  28. {
  29. Task.Run(() =>
  30. {
  31. AvatarProfileViewModel.PreloadAvatars(contentManager, virtualFileSystem);
  32. });
  33. }
  34. InitializeComponent();
  35. }
  36. public void GoBack(object parameter = null)
  37. {
  38. if (ContentFrame.BackStack.Count > 0)
  39. {
  40. ContentFrame.GoBack();
  41. }
  42. ViewModel.LoadProfiles();
  43. }
  44. public void Navigate(Type sourcePageType, object parameter)
  45. {
  46. ContentFrame.Navigate(sourcePageType, parameter);
  47. }
  48. public static async Task Show(AccountManager ownerAccountManager, ContentManager ownerContentManager, VirtualFileSystem ownerVirtualFileSystem)
  49. {
  50. var content = new NavigationDialogHost(ownerAccountManager, ownerContentManager, ownerVirtualFileSystem);
  51. ContentDialog contentDialog = new ContentDialog
  52. {
  53. Title = LocaleManager.Instance["UserProfileWindowTitle"],
  54. PrimaryButtonText = "",
  55. SecondaryButtonText = "",
  56. CloseButtonText = LocaleManager.Instance["UserProfilesClose"],
  57. Content = content,
  58. Padding = new Thickness(0)
  59. };
  60. contentDialog.Closed += (sender, args) =>
  61. {
  62. content.ViewModel.Dispose();
  63. };
  64. await contentDialog.ShowAsync();
  65. }
  66. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  67. {
  68. base.OnAttachedToVisualTree(e);
  69. Navigate(typeof(UserSelector), this);
  70. }
  71. }
  72. }