diff --git a/Totoro.Core/ViewModels/AboutAnimeViewModel.cs b/Totoro.Core/ViewModels/AboutAnimeViewModel.cs index 0355a74e..34eb188f 100644 --- a/Totoro.Core/ViewModels/AboutAnimeViewModel.cs +++ b/Totoro.Core/ViewModels/AboutAnimeViewModel.cs @@ -2,9 +2,13 @@ public class AboutAnimeViewModel : NavigatableViewModel { - private readonly ObservableAsPropertyHelper _anime; - private readonly ObservableAsPropertyHelper _hasTracking; - private readonly ObservableAsPropertyHelper> _sounds; + public ObservableCollection Pages { get; } = new() + { + new PivotItemModel { Header = "Previews" }, + new PivotItemModel { Header = "Related" }, + new PivotItemModel { Header = "Recommended" }, + new PivotItemModel { Header = "OST"} + }; public AboutAnimeViewModel(IAnimeServiceContext animeService, INavigationService navigationService, @@ -23,23 +27,61 @@ public AboutAnimeViewModel(IAnimeServiceContext animeService, this.ObservableForProperty(x => x.Id, x => x) .Where(id => id > 0) .SelectMany(animeService.GetInformation) - .ToProperty(this, nameof(Anime), out _anime, scheduler: RxApp.MainThreadScheduler); + .ToPropertyEx(this, x => x.Anime, scheduler: RxApp.MainThreadScheduler); this.WhenAnyValue(x => x.Anime) .WhereNotNull() .Select(anime => anime.Tracking is { }) - .ToProperty(this, nameof(HasTracking), out _hasTracking, scheduler: RxApp.MainThreadScheduler); + .ToPropertyEx(this, x => x.HasTracking, scheduler: RxApp.MainThreadScheduler); this.ObservableForProperty(x => x.Id, x => x) .Where(id => id > 0) .Select(animeSoundService.GetThemes) - .ToProperty(this, nameof(Sounds), out _sounds, scheduler: RxApp.MainThreadScheduler); + .ToPropertyEx(this, x => x.Sounds, scheduler: RxApp.MainThreadScheduler); + + this.WhenAnyValue(x => x.Sounds) + .WhereNotNull() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(sounds => + { + if (sounds is { Count: > 0 }) + { + return; + } + + Pages.Remove(Pages.First(x => x.Header == "OST")); + + }); + + this.WhenAnyValue(x => x.Anime) + .WhereNotNull() + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(anime => + { + if(anime.Videos is not { Count : >0}) + { + Pages.Remove(Pages.First(x => x.Header == "Previews")); + } + if(anime.Related is not { Length: > 0 }) + { + Pages.Remove(Pages.First(x => x.Header == "Related")); + } + if (anime.Recommended is not { Length: > 0 }) + { + Pages.Remove(Pages.First(x => x.Header == "Recommended")); + } + }); + + this.WhenAnyValue(x => x.SelectedPage) + .Where(x => x is null && Pages.Any(x => x.Visible)) + .Subscribe(_ => SelectedPage = Pages.First(x => x.Visible)); } [Reactive] public long Id { get; set; } - public AnimeModel Anime => _anime.Value; - public bool HasTracking => _hasTracking.Value; - public IList Sounds => _sounds.Value; + [Reactive] public PivotItemModel SelectedPage { get; set; } + [ObservableAsProperty] public AnimeModel Anime { get; } + [ObservableAsProperty] public bool HasTracking { get; } + [ObservableAsProperty] public IList Sounds { get; } public ICommand WatchEpidoes { get; } public ICommand UpdateStatus { get; } public ICommand PlaySound { get; } @@ -52,3 +94,10 @@ public override Task OnNavigatedTo(IReadOnlyDictionary parameter } } + +public class PivotItemModel : ReactiveObject +{ + public string Header { get; set; } + [Reactive] public bool Visible { get; set; } = true; +} + diff --git a/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs b/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs index b88691a2..0bd01dab 100644 --- a/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs +++ b/Totoro.WinUI/Media/Vlc/LibVLCMediaPlayerWrapper.cs @@ -32,7 +32,7 @@ internal class LibVLCMediaPlayerWrapper : IMediaPlayer public void Dispose() { - _mp?.Dispose(); + _mp?.Pause(); } public void Pause() diff --git a/Totoro.WinUI/Views/AboutAnimePage.xaml b/Totoro.WinUI/Views/AboutAnimePage.xaml index f5f6c743..1203b8b0 100644 --- a/Totoro.WinUI/Views/AboutAnimePage.xaml +++ b/Totoro.WinUI/Views/AboutAnimePage.xaml @@ -6,6 +6,7 @@ xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:help="using:Totoro.WinUI.Helpers" + xmlns:labs="using:CommunityToolkit.Labs.WinUI" xmlns:local="using:Totoro.WinUI.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:media="using:CommunityToolkit.WinUI.UI.Media" @@ -13,9 +14,18 @@ xmlns:root="using:Totoro.WinUI" xmlns:ui="using:CommunityToolkit.WinUI.UI" xmlns:usercontrols="using:Totoro.WinUI.UserControls" + xmlns:vm="using:Totoro.Core.ViewModels" Name="Page" mc:Ignorable="d"> + + + + + + + + @@ -196,9 +206,19 @@ - - - + + + + + + + - - + + - - + + - - + + @@ -276,8 +296,8 @@ - - + + diff --git a/Totoro.WinUI/Views/AboutAnimePage.xaml.cs b/Totoro.WinUI/Views/AboutAnimePage.xaml.cs index 3a90769e..c94c24f5 100644 --- a/Totoro.WinUI/Views/AboutAnimePage.xaml.cs +++ b/Totoro.WinUI/Views/AboutAnimePage.xaml.cs @@ -30,4 +30,4 @@ public AboutAnimePage() .DisposeWith(d); }); } -} +} \ No newline at end of file