-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add episodes section in about anime page
- Loading branch information
1 parent
0d55b9c
commit a9b2ff9
Showing
13 changed files
with
264 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Totoro.Core.Services.Anizip; | ||
|
||
namespace Totoro.Core.Contracts; | ||
|
||
|
||
public interface IEpisodesInfoProvider | ||
{ | ||
IAsyncEnumerable<EpisodeInfo> GetEpisodeInfos(long id, string serviceType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Text.Json.Nodes; | ||
using Flurl; | ||
using Flurl.Http; | ||
|
||
namespace Totoro.Core.Services.Anizip; | ||
|
||
public class AnizipEpisodeInfoProvider(TimeProvider timeProvider) : IEpisodesInfoProvider | ||
{ | ||
private readonly string _baseUrl = @"https://api.ani.zip/mappings"; | ||
private readonly TimeProvider _timeProvider; | ||
private readonly DateTimeOffset _today = timeProvider.GetUtcNow(); | ||
|
||
public async IAsyncEnumerable<EpisodeInfo> GetEpisodeInfos(long id, string serviceType) | ||
{ | ||
var response = await _baseUrl.SetQueryParam(serviceType, id).GetStringAsync(); | ||
var jObject = (JsonObject)JsonNode.Parse(response); | ||
var episodesObj = jObject["episodes"].AsObject(); | ||
|
||
foreach (var property in episodesObj) | ||
{ | ||
var model = property.Value.Deserialize<EpisodeInfo>(); | ||
|
||
if(model.AirDateUtc is null || model.AirDateUtc > _today) | ||
{ | ||
continue; | ||
} | ||
|
||
yield return model; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
| ||
using System.Text.Json.Serialization; | ||
|
||
namespace Totoro.Core.Services.Anizip; | ||
|
||
public class EpisodeInfo | ||
{ | ||
[JsonPropertyName("seasonNumber")] | ||
public int SeasonNumber { get; set; } | ||
|
||
[JsonPropertyName("episodeNumber")] | ||
public int EpisodeNumber { get; set; } | ||
|
||
[JsonPropertyName("absoluteEpisodeNumber")] | ||
public int AbsoluteEpisodeNumber { get; set; } | ||
|
||
[JsonPropertyName("title")] | ||
public Titles Titles { get; set; } | ||
|
||
[JsonPropertyName("overview")] | ||
public string Overview { get; set; } | ||
|
||
[JsonPropertyName("image")] | ||
public string Image { get; set; } | ||
|
||
[JsonPropertyName("airDate")] | ||
public string AirDate { get; set; } | ||
|
||
[JsonPropertyName("runtime")] | ||
public int Runtime { get; set; } | ||
|
||
[JsonPropertyName("airDateUtc")] | ||
public DateTime? AirDateUtc { get; set; } | ||
} | ||
|
||
public class Titles | ||
{ | ||
[JsonPropertyName("ja")] | ||
public string Japanese { get; set; } | ||
|
||
[JsonPropertyName("en")] | ||
public string English { get; set; } | ||
|
||
[JsonPropertyName("x-jat")] | ||
public string Romaji { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Totoro.Core.Services.Anizip; | ||
|
||
namespace Totoro.Core.ViewModels.About; | ||
|
||
public class AnimeEpisodesViewModel : BaseAboutAnimeViewModel | ||
{ | ||
public AnimeEpisodesViewModel(INavigationService navigationService) | ||
{ | ||
Watch = ReactiveCommand.Create<EpisodeInfo>(info => | ||
{ | ||
navigationService.NavigateTo<WatchViewModel>(parameter: new Dictionary<string, object> | ||
{ | ||
{ WatchViewModelParamters.Anime, Anime }, | ||
{ WatchViewModelParamters.EpisodeNumber, info.EpisodeNumber } | ||
}); | ||
}); | ||
} | ||
|
||
[Reactive] public List<EpisodeInfo> Episodes { get; set; } | ||
public ICommand Watch { get; } | ||
|
||
public override Task OnNavigatedTo(IReadOnlyDictionary<string, object> parameters) | ||
{ | ||
Episodes = (List<EpisodeInfo>)parameters.GetValueOrDefault(nameof(Episodes), new List<EpisodeInfo>()); | ||
|
||
return base.OnNavigatedTo(parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:EpisodesSectionBase | ||
x:Class="Totoro.WinUI.Views.AboutSections.EpisodesSection" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:cm="using:Totoro.Core.Services.Anizip" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:Totoro.WinUI.Views.AboutSections" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:root="using:Totoro.WinUI" | ||
xmlns:uc="using:Totoro.WinUI.UserControls" | ||
xmlns:ctk="using:CommunityToolkit.WinUI.Controls" | ||
mc:Ignorable="d"> | ||
|
||
<ItemsView | ||
x:Name="EpisodesView" | ||
Margin="{StaticResource LargeTopMargin}" | ||
IsItemInvokedEnabled="True" | ||
ItemsSource="{x:Bind ViewModel.Episodes, Mode=OneWay}" | ||
ItemInvoked="EpisodesView_ItemInvoked" | ||
SelectionMode="None"> | ||
<ItemsView.ItemTemplate> | ||
<DataTemplate x:DataType="cm:EpisodeInfo"> | ||
<ItemContainer Background="{ThemeResource CardBackgroundFillColorDefault}"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="2*"/> | ||
</Grid.ColumnDefinitions> | ||
|
||
<ctk:ConstrainedBox AspectRatio="16:9"> | ||
<uc:ImageEx Source="{x:Bind Image}" | ||
Stretch="UniformToFill" | ||
Width="360" | ||
PlaceholderSource="/Assets/placeholder.jpg" | ||
PlaceholderStretch="Fill"/> | ||
</ctk:ConstrainedBox> | ||
|
||
<StackPanel Grid.Column="1" Padding="10" Spacing="5"> | ||
<TextBlock Style="{ThemeResource SubtitleTextBlockStyle}" | ||
Margin="0 0 0 8"> | ||
<Run Text="Episode" Foreground="{ThemeResource TextFillColorSecondaryBrush}"/> | ||
<Run Text="{x:Bind EpisodeNumber}" Foreground="{ThemeResource TextFillColorSecondaryBrush}"/> | ||
<Run Text=":" Foreground="{ThemeResource TextFillColorSecondaryBrush}"/> | ||
<Run Text="{x:Bind Titles.English}"/> | ||
</TextBlock> | ||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0 0 0 8"> | ||
<SymbolIcon Symbol="CalendarDay"/> | ||
<TextBlock Text="{x:Bind AirDate}" Margin="0 0 16 0"/> | ||
<SymbolIcon Symbol="Clock"/> | ||
<TextBlock> | ||
<Run Text="{x:Bind Runtime}"/> | ||
<Run Text="Min"/> | ||
</TextBlock> | ||
</StackPanel> | ||
<TextBlock Text="{x:Bind Overview}" Style="{ThemeResource BodyTextBlockStyle}" TextWrapping="WrapWholeWords"/> | ||
</StackPanel> | ||
</Grid> | ||
</ItemContainer> | ||
</DataTemplate> | ||
</ItemsView.ItemTemplate> | ||
<ItemsView.Layout> | ||
<StackLayout Spacing="10"/> | ||
</ItemsView.Layout> | ||
</ItemsView> | ||
|
||
</local:EpisodesSectionBase> |
Oops, something went wrong.