瀏覽代碼

[Avalonia] Gallery fixes, refactor, misc

Ruben 1 年之前
父節點
當前提交
b10f9c3227

+ 31 - 15
src/PicView.Avalonia/CustomControls/GalleryAnimationControl.cs

@@ -17,6 +17,21 @@ namespace PicView.Avalonia.CustomControls;
 
 public class GalleryAnimationControl : UserControl
 {
+    #region Properties
+
+    public static readonly AvaloniaProperty<GalleryMode?> GalleryModeProperty =
+        AvaloniaProperty.Register<GalleryAnimationControl, GalleryMode?>(nameof(GalleryMode));
+
+    public GalleryMode GalleryMode
+    {
+        get => (GalleryMode)(GetValue(GalleryModeProperty) ?? false);
+        set => SetValue(GalleryModeProperty, value);
+    }
+
+    private bool _isAnimating;
+    
+    #endregion
+    
     #region Constructors
     protected GalleryAnimationControl()
     {
@@ -36,6 +51,7 @@ public class GalleryAnimationControl : UserControl
                         GalleryMode.ClosedToFull => ClosedToFullAnimation(),
                         GalleryMode.ClosedToBottom => ClosedToBottomAnimation(),
                         GalleryMode.Closed => CloseWithNoAnimation(),
+                        GalleryMode.BottomNoAnimation => BottomNoAnimation(),
                         _ => throw new ArgumentOutOfRangeException(nameof(galleryMode), galleryMode, null)
                     };
                 }).Subscribe();
@@ -48,21 +64,6 @@ public class GalleryAnimationControl : UserControl
         };
     }
 
-    #endregion
-    
-    #region Properties
-
-    public static readonly AvaloniaProperty<GalleryMode?> GalleryModeProperty =
-        AvaloniaProperty.Register<GalleryAnimationControl, GalleryMode?>(nameof(GalleryMode));
-
-    public GalleryMode GalleryMode
-    {
-        get => (GalleryMode)(GetValue(GalleryModeProperty) ?? false);
-        set => SetValue(GalleryModeProperty, value);
-    }
-
-    private bool _isAnimating;
-    
     #endregion
 
     #region Animation Methods
@@ -77,6 +78,21 @@ public class GalleryAnimationControl : UserControl
         });
     }
 
+    private async Task BottomNoAnimation()
+    {
+        if (DataContext is not MainViewModel vm)
+        {
+            return;
+        }
+        await Dispatcher.UIThread.InvokeAsync(() =>
+        {
+            IsVisible = true;
+            Opacity = 1;
+            Height = double.NaN;
+            vm.GalleryOrientation = Orientation.Horizontal;
+        });
+    }
+
     private async Task ClosedToFullAnimation()
     {
         if (DataContext is not MainViewModel vm || _isAnimating)

+ 5 - 8
src/PicView.Avalonia/Gallery/GalleryLoad.cs

@@ -1,13 +1,13 @@
-#if DEBUG
-using System.Diagnostics;
-#endif
+
 using Avalonia.Threading;
 using PicView.Avalonia.ImageHandling;
 using PicView.Avalonia.UI;
-using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Views.UC;
 using PicView.Core.Gallery;
 using PicView.Core.Localization;
+#if DEBUG
+using PicView.Avalonia.ViewModels;
+#endif
 
 namespace PicView.Avalonia.Gallery;
 
@@ -72,10 +72,7 @@ public static class GalleryLoad
             _ => DispatcherPriority.Normal
         };
 
