Browse Source

Don't show `Hide bottom gallery` menu item when in full gallery. Rename IsGalleryCloseIconVisible => IsFullGalleryOpen.

Ruben 7 tháng trước cách đây
mục cha
commit
c6ee233bb9

+ 5 - 5
src/PicView.Avalonia/CustomControls/GalleryAnimationControl.cs

@@ -163,7 +163,7 @@ public class GalleryAnimationControl : UserControl
             // Configure gallery
             ViewModel.GalleryOrientation = Orientation.Vertical;
             GalleryStretchMode.DetermineStretchMode(ViewModel);
-            ViewModel.IsGalleryCloseIconVisible = true;
+            ViewModel.IsFullGalleryOpen = true;
 
             // Animate opacity
             var opacityAnimation = AnimationsHelper.OpacityAnimation(NoOpacity, FullOpacity, MediumAnimationSpeed);
@@ -248,7 +248,7 @@ public class GalleryAnimationControl : UserControl
             // Configure gallery
             ViewModel.GalleryOrientation = Orientation.Horizontal;
             GalleryStretchMode.DetermineStretchMode(ViewModel);
-            ViewModel.IsGalleryCloseIconVisible = false;
+            ViewModel.IsFullGalleryOpen = false;
             ViewModel.GalleryVerticalAlignment = VerticalAlignment.Bottom;
 
             // Animate height
@@ -293,7 +293,7 @@ public class GalleryAnimationControl : UserControl
 
             // Configure gallery
             ViewModel.GalleryOrientation = Orientation.Horizontal;
-            ViewModel.IsGalleryCloseIconVisible = false;
+            ViewModel.IsFullGalleryOpen = false;
 
             // Animate height
             var heightAnimation = AnimationsHelper.HeightAnimation(from, ZeroHeight, FastAnimationSpeed);
@@ -326,7 +326,7 @@ public class GalleryAnimationControl : UserControl
 
             // Configure gallery
             ViewModel.GalleryOrientation = Orientation.Vertical;
-            ViewModel.IsGalleryCloseIconVisible = true;
+            ViewModel.IsFullGalleryOpen = true;
             GalleryStretchMode.DetermineStretchMode(ViewModel);
             ViewModel.GalleryItemMargin = FullGalleryItemMargin;
 
@@ -364,7 +364,7 @@ public class GalleryAnimationControl : UserControl
 
             // Configure gallery
             ViewModel.GalleryVerticalAlignment = VerticalAlignment.Bottom;
-            ViewModel.IsGalleryCloseIconVisible = false;
+            ViewModel.IsFullGalleryOpen = false;
 
             // Animate height
             var from = Bounds.Height;

+ 0 - 7
src/PicView.Avalonia/Gallery/GalleryFunctions.cs

@@ -274,7 +274,6 @@ public static class GalleryFunctions
     #region Gallery toggle
 
     public static bool IsFullGalleryOpen { get; private set; }
