Переглянути джерело

[Avalonia] Refactor, rename

Ruben 1 рік тому
батько
коміт
bbc026fe61

+ 1 - 1
src/PicView.Avalonia/CustomControls/EditableTitlebar.cs

@@ -172,7 +172,7 @@ public class EditableTitlebar : TextBox
             if (saved)
             {
                 // Navigate to newly saved file
-                await vm.ImageIterator.LoadPicFromFile(new FileInfo(newPath)).ConfigureAwait(false); 
+                await NavigationHelper.LoadPicFromFile(newPath, vm).ConfigureAwait(false);
                 
                 // Delete old file
                 var deleteMsg = FileDeletionHelper.DeleteFileWithErrorMsg(oldPath, false);

+ 1 - 1
src/PicView.Avalonia/Gallery/GalleryLoad.cs

@@ -102,7 +102,7 @@ public static class GalleryLoad
                         {
                             await GalleryFunctions.ToggleGallery(vm);
                         }
-                        await vm.ImageIterator.LoadPicAtIndex(i1);
+                        await vm.ImageIterator.IterateToIndex(i1);
                     };
                     galleryListBox.Items.Add(galleryItem);
                     if (i != vm.ImageIterator?.Index)

+ 1 - 1
src/PicView.Avalonia/Gallery/GalleryNavigation.cs

@@ -176,7 +176,7 @@ public static class GalleryNavigation
         await GalleryFunctions.ToggleGallery(vm);
         if (vm.SelectedGalleryItemIndex != vm.ImageIterator.Index) 
         {
-            await vm.ImageIterator.LoadPicAtIndex(vm.SelectedGalleryItemIndex);
+            await vm.ImageIterator.IterateToIndex(vm.SelectedGalleryItemIndex);
         }
     }
 }

+ 6 - 95
src/PicView.Avalonia/Navigation/ImageIterator.cs

@@ -349,7 +349,7 @@ public sealed class ImageIterator : IDisposable
         return next;
     }
 
-    public async Task LoadNextPic(NavigateTo navigateTo)
+    public async Task NextIteration(NavigateTo navigateTo)
     {
         var index = GetIteration(Index, navigateTo);
         if (index < 0)
@@ -359,15 +359,15 @@ public sealed class ImageIterator : IDisposable
 
         if (!MainKeyboardShortcuts.IsKeyHeldDown)
         {
-            await LoadPicAtIndex(index);
+            await IterateToIndex(index);
         }
         else
         {
-            await TimerPic(index);
+            await TimerIteration(index);
         }
     }
 
-    public async Task LoadPicAtIndex(int index)
+    public async Task IterateToIndex(int index)
     {
         if (index < 0 || index >= Pics.Count)
         {
@@ -426,7 +426,7 @@ public sealed class ImageIterator : IDisposable
         catch (OperationCanceledException)
         {
 #if DEBUG
-            Console.WriteLine($"{nameof(LoadPicAtIndex)} canceled at index {index}");
+            Console.WriteLine($"{nameof(IterateToIndex)} canceled at index {index}");
 #endif
         }
         catch (Exception e)
@@ -441,98 +441,9 @@ public sealed class ImageIterator : IDisposable
         }
     }
 
