Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Oct 29, 2023
1 parent 00f19b6 commit 8352755
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 67 deletions.
6 changes: 5 additions & 1 deletion AniStream/Models/Range.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using Juro.Core.Models.Anime;

namespace AniStream.Models;

public class Range
public partial class Range : ObservableObject
{
public string Name { get; set; } = default!;

public List<Episode> Episodes { get; set; } = new();

[ObservableProperty]
private bool _isSelected;

public Range(IEnumerable<Episode> episodes, int startIndex, int endIndex)
{
Episodes.AddRange(episodes);
Expand Down
30 changes: 14 additions & 16 deletions AniStream/ViewModels/EpisodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,20 @@ public async Task LoadEpisodes(IAnimeInfo anime)
{
var startIndex = 1;
var endIndex = 0;

for (var i = 0; i < EpisodeChunks.Count; i++)
{
var chunk = EpisodeChunks[i].ToList();
if (_settingsService.EpisodesDescending)
{
chunk.Reverse();
EpisodeChunks[i] = EpisodeChunks[i].Reverse().ToArray();
}

endIndex = startIndex + chunk.Count - 1;
ranges.Add(new Range(chunk, startIndex, endIndex));
startIndex += chunk.Count;
endIndex = startIndex + EpisodeChunks[i].Length - 1;
ranges.Add(new Range(EpisodeChunks[i], startIndex, endIndex));
startIndex += EpisodeChunks[i].Length;
}

ranges[0].IsSelected = true;
}
else
{
Expand All @@ -147,27 +149,23 @@ public async Task LoadEpisodes(IAnimeInfo anime)

result.ForEach(ep => ep.Image = anime.Image);

foreach (var episode in result)
{
var episodeKey = $"{Entity.Id}-{episode.Number}";
_playerSettings.WatchedEpisodes.TryGetValue(episodeKey, out var watchedEpisode);
if (watchedEpisode is not null)
{
episode.Progress = watchedEpisode.WatchedPercentage;
}
}

RefreshEpisodesProgress();

Entities.Push(EpisodeChunks[0]);

Ranges.Push(ranges);
OnPropertyChanged(nameof(Ranges));
}

[RelayCommand]
private void RangeSelected(Range range)
{
for (var i = 0; i < Ranges.Count; i++)
{
Ranges[i].IsSelected = false;
}

range.IsSelected = true;

Entities.ReplaceRange(range.Episodes);
}

Expand Down
34 changes: 22 additions & 12 deletions AniStream/ViewModels/Videos/VideoPlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,34 @@ public VideoPlayerViewModel(IAnimeInfo anime, Episode episode, VideoSource? vide
public VideoPlayerViewModel(IAnimeInfo anime, Episode episode, Media media)
: this(anime, episode, null, media) { }

[RelayCommand]
public void OnLoaded(IMediaElement mediaElement)
{
Shell.Current.Navigating += Current_Navigating;

MediaElement = mediaElement;
Controller = new(this, _anime, _episode, default!, _media);
Controller.OnLoaded(mediaElement);
}

private void Current_Navigating(object? sender, ShellNavigatingEventArgs e)
{
_cancellationTokenSource.Cancel();
UpdateProgress();
}

[RelayCommand]
private void OnUnloaded()
{
Shell.Current.Navigating -= Current_Navigating;

Controller.Dispose();

ApplicationEx.SetOrientation(_initialOrientation);
}

[RelayCommand]
private async Task OnStateChanged(MediaElementState state)
private void OnStateChanged(MediaElementState state)
{
switch (state)
{
Expand All @@ -97,10 +115,10 @@ private async Task OnStateChanged(MediaElementState state)
CanSaveProgress = true;
break;
case MediaElementState.Paused:
await UpdateProgress();
UpdateProgress();
break;
case MediaElementState.Stopped:
await UpdateProgress();
UpdateProgress();
break;
case MediaElementState.Failed:
CanSaveProgress = false;
Expand All @@ -110,14 +128,6 @@ private async Task OnStateChanged(MediaElementState state)
}
}

[RelayCommand]
public void OnLoaded(IMediaElement mediaElement)
{
MediaElement = mediaElement;
Controller = new(this, _anime, _episode, default!, _media);
Controller.OnLoaded(mediaElement);
}

public async Task ShowSpeedSelector()
{
var speeds = _playerSettings.GetSpeeds();
Expand Down Expand Up @@ -218,7 +228,7 @@ async Task ShowSheet()
await sheet.ShowAsync();
}

public async Task UpdateProgress()
public void UpdateProgress()
{
if (!CanSaveProgress)
return;
Expand Down
2 changes: 1 addition & 1 deletion AniStream/Views/BottomSheets/EpisodeSelectionSheet.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<LinearItemsLayout ItemSpacing="8" Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="{x:Type models:VideoServer}">
<DataTemplate x:DataType="{x:Null}">
<Label
Margin="25,10,0,0"
FontAttributes="Bold"
Expand Down
10 changes: 9 additions & 1 deletion AniStream/Views/Templates/EpisodeRangeTemplateView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
HorizontalOptions="FillAndExpand"
StrokeThickness="0"
VerticalOptions="FillAndExpand">
<Border.Triggers>
<DataTrigger
Binding="{Binding IsSelected}"
TargetType="Border"
Value="True">
<Setter Property="BackgroundColor" Value="#4287f5" />
</DataTrigger>
</Border.Triggers>
<Border.StrokeShape>
<RoundRectangle CornerRadius="22" />
</Border.StrokeShape>
<Label
Grid.Row="1"
Padding="20,13"
Padding="18,10"
FontAttributes="Bold"
FontFamily="SoraBold"
FontSize="15"
Expand Down
77 changes: 41 additions & 36 deletions AniStream/Views/Templates/FullEpisodeTemplateView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
xmlns:local="clr-namespace:AniStream"
xmlns:models="clr-namespace:Juro.Core.Models.Anime;assembly=Juro.Core"
x:Name="this"
Margin="3,5"
Margin="20,5"
Padding="0"
x:DataType="models:Episode"
BackgroundColor="Transparent"
HeightRequest="100">
HeightRequest="125">
<Border.Resources>
<ResourceDictionary>
<converters:WatchedEpisodeProgressConverter x:Key="WatchedEpisodeProgressConverter" />
Expand All @@ -22,7 +22,15 @@
<Border.StrokeShape>
<RoundRectangle CornerRadius="10" />
</Border.StrokeShape>
<Grid BackgroundColor="Transparent" ColumnDefinitions="auto,*">
<Grid BackgroundColor="{StaticResource Gray900}" ColumnDefinitions="auto,*">
<Grid.Behaviors>
<berry:TouchBehavior
Command="{Binding Parent.BindingContext.ItemClickCommand, Source={x:Reference this}}"
CommandParameter="{Binding BindingContext, Source={x:Reference this}}"
LongPressCommand="{Binding Parent.BindingContext.ShowSheetCommand, Source={x:Reference this}}"
LongPressCommandParameter="{Binding BindingContext, Source={x:Reference this}}"
NativeAnimation="True" />
</Grid.Behaviors>
<Border StrokeThickness="0">
<Border.StrokeShape>
<RoundRectangle CornerRadius="10" />
Expand All @@ -32,16 +40,7 @@
BackgroundColor="Transparent"
Opacity="0.8"
Source="{Binding Image}"
WidthRequest="190">
<Image.Behaviors>
<berry:TouchBehavior NativeAnimation="True" />
<berry:TouchBehavior
Command="{Binding Parent.BindingContext.ItemClickCommand, Source={x:Reference this}}"
CommandParameter="{Binding BindingContext, Source={x:Reference this}}"
LongPressCommand="{Binding Parent.BindingContext.ShowSheetCommand, Source={x:Reference this}}"
LongPressCommandParameter="{Binding BindingContext, Source={x:Reference this}}" />
</Image.Behaviors>
</Image>
WidthRequest="200" />
</Border>

<!-- Display Progress -->
Expand All @@ -59,39 +58,45 @@
VerticalOptions="End" />
</Grid>

<Label
Padding="5"
FontAttributes="Bold"
FontSize="15"
HorizontalTextAlignment="Start"
LineBreakMode="TailTruncation"
Opacity="0.9"
Text="{Binding Name}"
TextColor="#E9FFFFFF"
VerticalTextAlignment="Start" />
<Label
Padding="8,5"
FontAttributes="Bold"
FontFamily="SoraBold"
FontSize="25"
HorizontalTextAlignment="End"
LineBreakMode="TailTruncation"
Opacity="0.7"
Text="{Binding Number}"
TextColor="#E9FFFFFF"
VerticalTextAlignment="End" />
<Border
Grid.Column="0"
Margin="-10,-3,0,0"
Padding="4"
HorizontalOptions="Start"
StrokeThickness="0"
VerticalOptions="Start">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Offset="0.4" Color="#AE000000" />
<GradientStop Offset="1" Color="#31000000" />
</LinearGradientBrush>
</Border.Background>
<Border.StrokeShape>
<RoundRectangle CornerRadius="20,0,20,20" />
</Border.StrokeShape>
<Label
Padding="15,8,10,6"
FontAttributes="Bold"
FontSize="20"
HorizontalTextAlignment="Start"
LineBreakMode="TailTruncation"
Opacity="0.9"
Text="{Binding Number}"
TextColor="#E9FFFFFF"
VerticalTextAlignment="Start" />
</Border>

<Label
Grid.Column="1"
Padding="8,5"
FontAttributes="Bold"
FontFamily="SoraBold"
FontSize="25"
FontSize="20"
HorizontalOptions="Center"
HorizontalTextAlignment="End"
LineBreakMode="TailTruncation"
Opacity="0.7"
Text="{Binding Number}"
Text="{Binding Name}"
TextColor="#E9FFFFFF"
VerticalOptions="Center"
VerticalTextAlignment="End" />
Expand Down

0 comments on commit 8352755

Please sign in to comment.