-    public static bool IsBottomGalleryOpen { get; private set; }
 
     public static void ToggleGallery(MainViewModel vm)
     {
@@ -286,8 +285,6 @@ public static class GalleryFunctions
         MenuManager.CloseMenus(vm);
         if (Settings.Gallery.IsBottomGalleryShown)
         {
-            // Showing bottom gallery is enabled
-            IsBottomGalleryOpen = true;
             if (IsFullGalleryOpen)
             {
                 // Switch to bottom gallery
@@ -305,7 +302,6 @@ public static class GalleryFunctions
         }
         else
         {
-            IsBottomGalleryOpen = false;
             if (IsFullGalleryOpen)
             {
                 // close full gallery
@@ -340,11 +336,9 @@ public static class GalleryFunctions
             vm.Translation.IsShowingBottomGallery = TranslationManager.Translation.ShowBottomGallery;
             Settings.Gallery.IsBottomGalleryShown = false;
             IsFullGalleryOpen = false;
-            IsBottomGalleryOpen = false;
             return;
         }
 
-        IsBottomGalleryOpen = true;
         IsFullGalleryOpen = false;
         Settings.Gallery.IsBottomGalleryShown = true;
         if (NavigationManager.CanNavigate(vm))
@@ -363,7 +357,6 @@ public static class GalleryFunctions
 
     public static void OpenBottomGallery(MainViewModel vm)
     {
-        IsBottomGalleryOpen = true;
         vm.GalleryMode = GalleryMode.ClosedToBottom;
         vm.GalleryVerticalAlignment = VerticalAlignment.Bottom;
     }

+ 81 - 74
src/PicView.Avalonia/Navigation/ImageLoader.cs

@@ -15,62 +15,6 @@ namespace PicView.Avalonia.Navigation;
 
 public static class ImageLoader
 {
-    #region Cancellation
-
-    private static CancellationTokenSource? _cancellationTokenSource;
-    
-    public static void Cancel()
-    {
-        if (_cancellationTokenSource is not null)
-        {
-            _cancellationTokenSource.Cancel();
-            _cancellationTokenSource.Dispose();
-            _cancellationTokenSource = null;
-        }
-
-        _cancellationTokenSource = new CancellationTokenSource();
-    }
-
-    public static async Task CancelAsync()
-    {
-        if (_cancellationTokenSource is not null)
-        {
-            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
-            _cancellationTokenSource.Dispose();
-            _cancellationTokenSource = null;
-        }
-
-        _cancellationTokenSource = new CancellationTokenSource();
-    }
-
-    #endregion
-
-    #region Image Iterator Loading
-
-    public static async Task LastIterationAsync(ImageIterator imageIterator) => await imageIterator.NextIteration(NavigateTo.Last, _cancellationTokenSource)
-        .ConfigureAwait(false);
-    
-    public static async Task FirstIterationAsync(ImageIterator imageIterator) => await imageIterator.NextIteration(NavigateTo.First, _cancellationTokenSource)
-        .ConfigureAwait(false);
-    
-    /// <summary>
-    ///     Checks if the previous iteration has been cancelled and starts the iteration at the given index
-    /// </summary>
-    /// <param name="index">The index to iterate to.</param>
-    /// <param name="imageIterator">The ImageIterator instance.</param>
-    public static async Task CheckCancellationAndStartIterateToIndex(int index, ImageIterator imageIterator)
-    {
-        if (_cancellationTokenSource is not null)
-        {
-            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
-        }
-
-        _cancellationTokenSource = new CancellationTokenSource();
-        await imageIterator.NextIteration(index, _cancellationTokenSource).ConfigureAwait(false);
-    }
-
-    #endregion
-
     #region Load Pic From String
 
     /// <summary>
@@ -142,10 +86,10 @@ public static class ImageLoader
 
     #endregion
 
-
     #region Load Pic From File
-    
-    public static async Task LoadPicFromFile(string fileName, MainViewModel vm, ImageIterator imageIterator, FileInfo? fileInfo = null)
+
+    public static async Task LoadPicFromFile(string fileName, MainViewModel vm, ImageIterator imageIterator,
+        FileInfo? fileInfo = null)
     {
         if (vm is null)
         {
@@ -176,12 +120,12 @@ public static class ImageLoader
                 }
                 else
                 {
-                    await NavigationManager.LoadWithoutImageIterator(fileInfo, vm);
+                    await NavigationManager.LoadWithoutImageIterator(fileInfo, vm).ConfigureAwait(false);
                 }
             }
             else
             {
-                await NavigationManager.LoadWithoutImageIterator(fileInfo, vm);
+                await NavigationManager.LoadWithoutImageIterator(fileInfo, vm).ConfigureAwait(false);
             }
         }
         else
@@ -191,7 +135,7 @@ public static class ImageLoader
                 vm.PlatformService.StopTaskbarProgress();
             }
 
-            await NavigationManager.LoadWithoutImageIterator(fileInfo, vm);
+            await NavigationManager.LoadWithoutImageIterator(fileInfo, vm).ConfigureAwait(false);
         }
     }
 
@@ -268,12 +212,12 @@ public static class ImageLoader
     /// </summary>
     /// <param name="path">The path to the archive file containing the picture(s) to load.</param>
     /// <param name="vm">The main view model instance used to manage UI state and operations.</param>
-    ///  <param name="imageIterator">The image iterator to use for navigation.</param>
+    /// <param name="imageIterator">The image iterator to use for navigation.</param>
     public static async Task LoadPicFromArchiveAsync(string path, MainViewModel vm, ImageIterator imageIterator)
     {
         if (_cancellationTokenSource is not null)
         {
-            await _cancellationTokenSource.CancelAsync();
+            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
         }
 
         vm.IsLoading = true;
@@ -309,12 +253,11 @@ public static class ImageLoader
             await ErrorHandling.ReloadAsync(vm);
         }
     }
-    
 
     #endregion
 
     #region Load Pic From URL
-    
+
     /// <summary>
     ///     Loads a picture from a given URL.
     /// </summary>
@@ -359,7 +302,7 @@ public static class ImageLoader
             {
                 tasks.Add(imageIterator.DisposeAsync().AsTask());
             }
-            
+
             await Task.WhenAll(tasks).ConfigureAwait(false);
             destination = httpDownload.DownloadPath;
         }
@@ -396,7 +339,7 @@ public static class ImageLoader
 
     #region Load Pic From Base64
 
-        /// <summary>
+    /// <summary>
     ///     Loads a picture from a Base64-encoded string.
     /// </summary>
     /// <param name="base64">The Base64-encoded string representing the picture.</param>
@@ -408,12 +351,13 @@ public static class ImageLoader
         vm.IsLoading = true;
         vm.PicViewer.ImageSource = null;
         vm.PicViewer.FileInfo = null;