-    public async Task LoadPicFromString(string path)
-    {
-        if (!Path.Exists(path))
-        {
-            return;
-            // TODO load from URL if not a file
-            throw new FileNotFoundException(path); // TODO: Replace with reload function
-        }
-        if (Directory.Exists(path))
-
-            if (path.Equals(_vm.ImageIterator.FileInfo.DirectoryName))
-            {
-                using var cts = new CancellationTokenSource();
-                await LoadPicAtIndex(0).ConfigureAwait(false);
-            }
-            else
-            {
-                await ChangeDirectoryAndLoad().ConfigureAwait(false);
-            }
-        else
-        {
-            if (Path.GetDirectoryName(path) == Path.GetDirectoryName(Pics[Index]))
-            {
-                await LoadPicFromFile(new FileInfo(path)).ConfigureAwait(false);
-            }
-            else
-            {
-                await ChangeDirectoryAndLoad().ConfigureAwait(false);
-            }
-        }
-        return;
-
-        async Task ChangeDirectoryAndLoad()
-        {
-            var fileInfo = new FileInfo(path);
-            _vm.ImageIterator?.Dispose();
-            _vm.ImageIterator = new ImageIterator(fileInfo, _vm);
-            await _vm.ImageIterator.LoadPicFromFile(new FileInfo(_vm.ImageIterator.Pics[_vm.ImageIterator.Index])).ConfigureAwait(false);
-        }
-    }
-
-    public async Task LoadPicFromFile(FileInfo fileInfo)
-    {
-        SetTitleHelper.SetLoadingTitle(_vm);
-        using var image = new MagickImage();
-        image.Ping(fileInfo);
-        var thumb = image.GetExifProfile()?.CreateThumbnail();
-        if (thumb is not null)
-        {
-            var byteArray = await Task.FromResult(thumb.ToByteArray());
-            var stream = new MemoryStream(byteArray);
-            var writableBitmap = WriteableBitmap.Decode(stream);
-            _vm.ImageSource = writableBitmap;
-            _vm.ImageType = ImageType.Bitmap;
-        }
-        var imageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
-        WindowHelper.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, imageModel.Rotation, _vm);
-        _vm.ImageSource = imageModel.Image;
-        _vm.ImageType = imageModel.ImageType;
-        var isSameFolder = Path.GetDirectoryName(fileInfo.FullName) == Path.GetDirectoryName(Pics[Index]);
-        if (isSameFolder)
-        {
-            Index = Pics.IndexOf(fileInfo.FullName);
-        }
-        await AddAsync(Index, imageModel);
-        await LoadPicAtIndex(Index);
-        if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
-        {
-            if (Pics.Count == 1)
-            {
-                _vm.GalleryMode = GalleryMode.BottomToClosed;
-            }
-
-            if (isSameFolder)
-            {
-                // Fixes not scrolling to selected item
-                GalleryNavigation.CenterScrollToSelectedItem(_vm);
-            }
-            else
-            {
-                await GalleryLoad.ReloadGalleryAsync(_vm, fileInfo.DirectoryName);
-            }
-        }
-        else
-        {
-            GalleryFunctions.Clear(_vm);
-        }
-    }
-
     private static Timer? _timer;
 
-    internal async Task TimerPic(int index)
+    internal async Task TimerIteration(int index)
     {
         if (_timer is null)
         {

+ 6 - 6
src/PicView.Avalonia/Navigation/NavigationHelper.cs

@@ -52,7 +52,7 @@ public static class NavigationHelper
         }
 
         var navigateTo = next ? NavigateTo.Next : NavigateTo.Previous;
-        await vm.ImageIterator.LoadNextPic(navigateTo).ConfigureAwait(false);
+        await vm.ImageIterator.NextIteration(navigateTo).ConfigureAwait(false);
     }
 
     public static async Task NavigateFirstOrLast(bool last, MainViewModel vm)
@@ -71,7 +71,7 @@ public static class NavigationHelper
             return;
         }
 
-        await vm.ImageIterator.LoadNextPic(last ? NavigateTo.Last : NavigateTo.First).ConfigureAwait(false);
+        await vm.ImageIterator.NextIteration(last ? NavigateTo.Last : NavigateTo.First).ConfigureAwait(false);
         
         // Fix scroll position not scrolling to the end
         if (last)
@@ -216,7 +216,7 @@ public static class NavigationHelper
                 var index = vm.ImageIterator.Pics.IndexOf(fileName);
                 if (index != -1)
                 {
-                   await vm.ImageIterator.LoadPicAtIndex(index);
+                   await vm.ImageIterator.IterateToIndex(index);
                    return;
                 }
             }
@@ -227,7 +227,7 @@ public static class NavigationHelper
         vm.ImageType = imageModel.ImageType;
         WindowHelper.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, imageModel.Rotation, vm);
         vm.ImageIterator = new ImageIterator(fileInfo, vm);
