Skip to content

Commit

Permalink
generate thumbnails in same order as current sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekmotyl committed Sep 11, 2022
1 parent cd40f91 commit c74c192
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageProjectUrl>https://github.com/bartekmotyl/favourite-photo-browser</PackageProjectUrl>
<PackageIcon>favourite-photo-browser-icon.png</PackageIcon>
<PackageLicenseFile>MIT</PackageLicenseFile>
<AssemblyVersion>1.0.0</AssemblyVersion>
<AssemblyVersion>1.1.0</AssemblyVersion>
<Version>$(VersionPrefix)</Version>
</PropertyGroup>
<ItemGroup>
Expand Down
20 changes: 12 additions & 8 deletions sources/Favourite Photo Browser/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@ public async Task ToggleFavourite()
currentFolderItem.Favourite = updated;
}

private void UpdateThumbnailsSorting()
private IEnumerable<FolderItemViewModel> SortFolderItems(IEnumerable<FolderItemViewModel> folderItems)
{
IEnumerable<FolderItemViewModel> sorted;
if (SelectedSortOrderIndex == 0)
sorted = allFolderItems.OrderBy(f => f.FileDate);
return folderItems.OrderBy(f => f.FileDate);
else if (SelectedSortOrderIndex == 1)
sorted = allFolderItems.OrderByDescending(f => f.FileDate);
return folderItems.OrderByDescending(f => f.FileDate);
else if (SelectedSortOrderIndex == 2)
sorted = allFolderItems.OrderBy(f => f.FileName);
else
sorted = allFolderItems.OrderByDescending(f => f.FileName);
return folderItems.OrderBy(f => f.FileName);
else
return folderItems.OrderByDescending(f => f.FileName);
}

private void UpdateThumbnailsSorting()
{
IEnumerable<FolderItemViewModel> sorted = SortFolderItems(allFolderItems);

var newItems = sorted
.Where(f => !ShowFavouritesOnly || (f.Favourite ?? 0) > 0)
Expand All @@ -115,7 +119,7 @@ private async Task LoadFilesInFolder(string folderPath)

thumbnailsLoadingJob?.CancellationTokenSource.Cancel();

var fileNamesToProcess = allFolderItems.Where(fi => !fi.Ignored).Select(fi => fi.FileName).ToArray();
var fileNamesToProcess = SortFolderItems(allFolderItems.Where(fi => !fi.Ignored)).Select(fi => fi.FileName).ToArray();
thumbnailsLoadingJob = new ThumnailsLoadingJob(folderPath, fileNamesToProcess);

var readThumnailsTask = dbConnector.ReadThumbnails(thumbnailsLoadingJob);
Expand Down

0 comments on commit c74c192

Please sign in to comment.