Browse Source

Use last modified time for image viewer sorting

pull/165/head
Ionite 1 year ago
parent
commit
ea3ab2cdcb
No known key found for this signature in database
  1. 11
      StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs
  2. 4
      StabilityMatrix.Core/Services/ImageIndexService.cs

11
StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs

@ -1,6 +1,4 @@
using System; using System;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using DynamicData; using DynamicData;
@ -27,12 +25,6 @@ public partial class ImageFolderCardViewModel : ViewModelBase
private readonly SourceCache<LocalImageFile, string> localImagesSource = private readonly SourceCache<LocalImageFile, string> localImagesSource =
new(imageFile => imageFile.RelativePath); new(imageFile => imageFile.RelativePath);
/// <summary>
/// Collection of image files to display
/// </summary>
public IObservableCollection<LocalImageFile> LocalImages { get; } =
new ObservableCollectionExtended<LocalImageFile>();
/// <summary> /// <summary>
/// Collection of image items to display /// Collection of image items to display
/// </summary> /// </summary>
@ -49,6 +41,8 @@ public partial class ImageFolderCardViewModel : ViewModelBase
this.imageIndexService = imageIndexService; this.imageIndexService = imageIndexService;
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
var minDatetime = DateTimeOffset.FromUnixTimeMilliseconds(0);
localImagesSource localImagesSource
.Connect() .Connect()
.DeferUntilLoaded() .DeferUntilLoaded()
@ -62,6 +56,7 @@ public partial class ImageFolderCardViewModel : ViewModelBase
: imageFile.GetFullPath(settingsManager.ImagesDirectory) : imageFile.GetFullPath(settingsManager.ImagesDirectory)
} }
) )
.SortBy(x => x.LocalImageFile?.LastModifiedAt ?? minDatetime, SortDirection.Descending)
.Bind(Items) .Bind(Items)
.Subscribe(); .Subscribe();
} }

4
StabilityMatrix.Core/Services/ImageIndexService.cs

@ -80,7 +80,9 @@ public class ImageIndexService : IImageIndexService
var localImage = new LocalImageFile var localImage = new LocalImageFile
{ {
RelativePath = relativePath, RelativePath = relativePath,
ImageType = imageType ImageType = imageType,
CreatedAt = file.Info.CreationTimeUtc,
LastModifiedAt = file.Info.LastWriteTimeUtc
}; };
// Insert into database // Insert into database

Loading…
Cancel
Save