-        
+
         if (_cancellationTokenSource is not null)
         {
-            await _cancellationTokenSource.CancelAsync();
+            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
         }
-        await NavigationManager.DisposeImageIteratorAsync();
+
+        await NavigationManager.DisposeImageIteratorAsync().ConfigureAwait(false);
 
         await Task.Run(async () =>
         {
@@ -443,7 +387,7 @@ public static class ImageLoader
 #endif
                 if (vm.PicViewer.FileInfo is not null && vm.PicViewer.FileInfo.Exists)
                 {
-                    await LoadPicFromFile(vm.PicViewer.FileInfo.FullName, vm, imageIterator, vm.PicViewer.FileInfo);
+                    await LoadPicFromFile(vm.PicViewer.FileInfo.FullName, vm, imageIterator, vm.PicViewer.FileInfo).ConfigureAwait(false);
                 }
                 else
                 {
@@ -456,5 +400,68 @@ public static class ImageLoader
     }
 
     #endregion
-    
-}
+
+    #region Cancellation
+
+    private static CancellationTokenSource? _cancellationTokenSource;
+
+    public static void Cancel()
+    {
+        if (_cancellationTokenSource is not null)
+        {
+            _cancellationTokenSource.Cancel();
+            _cancellationTokenSource.Dispose();
+            _cancellationTokenSource = null;
+        }
+
+        _cancellationTokenSource = new CancellationTokenSource();
+    }
+
+    public static async Task CancelAsync()
+    {
+        if (_cancellationTokenSource is not null)
+        {
+            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
+            _cancellationTokenSource.Dispose();
+            _cancellationTokenSource = null;
+        }
+
+        _cancellationTokenSource = new CancellationTokenSource();
+    }
+
+    #endregion
+
+    #region Image Iterator Loading
+
+    /// <inheritdoc cref="ImageIterator.NextIteration(NavigateTo, CancellationTokenSource)" />
+    public static async Task LastIterationAsync(ImageIterator imageIterator) => await imageIterator
+        .NextIteration(NavigateTo.Last, _cancellationTokenSource)
+        .ConfigureAwait(false);
+
+    /// <inheritdoc cref="ImageIterator.NextIteration(NavigateTo, CancellationTokenSource)" />
+    public static async Task FirstIterationAsync(ImageIterator imageIterator) => await imageIterator
+        .NextIteration(NavigateTo.First, _cancellationTokenSource)
+        .ConfigureAwait(false);
+
+    /// <summary>
+    ///     Checks if the previous iteration has been cancelled and starts the iteration at the given index
+    /// </summary>
+    /// <param name="index">The index to iterate to.</param>
+    /// <param name="imageIterator">The ImageIterator instance.</param>
+    public static async Task CheckCancellationAndStartIterateToIndex(int index, ImageIterator imageIterator)
+    {
+        if (_cancellationTokenSource is not null)
+        {
+            await _cancellationTokenSource.CancelAsync().ConfigureAwait(false);
+        }
+
+        // Need to start in new task. This makes it more responsive, since it can get laggy when loading large images
+        await Task.Run(async () =>
+        {
+            _cancellationTokenSource = new CancellationTokenSource();
+            await imageIterator.NextIteration(index, _cancellationTokenSource).ConfigureAwait(false);
+        }).ConfigureAwait(false);
+    }
+
+    #endregion
+}

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

@@ -341,7 +341,7 @@ public class MainViewModel : ReactiveObject
         get;
     }
 
-    public bool IsGalleryCloseIconVisible
+    public bool IsFullGalleryOpen
     {
         get;
         set => this.RaiseAndSetIfChanged(ref field, value);

+ 7 - 3
src/PicView.Avalonia/Views/GalleryView.axaml

@@ -95,8 +95,12 @@
                         </Flyout>
                     </FlyoutBase.AttachedFlyout>
                 </MenuItem>
-                <Separator />
-                <MenuItem Command="{CompiledBinding CloseGalleryCommand}" Header="{CompiledBinding Translation.HideBottomGallery, Mode=OneWay}">
+                <Separator IsVisible="{CompiledBinding !IsFullGalleryOpen}" />
+                <MenuItem
+                    Command="{CompiledBinding CloseGalleryCommand}"
+                    Header="{CompiledBinding Translation.HideBottomGallery,
+                                             Mode=OneWay}"
+                    IsVisible="{CompiledBinding !IsFullGalleryOpen}">
                     <MenuItem.Icon>
                         <Path
                             Data="{StaticResource CloseGeometry}"
@@ -117,7 +121,7 @@
             DockPanel.Dock="Right"
             Height="60"
             HorizontalAlignment="Right"
-            IsVisible="{CompiledBinding IsGalleryCloseIconVisible}"
+            IsVisible="{CompiledBinding IsFullGalleryOpen}"
             VerticalAlignment="Top"
             Width="50"
             ZIndex="99">