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
This commit is contained in:
Elwador 2024-05-11 00:08:25 +02:00
parent f911489021
commit 76ddd9241a
6 changed files with 61 additions and 21 deletions

View File

@ -273,7 +273,7 @@ public class Crunchyroll{
return week; return week;
} }
public async void AddEpisodeToQue(string epId, string locale, List<string> dubLang){ public async Task AddEpisodeToQue(string epId, string locale, List<string> dubLang){
await CrAuth.RefreshToken(true); await CrAuth.RefreshToken(true);
var episodeL = await CrEpisode.ParseEpisodeById(epId, locale); var episodeL = await CrEpisode.ParseEpisodeById(epId, locale);

View File

@ -34,7 +34,7 @@ public class History(Crunchyroll crunInstance){
foreach (int season in result.Keys){ foreach (int season in result.Keys){
foreach (var key in result[season].Keys){ foreach (var key in result[season].Keys){
var s = result[season][key]; 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); var seasonData = await crunInstance.CrSeries.GetSeasonDataById(s);
UpdateWithSeasonData(seasonData); UpdateWithSeasonData(seasonData);
} }
@ -338,6 +338,28 @@ public class HistorySeries : INotifyPropertyChanged{
NewEpisodes = count; NewEpisodes = count;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NewEpisodes))); 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){ public async Task FetchData(string? seasonId){
await Crunchyroll.Instance.CrHistory.UpdateSeries(SeriesId, seasonId); await Crunchyroll.Instance.CrHistory.UpdateSeries(SeriesId, seasonId);
@ -404,8 +426,8 @@ public partial class HistoryEpisode : INotifyPropertyChanged{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WasDownloaded))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WasDownloaded)));
} }
public void DownloadEpisode(){ public async Task DownloadEpisode(){
Crunchyroll.Instance.AddEpisodeToQue(EpisodeId, Crunchyroll.Instance.DefaultLocale, Crunchyroll.Instance.CrunOptions.DubLang); await Crunchyroll.Instance.AddEpisodeToQue(EpisodeId, Crunchyroll.Instance.DefaultLocale, Crunchyroll.Instance.CrunOptions.DubLang);
} }
} }

View File