-        await vm.ImageIterator.LoadPicAtIndex(vm.ImageIterator.Pics.IndexOf(fileName));
+        await vm.ImageIterator.IterateToIndex(vm.ImageIterator.Pics.IndexOf(fileName));
         GalleryFunctions.Clear(vm);
         if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
         {
@@ -285,7 +285,7 @@ public static class NavigationHelper
         var fileInfo = new FileInfo(fileList[0]);
         vm.ImageIterator?.Dispose();
         vm.ImageIterator = new ImageIterator(fileInfo, fileList,0, vm);
-        await vm.ImageIterator.LoadPicAtIndex(0).ConfigureAwait(false);
+        await vm.ImageIterator.IterateToIndex(0).ConfigureAwait(false);
         GalleryFunctions.Clear(vm);
         if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
         {
@@ -389,7 +389,7 @@ public static class NavigationHelper
         vm.ImageType = imageModel.ImageType;
         WindowHelper.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, imageModel.Rotation, vm);
         vm.ImageIterator = new ImageIterator(fileInfo, vm);
-        await vm.ImageIterator.LoadPicAtIndex(vm.ImageIterator.Index);
+        await vm.ImageIterator.IterateToIndex(vm.ImageIterator.Index);
         GalleryFunctions.Clear(vm);
         if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
         {

+ 0 - 0
src/PicView.Avalonia/Navigation/PreloaderService.cs → src/PicView.Avalonia/Navigation/Preloader.cs


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

@@ -40,7 +40,7 @@ public static class QuickLoad
             if (isDirectory)
             {
                 vm.ImageIterator = new ImageIterator(fileInfo, vm);
-                await vm.ImageIterator.LoadPicAtIndex(0).ConfigureAwait(false);
+                await vm.ImageIterator.IterateToIndex(0).ConfigureAwait(false);
             }
             else
             {

+ 1 - 1
src/PicView.Avalonia/UI/FunctionsHelper.cs

@@ -759,7 +759,7 @@ public static class FunctionsHelper
         var newPath = FileHelper.DuplicateAndReturnFileName(oldPath);
         if (File.Exists(newPath))
         {
-            await Vm.ImageIterator.LoadPicFromFile(new FileInfo(newPath)).ConfigureAwait(false);
+            await NavigationHelper.LoadPicFromFile(newPath, Vm);
         }
     }
 

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

@@ -1339,7 +1339,7 @@ public class MainViewModel : ViewModelBase
         if (success)
         {
             ImageIterator?.PreLoader.Remove(ImageIterator.Index, ImageIterator.Pics);
-            await ImageIterator?.LoadPicAtIndex(ImageIterator.Index);
+            await ImageIterator?.IterateToIndex(ImageIterator.Index);
         }
         else
         {

+ 2 - 2
src/PicView.Avalonia/Views/ExifView.axaml.cs

@@ -44,7 +44,7 @@ public partial class ExifView : UserControl
             if (success)
             {
                 vm.ImageIterator?.PreLoader?.Remove(vm.ImageIterator.Index, vm.ImageIterator.Pics);
-                await vm.ImageIterator?.LoadPicAtIndex(vm.ImageIterator.Index);
+                await vm.ImageIterator?.IterateToIndex(vm.ImageIterator.Index);
             }
         }
     }
@@ -78,7 +78,7 @@ public partial class ExifView : UserControl
             if (success)
             {
                 vm.ImageIterator?.PreLoader?.Remove(vm.ImageIterator.Index, vm.ImageIterator.Pics);
-                await vm.ImageIterator?.LoadPicAtIndex(vm.ImageIterator.Index);
+                await vm.ImageIterator?.IterateToIndex(vm.ImageIterator.Index);
             }
         }
     }

+ 1 - 1
src/PicView.Avalonia/Views/ImageViewer.axaml.cs

@@ -182,7 +182,7 @@ public partial class ImageViewer : UserControl
                 navigateTo = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? NavigateTo.Next : NavigateTo.Previous;
             }
 
-            await mainViewModel.ImageIterator.LoadNextPic(navigateTo).ConfigureAwait(false);
+            await mainViewModel.ImageIterator.NextIteration(navigateTo).ConfigureAwait(false);
         }
     }
 

+ 1 - 1
src/PicView.Avalonia/Views/UC/Menus/ImageMenu.axaml.cs

@@ -43,7 +43,7 @@ public partial class ImageMenu  : AnimatedMenu
                 return;
             }
 
-            await vm.ImageIterator.LoadPicAtIndex(number).ConfigureAwait(false);
+            await vm.ImageIterator.IterateToIndex(number).ConfigureAwait(false);
         }
     }
 }