From 5a1b4a757867dceee9aef97cc505a2d1fdfdba28 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Mon, 25 Nov 2024 01:10:59 +0000 Subject: [PATCH] More bugfixes/compose view improvements --- UniSky/App.xaml | 8 +- UniSky/Controls/Compose/ComposeSheet.xaml | 41 +++- UniSky/Controls/Compose/ComposeSheet.xaml.cs | 8 +- .../RadialProgressBar/RadialProgressBar.cs | 202 ++++++++++++++++++ .../RadialProgressBar/RadialProgressBar.xaml | 63 ++++++ .../Sheet/SheetControl.xaml} | 0 .../Controls/Sheet/SheetRootControl.xaml.cs | 35 ++- UniSky/Converters/Static.cs | 1 - UniSky/Package.appxmanifest | 2 +- UniSky/UniSky.csproj | 7 +- UniSky/ViewModels/Compose/ComposeViewModel.cs | 10 +- 11 files changed, 363 insertions(+), 14 deletions(-) create mode 100644 UniSky/Controls/RadialProgressBar/RadialProgressBar.cs create mode 100644 UniSky/Controls/RadialProgressBar/RadialProgressBar.xaml rename UniSky/{Templates/SheetControlStyles.xaml => Controls/Sheet/SheetControl.xaml} (100%) diff --git a/UniSky/App.xaml b/UniSky/App.xaml index 2b36f20..d23ab64 100644 --- a/UniSky/App.xaml +++ b/UniSky/App.xaml @@ -22,15 +22,18 @@ - + + + #10FFFFFF + #10000000 @@ -48,6 +51,9 @@ 14 14 + + + \ No newline at end of file diff --git a/UniSky/Templates/SheetControlStyles.xaml b/UniSky/Controls/Sheet/SheetControl.xaml similarity index 100% rename from UniSky/Templates/SheetControlStyles.xaml rename to UniSky/Controls/Sheet/SheetControl.xaml diff --git a/UniSky/Controls/Sheet/SheetRootControl.xaml.cs b/UniSky/Controls/Sheet/SheetRootControl.xaml.cs index 08741ce..098fd5c 100644 --- a/UniSky/Controls/Sheet/SheetRootControl.xaml.cs +++ b/UniSky/Controls/Sheet/SheetRootControl.xaml.cs @@ -13,6 +13,8 @@ using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Composition; +using Windows.UI.Core; +using Windows.UI.Core.Preview; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; @@ -58,12 +60,16 @@ public SheetRootControl() protected override Size ArrangeOverride(Size finalSize) { - if (finalSize.Width > 620) + if (!double.IsInfinity(HostControl.MaxHeight)) + { TotalHeight = 64; + SheetRoot.Height = Math.Max(0, HostControl.MaxHeight - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom) - (HostControl.Margin.Top + HostControl.Margin.Bottom)); + } else + { TotalHeight = finalSize.Height; - - SheetRoot.Height = Math.Max(0, finalSize.Height - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom)); + SheetRoot.Height = Math.Max(0, finalSize.Height - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom) - (HostControl.Margin.Top + HostControl.Margin.Bottom)); + } return base.ArrangeOverride(finalSize); } @@ -76,8 +82,18 @@ internal void ShowSheet(SheetControl control) VisualStateManager.GoToState(this, "Open", true); Window.Current.SetTitleBar(TitleBar); + var safeAreaService = Ioc.Default.GetRequiredService(); safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated; + + var systemNavigationManager = SystemNavigationManager.GetForCurrentView(); + systemNavigationManager.BackRequested += OnBackRequested; + } + + private async void OnBackRequested(object sender, BackRequestedEventArgs e) + { + e.Handled = true; + await HideSheetAsync(); } internal async Task HideSheetAsync() @@ -94,6 +110,9 @@ internal async Task HideSheetAsync() var safeAreaService = Ioc.Default.GetRequiredService(); safeAreaService.SafeAreaUpdated -= OnSafeAreaUpdated; + var systemNavigationManager = SystemNavigationManager.GetForCurrentView(); + systemNavigationManager.BackRequested -= OnBackRequested; + return true; } @@ -101,8 +120,16 @@ private void OnSafeAreaUpdated(object sender, SafeAreaUpdatedEventArgs e) { TitleBar.Height = e.SafeArea.Bounds.Top; SheetBorder.Margin = new Thickness(0, 16 + e.SafeArea.Bounds.Top, 0, 0); - SheetRoot.Height = Math.Max(0, ActualHeight - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom)); HostControl.Margin = new Thickness(e.SafeArea.Bounds.Left, 0, e.SafeArea.Bounds.Right, e.SafeArea.Bounds.Bottom); + + if (!double.IsInfinity(HostControl.MaxHeight)) + { + SheetRoot.Height = Math.Max(0, HostControl.MaxHeight - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom) - (HostControl.Margin.Top + HostControl.Margin.Bottom)); + } + else + { + SheetRoot.Height = Math.Max(0, ActualHeight - (SheetBorder.Margin.Top + SheetBorder.Margin.Bottom) - (HostControl.Margin.Top + HostControl.Margin.Bottom)); + } } private async void RefreshContainer_RefreshRequested(MUXC.RefreshContainer sender, MUXC.RefreshRequestedEventArgs args) diff --git a/UniSky/Converters/Static.cs b/UniSky/Converters/Static.cs index c06d66a..460ae07 100644 --- a/UniSky/Converters/Static.cs +++ b/UniSky/Converters/Static.cs @@ -16,7 +16,6 @@ public static bool Not(bool x) => !x; public static bool NotNull(object x) => x is not null; - public static bool NotNullOrWhiteSpace(string s) => !string.IsNullOrWhiteSpace(s); } diff --git a/UniSky/Package.appxmanifest b/UniSky/Package.appxmanifest index 2a4fe68..3a68deb 100644 --- a/UniSky/Package.appxmanifest +++ b/UniSky/Package.appxmanifest @@ -10,7 +10,7 @@ + Version="1.0.123.0" /> diff --git a/UniSky/UniSky.csproj b/UniSky/UniSky.csproj index a741b19..a06a24a 100644 --- a/UniSky/UniSky.csproj +++ b/UniSky/UniSky.csproj @@ -149,6 +149,7 @@ + SheetRootControl.xaml @@ -373,6 +374,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -417,7 +422,7 @@ Designer MSBuild:Compile - + MSBuild:Compile Designer diff --git a/UniSky/ViewModels/Compose/ComposeViewModel.cs b/UniSky/ViewModels/Compose/ComposeViewModel.cs index 2d31689..5c127e5 100644 --- a/UniSky/ViewModels/Compose/ComposeViewModel.cs +++ b/UniSky/ViewModels/Compose/ComposeViewModel.cs @@ -20,9 +20,12 @@ public partial class ComposeViewModel : ViewModelBase { [ObservableProperty] [NotifyPropertyChangedFor(nameof(CanPost))] + [NotifyPropertyChangedFor(nameof(Characters))] private string _text; [ObservableProperty] private string _avatarUrl; + [ObservableProperty] + private int maxCharacters; private readonly IProtocolService protocolService; private readonly ILogger logger; @@ -30,10 +33,11 @@ public partial class ComposeViewModel : ViewModelBase // TODO: this but better public bool IsDirty => !string.IsNullOrEmpty(Text); - // TODO: ditto public bool CanPost - => !string.IsNullOrEmpty(Text); + => !string.IsNullOrEmpty(Text) && Text.Length <= 300; + public int Characters + => Text?.Length ?? 0; public ComposeViewModel( IProtocolService protocolService, @@ -42,6 +46,8 @@ public ComposeViewModel( this.protocolService = protocolService; this.logger = logger; + this.MaxCharacters = 300; + Task.Run(LoadAsync); }