Add - Filter By Air date toggle to custom calendar

This commit is contained in:
Elwador 2024-07-13 13:26:11 +02:00
parent c4922af741
commit 6b44dbf28c
4 changed files with 107 additions and 36 deletions

51
CRD/CRD.csproj Normal file
View File

@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<ApplicationIcon>Assets\app_icon.ico</ApplicationIcon>
<Version>1.5.2.0</Version>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0-beta2" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0-beta2" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0-beta2" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="ExtendedXmlSerializer" Version="3.7.18" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview5" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.60" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="YamlDotNet" Version="15.1.2" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Styling\ControlsGalleryStyles.axaml" />
<UpToDateCheckInput Remove="Styling\ControlThemes.axaml" />
<UpToDateCheckInput Remove="Views\Utils\ErrorWindow.axaml" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\Utils\ContentDialogUpdateView.axaml.cs">
<DependentUpon>ContentDialogInputLoginView.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\Utils\ContentDialogInputLoginView.axaml.cs">
<DependentUpon>ContentDialogInputLoginView.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@ -140,6 +140,9 @@ public class CrDownloadOptions{
[YamlMember(Alias = "calendar_hide_dubs", ApplyNamingConventions = false)] [YamlMember(Alias = "calendar_hide_dubs", ApplyNamingConventions = false)]
public bool CalendarHideDubs{ get; set; } public bool CalendarHideDubs{ get; set; }
[YamlMember(Alias = "calendar_filter_by_air_date", ApplyNamingConventions = false)]
public bool CalendarFilterByAirDate{ get; set; }
[YamlMember(Alias = "history", ApplyNamingConventions = false)] [YamlMember(Alias = "history", ApplyNamingConventions = false)]
public bool History{ get; set; } public bool History{ get; set; }

View File

@ -16,23 +16,25 @@ public partial class CalendarPageViewModel : ViewModelBase{
public ObservableCollection<CalendarDay> CalendarDays{ get; set; } public ObservableCollection<CalendarDay> CalendarDays{ get; set; }
[ObservableProperty] [ObservableProperty]
private bool _showLoading; private bool _showLoading;
[ObservableProperty] [ObservableProperty]
private bool _customCalendar; private bool _customCalendar;
[ObservableProperty]
private bool _filterByAirDate;
[ObservableProperty] [ObservableProperty]
private bool _hideDubs; private bool _hideDubs;
public ObservableCollection<ComboBoxItem> CalendarDubFilter{ get; } = new(){ public ObservableCollection<ComboBoxItem> CalendarDubFilter{ get; } = new(){
new ComboBoxItem(){ Content = "none" }, new ComboBoxItem(){ Content = "none" },
}; };
[ObservableProperty] [ObservableProperty]
private ComboBoxItem? _currentCalendarDubFilter; private ComboBoxItem? _currentCalendarDubFilter;
public ObservableCollection<ComboBoxItem> CalendarLanguage{ get; } = new(){ public ObservableCollection<ComboBoxItem> CalendarLanguage{ get; } = new(){
new ComboBoxItem(){ Content = "en-us" }, new ComboBoxItem(){ Content = "en-us" },
new ComboBoxItem(){ Content = "es" }, new ComboBoxItem(){ Content = "es" },
@ -46,27 +48,28 @@ public partial class CalendarPageViewModel : ViewModelBase{
new ComboBoxItem(){ Content = "ru" }, new ComboBoxItem(){ Content = "ru" },
new ComboBoxItem(){ Content = "hi" }, new ComboBoxItem(){ Content = "hi" },
}; };
[ObservableProperty] [ObservableProperty]
private ComboBoxItem? _currentCalendarLanguage; private ComboBoxItem? _currentCalendarLanguage;
private CalendarWeek? currentWeek; private CalendarWeek? currentWeek;
private bool loading = true; private bool loading = true;
public CalendarPageViewModel(){ public CalendarPageViewModel(){
CalendarDays = new ObservableCollection<CalendarDay>(); CalendarDays = new ObservableCollection<CalendarDay>();
foreach (var languageItem in Languages.languages){ foreach (var languageItem in Languages.languages){
CalendarDubFilter.Add(new ComboBoxItem{ Content = languageItem.CrLocale }); CalendarDubFilter.Add(new ComboBoxItem{ Content = languageItem.CrLocale });
} }
CustomCalendar = Crunchyroll.Instance.CrunOptions.CustomCalendar; CustomCalendar = Crunchyroll.Instance.CrunOptions.CustomCalendar;
HideDubs = Crunchyroll.Instance.CrunOptions.CalendarHideDubs; HideDubs = Crunchyroll.Instance.CrunOptions.CalendarHideDubs;
HideDubs = Crunchyroll.Instance.CrunOptions.CalendarFilterByAirDate;
ComboBoxItem? dubfilter = CalendarDubFilter.FirstOrDefault(a => a.Content != null && (string)a.Content == Crunchyroll.Instance.CrunOptions.CalendarDubFilter) ?? null; ComboBoxItem? dubfilter = CalendarDubFilter.FirstOrDefault(a => a.Content != null && (string)a.Content == Crunchyroll.Instance.CrunOptions.CalendarDubFilter) ?? null;
CurrentCalendarDubFilter = dubfilter ?? CalendarDubFilter[0]; CurrentCalendarDubFilter = dubfilter ?? CalendarDubFilter[0];
CurrentCalendarLanguage = CalendarLanguage.FirstOrDefault(a => a.Content != null && (string)a.Content == Crunchyroll.Instance.CrunOptions.SelectedCalendarLanguage) ?? CalendarLanguage[0]; CurrentCalendarLanguage = CalendarLanguage.FirstOrDefault(a => a.Content != null && (string)a.Content == Crunchyroll.Instance.CrunOptions.SelectedCalendarLanguage) ?? CalendarLanguage[0];
loading = false; loading = false;
LoadCalendar(GetThisWeeksMondayDate(), false); LoadCalendar(GetThisWeeksMondayDate(), false);
@ -95,12 +98,11 @@ public partial class CalendarPageViewModel : ViewModelBase{
} }
public async void LoadCalendar(string mondayDate, bool forceUpdate){ public async void LoadCalendar(string mondayDate, bool forceUpdate){
if (CustomCalendar){ if (CustomCalendar){
BuildCustomCalendar(); BuildCustomCalendar();
return; return;
} }
ShowLoading = true; ShowLoading = true;
CalendarWeek week = await Crunchyroll.Instance.GetCalendarForDate(mondayDate, forceUpdate); CalendarWeek week = await Crunchyroll.Instance.GetCalendarForDate(mondayDate, forceUpdate);
if (currentWeek != null && currentWeek == week){ if (currentWeek != null && currentWeek == week){
@ -113,7 +115,7 @@ public partial class CalendarPageViewModel : ViewModelBase{
CalendarDays.AddRange(week.CalendarDays); CalendarDays.AddRange(week.CalendarDays);
RaisePropertyChanged(nameof(CalendarDays)); RaisePropertyChanged(nameof(CalendarDays));
ShowLoading = false; ShowLoading = false;
foreach (var calendarDay in CalendarDays){ foreach (var calendarDay in CalendarDays){
var episodesCopy = new List<CalendarEpisode>(calendarDay.CalendarEpisodes); var episodesCopy = new List<CalendarEpisode>(calendarDay.CalendarEpisodes);
foreach (var calendarDayCalendarEpisode in episodesCopy){ foreach (var calendarDayCalendarEpisode in episodesCopy){
@ -121,6 +123,7 @@ public partial class CalendarPageViewModel : ViewModelBase{
calendarDay.CalendarEpisodes.Remove(calendarDayCalendarEpisode); calendarDay.CalendarEpisodes.Remove(calendarDayCalendarEpisode);
continue; continue;
} }
if (calendarDayCalendarEpisode.ImageBitmap == null){ if (calendarDayCalendarEpisode.ImageBitmap == null){
calendarDayCalendarEpisode.LoadImage(); calendarDayCalendarEpisode.LoadImage();
} }
@ -141,16 +144,15 @@ public partial class CalendarPageViewModel : ViewModelBase{
[RelayCommand] [RelayCommand]
public void Refresh(){ public void Refresh(){
if (loading){ if (loading){
return; return;
} }
if (CustomCalendar){ if (CustomCalendar){
BuildCustomCalendar(); BuildCustomCalendar();
return; return;
} }
string mondayDate; string mondayDate;
if (currentWeek is{ FirstDayOfWeekString: not null }){ if (currentWeek is{ FirstDayOfWeekString: not null }){
@ -167,7 +169,7 @@ public partial class CalendarPageViewModel : ViewModelBase{
if (loading){ if (loading){
return; return;
} }
string mondayDate; string mondayDate;
if (currentWeek is{ FirstDayOfWeek: not null }){ if (currentWeek is{ FirstDayOfWeek: not null }){
@ -184,7 +186,7 @@ public partial class CalendarPageViewModel : ViewModelBase{
if (loading){ if (loading){
return; return;
} }
string mondayDate; string mondayDate;
if (currentWeek is{ FirstDayOfWeek: not null }){ if (currentWeek is{ FirstDayOfWeek: not null }){
@ -201,7 +203,7 @@ public partial class CalendarPageViewModel : ViewModelBase{
if (loading){ if (loading){
return; return;
} }
if (value?.Content != null){ if (value?.Content != null){
Crunchyroll.Instance.CrunOptions.SelectedCalendarLanguage = value.Content.ToString(); Crunchyroll.Instance.CrunOptions.SelectedCalendarLanguage = value.Content.ToString();
Refresh(); Refresh();
@ -213,13 +215,13 @@ public partial class CalendarPageViewModel : ViewModelBase{
if (loading){ if (loading){
return; return;
} }
if (CustomCalendar){ if (CustomCalendar){
BuildCustomCalendar(); BuildCustomCalendar();
} else{ } else{
LoadCalendar(GetThisWeeksMondayDate(), true); LoadCalendar(GetThisWeeksMondayDate(), true);
} }
Crunchyroll.Instance.CrunOptions.CustomCalendar = value; Crunchyroll.Instance.CrunOptions.CustomCalendar = value;
CfgManager.WriteSettingsToFile(); CfgManager.WriteSettingsToFile();
} }
@ -228,10 +230,19 @@ public partial class CalendarPageViewModel : ViewModelBase{
if (loading){ if (loading){
return; return;
} }
Crunchyroll.Instance.CrunOptions.CalendarHideDubs = value; Crunchyroll.Instance.CrunOptions.CalendarHideDubs = value;
CfgManager.WriteSettingsToFile(); CfgManager.WriteSettingsToFile();
} }
partial void OnFilterByAirDateChanged(bool value){
if (loading){
return;
}
Crunchyroll.Instance.CrunOptions.CalendarFilterByAirDate = value;
CfgManager.WriteSettingsToFile();
}
partial void OnCurrentCalendarDubFilterChanged(ComboBoxItem? value){ partial void OnCurrentCalendarDubFilterChanged(ComboBoxItem? value){
if (loading){ if (loading){
@ -242,13 +253,12 @@ public partial class CalendarPageViewModel : ViewModelBase{
Crunchyroll.Instance.CrunOptions.CalendarDubFilter = value?.Content + ""; Crunchyroll.Instance.CrunOptions.CalendarDubFilter = value?.Content + "";
CfgManager.WriteSettingsToFile(); CfgManager.WriteSettingsToFile();
} }
} }
private async void BuildCustomCalendar(){ private async void BuildCustomCalendar(){
ShowLoading = true; ShowLoading = true;
var newEpisodesBase = await Crunchyroll.Instance.CrEpisode.GetNewEpisodes(Crunchyroll.Instance.CrunOptions.HistoryLang,200); var newEpisodesBase = await Crunchyroll.Instance.CrEpisode.GetNewEpisodes(Crunchyroll.Instance.CrunOptions.HistoryLang, 200);
CalendarWeek week = new CalendarWeek(); CalendarWeek week = new CalendarWeek();
week.CalendarDays = new List<CalendarDay>(); week.CalendarDays = new List<CalendarDay>();
@ -271,8 +281,8 @@ public partial class CalendarPageViewModel : ViewModelBase{
var newEpisodes = newEpisodesBase.Data; var newEpisodes = newEpisodesBase.Data;
foreach (var crBrowseEpisode in newEpisodes){ foreach (var crBrowseEpisode in newEpisodes){
var episodeAirDate = crBrowseEpisode.EpisodeMetadata.EpisodeAirDate; var targetDate = FilterByAirDate ? crBrowseEpisode.EpisodeMetadata.EpisodeAirDate : crBrowseEpisode.LastPublic;
if (HideDubs && crBrowseEpisode.EpisodeMetadata.SeasonTitle != null && crBrowseEpisode.EpisodeMetadata.SeasonTitle.EndsWith("Dub)")){ if (HideDubs && crBrowseEpisode.EpisodeMetadata.SeasonTitle != null && crBrowseEpisode.EpisodeMetadata.SeasonTitle.EndsWith("Dub)")){
continue; continue;
} }
@ -284,13 +294,15 @@ public partial class CalendarPageViewModel : ViewModelBase{
} }
} }
var calendarDay = week.CalendarDays.FirstOrDefault(day => day.DateTime != null && day.DateTime.Value.Date == episodeAirDate.Date); var calendarDay = (from day in week.CalendarDays
where day.DateTime.HasValue && day.DateTime.Value.Date == targetDate.Date
select day).FirstOrDefault();
if (calendarDay != null){ if (calendarDay != null){
CalendarEpisode calEpisode = new CalendarEpisode(); CalendarEpisode calEpisode = new CalendarEpisode();
calEpisode.DateTime = episodeAirDate; calEpisode.DateTime = targetDate;
calEpisode.HasPassed = DateTime.Now > episodeAirDate; calEpisode.HasPassed = DateTime.Now > targetDate;
calEpisode.EpisodeName = crBrowseEpisode.Title; calEpisode.EpisodeName = crBrowseEpisode.Title;
calEpisode.SeriesUrl = "https://www.crunchyroll.com/series/" + crBrowseEpisode.EpisodeMetadata.SeriesId; calEpisode.SeriesUrl = "https://www.crunchyroll.com/series/" + crBrowseEpisode.EpisodeMetadata.SeriesId;
calEpisode.EpisodeUrl = $"https://www.crunchyroll.com/de/watch/{crBrowseEpisode.Id}/"; calEpisode.EpisodeUrl = $"https://www.crunchyroll.com/de/watch/{crBrowseEpisode.Id}/";

View File

@ -90,16 +90,21 @@
<controls:SettingsExpander IsVisible="{Binding CustomCalendar}" Header="Custom Calendar Dub Filter"> <controls:SettingsExpander IsVisible="{Binding CustomCalendar}" Header="Custom Calendar Dub Filter">
<controls:SettingsExpander.Footer> <controls:SettingsExpander.Footer>
<StackPanel Orientation="Vertical">
<ComboBox HorizontalAlignment="Center" Margin="10 0 0 0" MinWidth="200" <ComboBox HorizontalAlignment="Center" Margin="5 0 0 5" MinWidth="200"
SelectedItem="{Binding CurrentCalendarDubFilter}" SelectedItem="{Binding CurrentCalendarDubFilter}"
ItemsSource="{Binding CalendarDubFilter}"> ItemsSource="{Binding CalendarDubFilter}">
</ComboBox> </ComboBox>
<CheckBox IsChecked="{Binding FilterByAirDate}"
Content="Filter by episode air date" Margin="5 5 0 0">
</CheckBox>
</StackPanel>
</controls:SettingsExpander.Footer> </controls:SettingsExpander.Footer>
</controls:SettingsExpander> </controls:SettingsExpander>
<controls:SettingsExpander Header="Calendar "> <controls:SettingsExpander Header="Calendar ">
<controls:SettingsExpander.Footer> <controls:SettingsExpander.Footer>
<CheckBox IsChecked="{Binding HideDubs}" <CheckBox IsChecked="{Binding HideDubs}"