UserSelector.axaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using FluentAvalonia.UI.Controls;
  4. using FluentAvalonia.UI.Navigation;
  5. using Ryujinx.Ava.Ui.ViewModels;
  6. using UserProfile = Ryujinx.Ava.Ui.Models.UserProfile;
  7. namespace Ryujinx.Ava.Ui.Controls
  8. {
  9. public partial class UserSelector : UserControl
  10. {
  11. private NavigationDialogHost _parent;
  12. public UserProfileViewModel ViewModel { get; set; }
  13. public UserSelector()
  14. {
  15. InitializeComponent();
  16. if (Program.PreviewerDetached)
  17. {
  18. AddHandler(Frame.NavigatedToEvent, (s, e) =>
  19. {
  20. NavigatedTo(e);
  21. }, RoutingStrategies.Direct);
  22. }
  23. }
  24. private void NavigatedTo(NavigationEventArgs arg)
  25. {
  26. if (Program.PreviewerDetached)
  27. {
  28. if (arg.NavigationMode == NavigationMode.New)
  29. {
  30. _parent = (NavigationDialogHost)arg.Parameter;
  31. ViewModel = _parent.ViewModel;
  32. }
  33. DataContext = ViewModel;
  34. }
  35. }
  36. private void ProfilesList_DoubleTapped(object sender, RoutedEventArgs e)
  37. {
  38. if (sender is ListBox listBox)
  39. {
  40. int selectedIndex = listBox.SelectedIndex;
  41. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  42. {
  43. ViewModel.SelectedProfile = ViewModel.Profiles[selectedIndex];
  44. _parent?.AccountManager?.OpenUser(ViewModel.SelectedProfile.UserId);
  45. ViewModel.LoadProfiles();
  46. foreach (UserProfile profile in ViewModel.Profiles)
  47. {
  48. profile.UpdateState();
  49. }
  50. }
  51. }
  52. }
  53. private void SelectingItemsControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
  54. {
  55. if (sender is ListBox listBox)
  56. {
  57. int selectedIndex = listBox.SelectedIndex;
  58. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  59. {
  60. ViewModel.HighlightedProfile = ViewModel.Profiles[selectedIndex];
  61. }
  62. }
  63. }
  64. }
  65. }