-        if (GalleryFunctions.IsBottomGalleryOpen)
-        {
-            GalleryStretchMode.SetSquareFillStretch(vm);
-        }
+        GalleryStretchMode.SetSquareFillStretch(vm);
         var fileInfos = new FileInfo[endIndex];
         try
         {

+ 1 - 1
src/PicView.Avalonia/Navigation/ImageIterator.cs

@@ -584,7 +584,7 @@ public sealed class ImageIterator : IDisposable
         if (_vm.SelectedGalleryItemIndex != index)
         {
             _vm.SelectedGalleryItemIndex = index;
-            if (GalleryFunctions.IsBottomGalleryOpen)
+            if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
             {
                 GalleryNavigation.CenterScrollToSelectedItem(_vm);
             }

+ 5 - 0
src/PicView.Avalonia/Navigation/NavigationHelper.cs

@@ -184,24 +184,28 @@ public static class NavigationHelper
                 vm.CurrentView = vm.ImageViewer;
                 await LoadPicFromFile(check, vm).ConfigureAwait(false);
                 vm.IsLoading = false;
+                ArchiveExtraction.Cleanup();
                 return;
 
             case "web":
                 vm.CurrentView = vm.ImageViewer;
                 await LoadPicFromUrlAsync(source, vm).ConfigureAwait(false);
                 vm.IsLoading = false;
+                ArchiveExtraction.Cleanup();
                 return;
 
             case "base64":
                 vm.CurrentView = vm.ImageViewer;
                 await LoadPicFromBase64Async(source, vm).ConfigureAwait(false);
                 vm.IsLoading = false;
+                ArchiveExtraction.Cleanup();
                 return;
 
             case "directory":
                 vm.CurrentView = vm.ImageViewer;
                 await LoadPicFromDirectoryAsync(source, vm).ConfigureAwait(false);
                 vm.IsLoading = false;
+                ArchiveExtraction.Cleanup();
                 return;
 
             case "zip":
@@ -213,6 +217,7 @@ public static class NavigationHelper
             case "":
                 await ErrorHandling.ReloadAsync(vm);
                 vm.IsLoading = false;
+                ArchiveExtraction.Cleanup();
                 return;
         }
     }

+ 4 - 0
src/PicView.Avalonia/Navigation/QuickLoad.cs

@@ -5,6 +5,7 @@ using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 using PicView.Core.Config;
 using PicView.Core.FileHandling;
+using PicView.Core.Gallery;
 
 namespace PicView.Avalonia.Navigation;
 
@@ -79,14 +80,17 @@ public static class QuickLoad
         {
             if (vm.IsInterfaceShown)
             {
+                vm.GalleryMode = GalleryMode.BottomNoAnimation;
                 tasks.Add(GalleryLoad.LoadGallery(vm, fileInfo.DirectoryName));
             }
             else if (SettingsHelper.Settings.Gallery.ShowBottomGalleryInHiddenUI)
             {
+                vm.GalleryMode = GalleryMode.BottomNoAnimation;
                 tasks.Add(GalleryLoad.LoadGallery(vm, fileInfo.DirectoryName));
             }
             else if (SettingsHelper.Settings.WindowProperties.Fullscreen)
             {
+                vm.GalleryMode = GalleryMode.BottomNoAnimation;
                 tasks.Add(GalleryLoad.LoadGallery(vm, fileInfo.DirectoryName));
             }
         }

+ 0 - 6
src/PicView.Avalonia/UI/StartUpHelper.cs

@@ -1,7 +1,6 @@
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Primitives;
-using PicView.Avalonia.Gallery;
 using PicView.Avalonia.Keybindings;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.ViewModels;
@@ -147,11 +146,6 @@ public static class StartUpHelper
         
         ThemeHelper.SetBackground(vm);
         
-        if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
-        {
-            GalleryFunctions.OpenBottomGallery(vm);
-        }
-        
         Task.Run(KeybindingsHelper.LoadKeybindings);
         
         vm.GetLooping = SettingsHelper.Settings.UIProperties.Looping

+ 2 - 2
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -103,7 +103,7 @@ public class MainViewModel : ViewModelBase
         set => this.RaiseAndSetIfChanged(ref _isBottomGalleryShownInHiddenUi, value);
     }
 
-    private GalleryMode _galleryMode;
+    private GalleryMode _galleryMode = GalleryMode.Closed;
 
     public GalleryMode GalleryMode
     {
@@ -127,7 +127,7 @@ public class MainViewModel : ViewModelBase
         set => this.RaiseAndSetIfChanged(ref _selectedGalleryItemIndex, value);
     }
 
-    private VerticalAlignment _galleryVerticalAlignment;
+    private VerticalAlignment _galleryVerticalAlignment = VerticalAlignment.Bottom;
 
     public VerticalAlignment GalleryVerticalAlignment
     {

+ 1 - 0
src/PicView.Avalonia/Views/GalleryView.axaml

@@ -141,6 +141,7 @@
             BorderThickness="0,1,0,0"
             Focusable="False"
             Padding="0"
+            VerticalAlignment="{CompiledBinding GalleryVerticalAlignment}"
             ScrollViewer.HorizontalScrollBarVisibility="Visible"
             ScrollViewer.IsScrollInertiaEnabled="True"
             ScrollViewer.VerticalScrollBarVisibility="Disabled"

+ 2 - 1
src/PicView.Core/Gallery/GalleryMode.cs

@@ -10,5 +10,6 @@
         BottomToClosed,
         ClosedToFull,
         ClosedToBottom,
-        Closed
+        Closed,
+        BottomNoAnimation
     }