From 76ddd9241aefe19b94dd567a15631f7f69ddd2eb Mon Sep 17 00:00:00 2001 From: Elwador <75888166+Elwador@users.noreply.github.com> Date: Sat, 11 May 2024 00:08:25 +0200 Subject: [PATCH] Add - Added "Add to Queue" button to history page Chg - Update button is now always visible but becomes inactive if no update is available Fix - Scaling issue in calendar Fix - Refresh all button on history page not working --- CRD/Downloader/Crunchyroll.cs | 2 +- CRD/Downloader/History.cs | 28 ++++++++++++++++++++++--- CRD/ViewModels/HistoryPageViewModel.cs | 14 ++++++++++--- CRD/Views/CalendarPageView.axaml | 29 ++++++++++++++++---------- CRD/Views/HistoryPageView.axaml | 7 +++++-- CRD/Views/MainWindow.axaml | 2 +- 6 files changed, 61 insertions(+), 21 deletions(-) diff --git a/CRD/Downloader/Crunchyroll.cs b/CRD/Downloader/Crunchyroll.cs index a4003f8..bf6aa1b 100644 --- a/CRD/Downloader/Crunchyroll.cs +++ b/CRD/Downloader/Crunchyroll.cs @@ -273,7 +273,7 @@ public class Crunchyroll{ return week; } - public async void AddEpisodeToQue(string epId, string locale, List dubLang){ + public async Task AddEpisodeToQue(string epId, string locale, List dubLang){ await CrAuth.RefreshToken(true); var episodeL = await CrEpisode.ParseEpisodeById(epId, locale); diff --git a/CRD/Downloader/History.cs b/CRD/Downloader/History.cs index f679769..1a58903 100644 --- a/CRD/Downloader/History.cs +++ b/CRD/Downloader/History.cs @@ -34,7 +34,7 @@ public class History(Crunchyroll crunInstance){ foreach (int season in result.Keys){ foreach (var key in result[season].Keys){ var s = result[season][key]; - if (seasonId != null && s.Id != seasonId) continue; + if (!string.IsNullOrEmpty(seasonId) && s.Id != seasonId) continue; var seasonData = await crunInstance.CrSeries.GetSeasonDataById(s); UpdateWithSeasonData(seasonData); } @@ -338,6 +338,28 @@ public class HistorySeries : INotifyPropertyChanged{ NewEpisodes = count; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NewEpisodes))); } + + public async Task AddNewMissingToDownloads(){ + bool foundWatched = false; + + // Iterate over the Seasons list from the end to the beginning + for (int i = Seasons.Count - 1; i >= 0 && !foundWatched; i--){ + + if (Seasons[i].SpecialSeason == true){ + continue; + } + + // Iterate over the Episodes from the end to the beginning + for (int j = Seasons[i].EpisodesList.Count - 1; j >= 0 && !foundWatched; j--){ + if (!Seasons[i].EpisodesList[j].WasDownloaded){ + //ADD to download queue + await Seasons[i].EpisodesList[j].DownloadEpisode(); + } else{ + foundWatched = true; + } + } + } + } public async Task FetchData(string? seasonId){ await Crunchyroll.Instance.CrHistory.UpdateSeries(SeriesId, seasonId); @@ -404,8 +426,8 @@ public partial class HistoryEpisode : INotifyPropertyChanged{ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WasDownloaded))); } - public void DownloadEpisode(){ - Crunchyroll.Instance.AddEpisodeToQue(EpisodeId, Crunchyroll.Instance.DefaultLocale, Crunchyroll.Instance.CrunOptions.DubLang); + public async Task DownloadEpisode(){ + await Crunchyroll.Instance.AddEpisodeToQue(EpisodeId, Crunchyroll.Instance.DefaultLocale, Crunchyroll.Instance.CrunOptions.DubLang); } } \ No newline at end of file diff --git a/CRD/ViewModels/HistoryPageViewModel.cs b/CRD/ViewModels/HistoryPageViewModel.cs index 2900b18..27905b8 100644 --- a/CRD/ViewModels/HistoryPageViewModel.cs +++ b/CRD/ViewModels/HistoryPageViewModel.cs @@ -42,10 +42,18 @@ public partial class HistoryPageViewModel : ViewModelBase{ [RelayCommand] public async void RefreshAll(){ - foreach (var historySeries in Items){ + for (int i = 0; i < Items.Count; i++) { ShowLoading = true; - await historySeries.FetchData(""); - historySeries.UpdateNewEpisodes(); + await Items[i].FetchData(""); + Items[i].UpdateNewEpisodes(); + } + ShowLoading = false; + } + + [RelayCommand] + public async void AddMissingToQueue(){ + for (int i = 0; i < Items.Count; i++) { + await Items[i].AddNewMissingToDownloads(); } ShowLoading = false; } diff --git a/CRD/Views/CalendarPageView.axaml b/CRD/Views/CalendarPageView.axaml index 8ccd3e1..36b4e1f 100644 --- a/CRD/Views/CalendarPageView.axaml +++ b/CRD/Views/CalendarPageView.axaml @@ -21,13 +21,15 @@ - - + + + - - + diff --git a/CRD/Views/MainWindow.axaml b/CRD/Views/MainWindow.axaml index cdca202..d3bc62d 100644 --- a/CRD/Views/MainWindow.axaml +++ b/CRD/Views/MainWindow.axaml @@ -65,7 +65,7 @@ + IconSource="CloudDownload" Focusable="False" IsEnabled="{Binding UpdateAvailable}" />