Skip to content

Commit

Permalink
Fix Folder has 'new' label if all videos are played
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk907 committed May 8, 2019
1 parent 85f0c11 commit 37dd9e2
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions VideoPlayerTrimmer/VideoPlayerTrimmer/Services/VideoLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ public async Task Refresh()
{
await libraryUpdater.UpdateAsync();
var videos = await database.GetAsync<VideoFileTable>(e => e.VideoId, e => !e.IsDeleted);
folderItems.Clear();
videoItems.Clear();
foreach(var directoryGroup in videos.GroupBy(e => e.Directory))
foreach(var video in videos)
{
videoItems.Add(video.ToVideoItem());
}
RefreshFolders();
}

private void RefreshFolders()
{
folderItems.Clear();
foreach(var group in videoItems.GroupBy(v => v.FolderPath))
{
folderItems.Add(new FolderItem()
{
AreNewVideos = directoryGroup.Any(e => e.IsNew),
FolderName = Path.GetFileName(directoryGroup.Key),
FolderPath = directoryGroup.Key,
VideoCount = directoryGroup.Count()
AreNewVideos = group.Any(e => e.IsNew),
FolderName = Path.GetFileName(group.Key),
FolderPath = group.Key,
VideoCount = group.Count()
});
}
foreach(var video in videos)
{
videoItems.Add(video.ToVideoItem());
}
}

public async Task<List<FolderItem>> GetFolderItemsAsync(bool forceUpdate = false)
Expand All @@ -53,6 +58,10 @@ public async Task<List<FolderItem>> GetFolderItemsAsync(bool forceUpdate = false
{
await Refresh();
}
else
{
RefreshFolders();
}
return folderItems;
}

Expand All @@ -63,7 +72,7 @@ public Task<VideoItem> GetVideoItemAsync(string filePath)

public async Task<List<VideoItem>> GetVideoItemsAsync(string folderPath, bool forceUpdate = false)
{
if (folderItems.Count == 0 || forceUpdate)
if (videoItems.Count == 0 || forceUpdate)
{
await Refresh();
}
Expand Down

0 comments on commit 37dd9e2

Please sign in to comment.