diff --git a/Totoro.Core/ViewModels/TorrentingViewModel.cs b/Totoro.Core/ViewModels/TorrentingViewModel.cs index cd1c1492..8f52d044 100644 --- a/Totoro.Core/ViewModels/TorrentingViewModel.cs +++ b/Totoro.Core/ViewModels/TorrentingViewModel.cs @@ -14,30 +14,30 @@ public enum SortMode public class TorrentingViewModel : NavigatableViewModel { private readonly IDebridServiceContext _debridServiceContext; - private readonly ITorrentCatalog _catalog; + private readonly ITorrentCatalogFactory _indexerFactory; private readonly IAnimeIdService _animeIdService; private readonly ISettings _settings; private readonly SourceCache _torrentsCache = new(x => x.Link); private readonly SourceCache _transfersCache = new(x => x.Name); private readonly ReadOnlyObservableCollection _torrents; private readonly ReadOnlyObservableCollection _transfers; + private ITorrentCatalog _catalog; private IDisposable _transfersSubscription; private bool _isSubscriptionDisposed; public TorrentingViewModel(IDebridServiceContext debridServiceContext, - ITorrentCatalogFactory catalogFactory, + ITorrentCatalogFactory indexerFactory, IAnimeIdService animeIdService, ISettings settings, ITorrentEngine torrentEngine) { _debridServiceContext = debridServiceContext; - _catalog = catalogFactory.GetCatalog(settings.TorrentProviderType); + _indexerFactory = indexerFactory; _animeIdService = animeIdService; _settings = settings; - IsDebridAuthenticated = _debridServiceContext.IsAuthenticated; - ProviderType = settings.TorrentProviderType; + var sort = this.WhenAnyValue(x => x.SortMode) .Select(sort => sort switch { @@ -111,7 +111,7 @@ public TorrentingViewModel(IDebridServiceContext debridServiceContext, [Reactive] public PivotItemModel SelectedSection { get; set; } public bool IsDebridAuthenticated { get; } - public TorrentProviderType ProviderType { get; } + [Reactive] public TorrentProviderType? ProviderType { get; private set; } public TorrentModel PastedTorrent { get; } = new(); public ReadOnlyObservableCollection Torrents => _torrents; public ReadOnlyObservableCollection Transfers => _transfers; @@ -184,6 +184,9 @@ public override async Task OnNavigatedTo(IReadOnlyDictionary par IsLoading = true; MonitorTransfers(); + var indexer = (TorrentProviderType)parameters.GetValueOrDefault("Indexer", _settings.TorrentProviderType); + _catalog = _indexerFactory.GetCatalog(indexer); + ProviderType = indexer; if (parameters.ContainsKey("Anime")) { diff --git a/Totoro.WinUI/Helpers/Converters.cs b/Totoro.WinUI/Helpers/Converters.cs index 4160c066..b2531b49 100644 --- a/Totoro.WinUI/Helpers/Converters.cs +++ b/Totoro.WinUI/Helpers/Converters.cs @@ -102,14 +102,17 @@ public static MenuFlyout AnimeToFlyout(AnimeModel anime) CommandParameter = (anime, item.Name) }); } + scrapersFlyoutItem.Tapped += (_, _) => App.Commands.Watch.Execute(anime); flyout.Items.Add(scrapersFlyoutItem); var torrentFlyoutItem = new MenuFlyoutSubItem { Text = @"Search Torrents", - Icon = new SymbolIcon { Symbol = Symbol.Globe } + Icon = new SymbolIcon { Symbol = Symbol.Globe }, }; + torrentFlyoutItem.Tapped += (_, _) => App.Commands.SearchTorrent.Execute(anime); + foreach (var item in Enum.GetValues().Cast()) { torrentFlyoutItem.Items.Add(new MenuFlyoutItem diff --git a/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml b/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml index 91fce5b7..48f7a3ae 100644 --- a/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml +++ b/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:labs="using:CommunityToolkit.Labs.WinUI" xmlns:local="using:Totoro.WinUI.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:root="using:Totoro.WinUI" diff --git a/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml.cs b/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml.cs index 6c2dd04c..88856240 100644 --- a/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml.cs +++ b/Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml.cs @@ -35,19 +35,24 @@ public SearchSection() SearchBox .Events() .QuerySubmitted - .Select(_ => System.Reactive.Unit.Default) + .Select(_ => Unit.Default) .InvokeCommand(ViewModel.Search) .DisposeWith(d); - switch (ViewModel.ProviderType) - { - case TorrentProviderType.Nya: - foreach (var item in DataGrid.Columns) + this.WhenAnyValue(x => x.ViewModel.ProviderType) + .WhereNotNull() + .Subscribe(type => + { + switch (type) { - item.Visibility = Visibility.Visible; + case TorrentProviderType.Nya: + foreach (var item in DataGrid.Columns) + { + item.Visibility = Visibility.Visible; + } + break; } - break; - } + }); }); }