diff --git a/StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs index 96f38a14..df53c623 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Inference/ImageFolderCardViewModel.cs @@ -1,6 +1,4 @@ using System; -using System.Reactive.Linq; -using System.Threading; using System.Threading.Tasks; using Avalonia.Controls; using DynamicData; @@ -27,12 +25,6 @@ public partial class ImageFolderCardViewModel : ViewModelBase private readonly SourceCache localImagesSource = new(imageFile => imageFile.RelativePath); - /// - /// Collection of image files to display - /// - public IObservableCollection LocalImages { get; } = - new ObservableCollectionExtended(); - /// /// Collection of image items to display /// @@ -49,6 +41,8 @@ public partial class ImageFolderCardViewModel : ViewModelBase this.imageIndexService = imageIndexService; this.settingsManager = settingsManager; + var minDatetime = DateTimeOffset.FromUnixTimeMilliseconds(0); + localImagesSource .Connect() .DeferUntilLoaded() @@ -62,6 +56,7 @@ public partial class ImageFolderCardViewModel : ViewModelBase : imageFile.GetFullPath(settingsManager.ImagesDirectory) } ) + .SortBy(x => x.LocalImageFile?.LastModifiedAt ?? minDatetime, SortDirection.Descending) .Bind(Items) .Subscribe(); } diff --git a/StabilityMatrix.Core/Services/ImageIndexService.cs b/StabilityMatrix.Core/Services/ImageIndexService.cs index b5d795e9..c935c1d8 100644 --- a/StabilityMatrix.Core/Services/ImageIndexService.cs +++ b/StabilityMatrix.Core/Services/ImageIndexService.cs @@ -80,7 +80,9 @@ public class ImageIndexService : IImageIndexService var localImage = new LocalImageFile { RelativePath = relativePath, - ImageType = imageType + ImageType = imageType, + CreatedAt = file.Info.CreationTimeUtc, + LastModifiedAt = file.Info.LastWriteTimeUtc }; // Insert into database