UserSelector.axaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }, Avalonia.Interactivity.RoutingStrategies.Direct);
  22. }
  23. }
  24. private void NavigatedTo(NavigationEventArgs arg)
  25. {
  26. if (Program.PreviewerDetached)
  27. {
  28. switch (arg.NavigationMode)
  29. {
  30. case NavigationMode.New:
  31. _parent = (NavigationDialogHost)arg.Parameter;
  32. ViewModel = _parent.ViewModel;
  33. break;
  34. }
  35. DataContext = ViewModel;
  36. }
  37. }
  38. private void ProfilesList_DoubleTapped(object sender, RoutedEventArgs e)
  39. {
  40. if (sender is ListBox listBox)
  41. {
  42. int selectedIndex = listBox.SelectedIndex;
  43. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  44. {
  45. ViewModel.SelectedProfile = ViewModel.Profiles[selectedIndex];
  46. _parent?.AccountManager?.OpenUser(ViewModel.SelectedProfile.UserId);
  47. ViewModel.LoadProfiles();
  48. foreach (UserProfile profile in ViewModel.Profiles)
  49. {
  50. profile.UpdateState();
  51. }
  52. }
  53. }
  54. }
  55. private void SelectingItemsControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
  56. {
  57. if (sender is ListBox listBox)
  58. {
  59. int selectedIndex = listBox.SelectedIndex;
  60. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  61. {
  62. ViewModel.HighlightedProfile = ViewModel.Profiles[selectedIndex];
  63. }
  64. }
  65. }
  66. }
  67. }