@ -42,10 +42,18 @@ public partial class HistoryPageViewModel : ViewModelBase{
[RelayCommand] [RelayCommand]
public async void RefreshAll(){ public async void RefreshAll(){
foreach (var historySeries in Items){ for (int i = 0; i < Items.Count; i++) {
ShowLoading = true; ShowLoading = true;
await historySeries.FetchData(""); await Items[i].FetchData("");
historySeries.UpdateNewEpisodes(); Items[i].UpdateNewEpisodes();
}
ShowLoading = false;
}
[RelayCommand]
public async void AddMissingToQueue(){
for (int i = 0; i < Items.Count; i++) {
await Items[i].AddNewMissingToDownloads();
} }
ShowLoading = false; ShowLoading = false;
} }

View File

@ -21,13 +21,15 @@
<ColumnDefinition Width="Auto" /> <!-- Takes up most space for the title --> <ColumnDefinition Width="Auto" /> <!-- Takes up most space for the title -->
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Margin="10 10 0 0" HorizontalAlignment="Center" Command="{Binding PrevWeek}"> <Button Grid.Row="0" Grid.Column="0" Margin="10 10 0 0" HorizontalAlignment="Center"
Command="{Binding PrevWeek}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="ChevronLeft" FontSize="18" /> <controls:SymbolIcon Symbol="ChevronLeft" FontSize="18" />
</StackPanel> </StackPanel>
</Button> </Button>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 10 0 0"> <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center"
Margin="0 10 0 0">
<Button HorizontalAlignment="Center" Command="{Binding Refresh}"> <Button HorizontalAlignment="Center" Command="{Binding Refresh}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="Refresh" FontSize="18" /> <controls:SymbolIcon Symbol="Refresh" FontSize="18" />
@ -40,7 +42,8 @@
</StackPanel> </StackPanel>
<Button Grid.Row="0" Grid.Column="2" Margin="0 0 10 0" HorizontalAlignment="Center" Command="{Binding NextWeek}"> <Button Grid.Row="0" Grid.Column="2" Margin="0 0 10 0" HorizontalAlignment="Center"
Command="{Binding NextWeek}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="ChevronRight" FontSize="18" /> <controls:SymbolIcon Symbol="ChevronRight" FontSize="18" />
</StackPanel> </StackPanel>
@ -85,7 +88,7 @@
<ListBox Grid.Row="1" ItemsSource="{Binding CalendarEpisodes}"> <!-- Adjust MaxHeight as needed --> <ListBox Grid.Row="1" ItemsSource="{Binding CalendarEpisodes}"> <!-- Adjust MaxHeight as needed -->
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border Padding="10" Margin="5" Height="200"> <Border Padding="10" Margin="5">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBlock HorizontalAlignment="Center" <TextBlock HorizontalAlignment="Center"
Text="{Binding DateTime, StringFormat='hh:mm tt'}" Text="{Binding DateTime, StringFormat='hh:mm tt'}"
@ -93,20 +96,23 @@
<Grid HorizontalAlignment="Center"> <Grid HorizontalAlignment="Center">
<Image HorizontalAlignment="Center" Source="{Binding ImageBitmap}" /> <Image HorizontalAlignment="Center" Source="{Binding ImageBitmap}" />
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left"> <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock VerticalAlignment="Center" TextAlignment="Center" Margin="0 0 5 0" Width="30" Height="30" <TextBlock VerticalAlignment="Center" TextAlignment="Center"
Background="Black" Opacity="0.8" Text="{Binding EpisodeNumber}" Margin="0 0 5 0" Width="30" Height="30"
Padding="0,5,0,0"/> Background="Black" Opacity="0.8"
Text="{Binding EpisodeNumber}"
Padding="0,5,0,0" />
</StackPanel> </StackPanel>
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right" <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right"
IsVisible="{Binding IsPremiumOnly}" Margin="0,0,5,5"> IsVisible="{Binding IsPremiumOnly}" Margin="0,0,5,5">
<Canvas Width="28" Height="28"> <Canvas Width="28" Height="28">
<Ellipse Fill="#40FFFFFF" Width="28" Height="28"/> <Ellipse Fill="#40FFFFFF" Width="28" Height="28" />
<Viewbox Width="24" Height="24" Stretch="Uniform" Canvas.Left="2" Canvas.Top="2"> <Viewbox Width="24" Height="24" Stretch="Uniform"
Canvas.Left="2" Canvas.Top="2">
<Canvas Width="50" Height="50"> <!-- Ensure inner canvas is large enough to hold the path data --> <Canvas Width="50" Height="50"> <!-- Ensure inner canvas is large enough to hold the path data -->
<Path Fill="#f78c25" <Path Fill="#f78c25"
Stroke="#f78c25" Stroke="#f78c25"
StrokeThickness="1" StrokeThickness="1"
Data="M35.7,36.2H12.3c-0.7,0-1.4-0.5-1.6-1.2L6.1,18.6c-0.2-0.6,0-1.3,0.5-1.7c0.5-0.4,1.2-0.5,1.8-0.2l8.1,4.1 l6.2-8.3c0.3-0.4,0.8-0.7,1.3-0.7h0c0.5,0,1,0.2,1.3,0.7l6.2,8.3l8.2-4.1c0.6-0.3,1.3-0.2,1.8,0.2c0.5,0.4,0.7,1.1,0.5,1.7 L37.3,35C37.1,35.7,36.4,36.2,35.7,36.2z"/> Data="M35.7,36.2H12.3c-0.7,0-1.4-0.5-1.6-1.2L6.1,18.6c-0.2-0.6,0-1.3,0.5-1.7c0.5-0.4,1.2-0.5,1.8-0.2l8.1,4.1 l6.2-8.3c0.3-0.4,0.8-0.7,1.3-0.7h0c0.5,0,1,0.2,1.3,0.7l6.2,8.3l8.2-4.1c0.6-0.3,1.3-0.2,1.8,0.2c0.5,0.4,0.7,1.1,0.5,1.7 L37.3,35C37.1,35.7,36.4,36.2,35.7,36.2z" />
</Canvas> </Canvas>
</Viewbox> </Viewbox>
</Canvas> </Canvas>
@ -124,7 +130,8 @@
</TextBlock> </TextBlock>
<Button HorizontalAlignment="Center" Content="Download" <Button HorizontalAlignment="Center" Content="Download"
IsEnabled="{Binding HasPassed}" Command="{Binding AddEpisodeToQue}" IsEnabled="{Binding HasPassed}"
Command="{Binding AddEpisodeToQue}"
CommandParameter="{Binding EpisodeUrl}" /> CommandParameter="{Binding EpisodeUrl}" />
</StackPanel> </StackPanel>
</Border> </Border>

View File

@ -20,8 +20,11 @@
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Margin="20 0 0 0 ">
<Button Command="{Binding RefreshAll}" Margin="10">Refresh All</Button>
<Button Command="{Binding AddMissingToQueue}" Margin="10">Add To Queue</Button>
</StackPanel>
<Button Grid.Row="0" Grid.Column="0" Command="{Binding RefreshAll}" Margin="10">Refresh All</Button>
<Grid Grid.Row="1" Grid.Column="0"> <Grid Grid.Row="1" Grid.Column="0">
<!-- Spinner Style ProgressBar --> <!-- Spinner Style ProgressBar -->
<ProgressBar IsIndeterminate="True" <ProgressBar IsIndeterminate="True"
@ -32,7 +35,7 @@
</ProgressBar> </ProgressBar>
</Grid> </Grid>
<ListBox Grid.Row="1" ItemsSource="{Binding Items}" IsVisible="{Binding !ShowLoading}" SelectedItem="{Binding SelectedSeries}" Margin="5"> <ListBox Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Items}" IsVisible="{Binding !ShowLoading}" SelectedItem="{Binding SelectedSeries}" Margin="5">
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>

View File

@ -65,7 +65,7 @@
</ui:NavigationView.MenuItems> </ui:NavigationView.MenuItems>
<ui:NavigationView.FooterMenuItems> <ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem Classes="SampleAppNav" Content="Update Available" Tag="UpdateAvailable" <ui:NavigationViewItem Classes="SampleAppNav" Content="Update Available" Tag="UpdateAvailable"
IconSource="CloudDownload" Focusable="False" IsVisible="{Binding UpdateAvailable}" /> IconSource="CloudDownload" Focusable="False" IsEnabled="{Binding UpdateAvailable}" />
<ui:NavigationViewItem Classes="SampleAppNav" Content="Account" Tag="Account" <ui:NavigationViewItem Classes="SampleAppNav" Content="Account" Tag="Account"
IconSource="Contact" /> IconSource="Contact" />
<ui:NavigationViewItem Classes="SampleAppNav" Content="Settings" Tag="Settings" <ui:NavigationViewItem Classes="SampleAppNav" Content="Settings" Tag="Settings"