PulseAppPage.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Threading.Tasks;
  4. using Avalonia;
  5. using Avalonia.Animation;
  6. using Avalonia.Controls;
  7. using Avalonia.Interactivity;
  8. using Avalonia.Media;
  9. namespace ControlCatalog.Pages;
  10. public partial class PulseAppPage : UserControl
  11. {
  12. static readonly Color Primary = Color.Parse("#256af4");
  13. static readonly Color BgDark = Color.Parse("#101622");
  14. static readonly Color BgDashboard = Color.Parse("#0a0a0a");
  15. static readonly Color TextDimmed = Color.Parse("#64748b");
  16. NavigationPage? _navPage;
  17. ContentPage? _loginPage;
  18. ScrollViewer? _infoPanel;
  19. public PulseAppPage()
  20. {
  21. InitializeComponent();
  22. _navPage = this.FindControl<NavigationPage>("NavPage");
  23. if (_navPage != null)
  24. {
  25. _loginPage = BuildLoginPage();
  26. _ = _navPage.PushAsync(_loginPage);
  27. }
  28. }
  29. protected override void OnLoaded(RoutedEventArgs e)
  30. {
  31. base.OnLoaded(e);
  32. _infoPanel = this.FindControl<ScrollViewer>("InfoPanel");
  33. UpdateInfoPanelVisibility();
  34. }
  35. protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
  36. {
  37. base.OnPropertyChanged(change);
  38. if (change.Property == BoundsProperty)
  39. UpdateInfoPanelVisibility();
  40. }
  41. void UpdateInfoPanelVisibility()
  42. {
  43. if (_infoPanel != null)
  44. _infoPanel.IsVisible = Bounds.Width >= 650;
  45. }
  46. ContentPage BuildLoginPage()
  47. {
  48. var loginView = new PulseLoginView();
  49. loginView.LoginRequested = OnLoginRequested;
  50. var page = new ContentPage
  51. {
  52. Content = loginView,
  53. Background = new SolidColorBrush(BgDark),
  54. };
  55. NavigationPage.SetHasNavigationBar(page, false);
  56. return page;
  57. }
  58. async void OnLoginRequested()
  59. {
  60. if (_navPage == null || _loginPage == null) return;
  61. var dashboard = BuildDashboardPage();
  62. await _navPage.PushAsync(dashboard);
  63. _navPage.RemovePage(_loginPage);
  64. _loginPage = null;
  65. }
  66. TabbedPage BuildDashboardPage()
  67. {
  68. var tp = new TabbedPage
  69. {
  70. Background = new SolidColorBrush(BgDashboard),
  71. TabPlacement = TabPlacement.Bottom,
  72. PageTransition = new PageSlide(TimeSpan.FromMilliseconds(200)),
  73. };
  74. tp.Resources["TabItemHeaderFontSize"] = 12.0;
  75. tp.Resources["TabbedPageTabStripBackground"] = new SolidColorBrush(BgDashboard);
  76. tp.Resources["TabbedPageTabItemHeaderForegroundSelected"] = new SolidColorBrush(Primary);
  77. tp.Resources["TabbedPageTabItemHeaderForegroundUnselected"] = new SolidColorBrush(TextDimmed);
  78. NavigationPage.SetHasNavigationBar(tp, false);
  79. var homeView = new PulseHomeView();
  80. homeView.WorkoutDetailRequested = PushWorkoutDetail;
  81. var homePage = new ContentPage
  82. {
  83. Content = homeView,
  84. Background = new SolidColorBrush(BgDashboard),
  85. Header = "Home",
  86. Icon = new PathIcon { Data = Geometry.Parse("M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z") },
  87. };
  88. var workoutsPage = new ContentPage
  89. {
  90. Content = new PulseWorkoutsView(),
  91. Background = new SolidColorBrush(BgDashboard),
  92. Header = "Workouts",
  93. Icon = new PathIcon { Data = Geometry.Parse("M20.57 14.86L22 13.43 20.57 12 17 15.57 8.43 7 12 3.43 10.57 2 9.14 3.43 7.71 2 5.57 4.14 4.14 2.71 2.71 4.14l1.43 1.43L2 7.71l1.43 1.43L2 10.57 3.43 12 7 8.43 15.57 17 12 20.57 13.43 22l1.43-1.43L16.29 22l2.14-2.14 1.43 1.43 1.43-1.43-1.43-1.43L22 16.29z") },
  94. };
  95. var profilePage = new ContentPage
  96. {
  97. Content = new PulseProfileView(),
  98. Background = new SolidColorBrush(BgDashboard),
  99. Header = "Profile",
  100. Icon = new PathIcon { Data = Geometry.Parse("M12 2C9.243 2 7 4.243 7 7s2.243 5 5 5 5-2.243 5-5-2.243-5-5-5zM12 14c-5.523 0-10 3.582-10 8a1 1 0 001 1h18a1 1 0 001-1c0-4.418-4.477-8-10-8z") },
  101. };
  102. tp.Pages = new ObservableCollection<Page> { homePage, workoutsPage, profilePage };
  103. return tp;
  104. }
  105. async void PushWorkoutDetail()
  106. {
  107. if (_navPage == null) return;
  108. var detailView = new PulseWorkoutDetailView();
  109. detailView.BackRequested = async () => { if (_navPage != null) await _navPage.PopAsync(); };
  110. var page = new ContentPage
  111. {
  112. Content = detailView,
  113. Background = new SolidColorBrush(BgDark),
  114. };
  115. NavigationPage.SetHasNavigationBar(page, false);
  116. await _navPage.PushAsync(page);
  117. }
  118. }