Skip to content

Commit

Permalink
choose different torrent indexers in flyout
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed May 7, 2023
1 parent 435ab5d commit e272471
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
15 changes: 9 additions & 6 deletions Totoro.Core/ViewModels/TorrentingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TorrentModel, string> _torrentsCache = new(x => x.Link);
private readonly SourceCache<Transfer, string> _transfersCache = new(x => x.Name);
private readonly ReadOnlyObservableCollection<TorrentModel> _torrents;
private readonly ReadOnlyObservableCollection<Transfer> _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
{
Expand Down Expand Up @@ -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<TorrentModel> Torrents => _torrents;
public ReadOnlyObservableCollection<Transfer> Transfers => _transfers;
Expand Down Expand Up @@ -184,6 +184,9 @@ public override async Task OnNavigatedTo(IReadOnlyDictionary<string, object> par
IsLoading = true;
MonitorTransfers();

var indexer = (TorrentProviderType)parameters.GetValueOrDefault("Indexer", _settings.TorrentProviderType);
_catalog = _indexerFactory.GetCatalog(indexer);
ProviderType = indexer;

if (parameters.ContainsKey("Anime"))
{
Expand Down
5 changes: 4 additions & 1 deletion Totoro.WinUI/Helpers/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TorrentProviderType>().Cast<TorrentProviderType>())
{
torrentFlyoutItem.Items.Add(new MenuFlyoutItem
Expand Down
1 change: 0 additions & 1 deletion Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 13 additions & 8 deletions Totoro.WinUI/Views/TorrentingSections/SearchSection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
});
}

Expand Down

0 comments on commit e272471

Please sign in to comment.