public ProviderSetViewModel(MangaInfo mangaInfo, IMangaIndex mangaIndex, SubscriptionViewModel.Factory factory) { _mangaIndex = mangaIndex; SubscriptionFactory = factory; Name = mangaInfo.Name; Providers = mangaInfo.Instances.Select(t => new ProviderData { Provider = t.provider, Url = t.url }).ToBindableCollection(); MetaData = mangaInfo.MetaData; var providerData = this .OnPropertyChanges(s => s.SelectedProvider).Do(_ => IsLoading = true) .SelectTask(a => GetProviderData(a.Provider, a.Url)).Do(_ => IsLoading = false) .ObserveOnDispatcher(); SelectedInstance = providerData .Select(vt => CreateInstanceViewModel(vt.coverUrl, new ChapterInstanceViewModel(vt.chapters))) .ToReactiveProperty(); Test = providerData .Select(vt => CreateInstanceViewModel(vt.coverUrl, SubscriptionFactory((Name, SelectedProvider), vt.chapters))) .ToReactiveProperty(); SelectedInstance .Subscribe(x => x?.ChapterInstanceViewModel.SelectedRows.Clear()); }
public SearchViewModel(IMangaIndex mangaIndex, ProviderSetViewModel.Factory factory) { MangaIndex = mangaIndex; Factory = factory; Genres = new GenresViewModel(); Instances = this.OnPropertyChanges(s => s.SearchString) .Throttle(TimeSpan.FromMilliseconds(500), DispatcherScheduler.Current) .SelectTask(FindMangas) .Merge(Genres.OnPropertyChanges(t => t.SelectedGenres).SelectTask(SelectedGenreChanged)) .Merge(this.OnPropertyChanges(t => t.ArtistSearchString) .Throttle(TimeSpan.FromMilliseconds(500), DispatcherScheduler.Current) .SelectTask(FindMangasByArtist)) .ToReactiveCollection(); }
public static async Task <IEnumerable <ChapterInstance> > GetChapters(IMangaIndex index, string provider, string url) { try { var chapters = await index.Chapters(provider, url).ToListAsync(); var maxDigits = chapters.Count == 0 ? 1 : (int)Floor(Log10(Abs(chapters.Count))) + 1; return(chapters .Select(c => new ChapterInstance { MaxDigits = maxDigits, Number = c.Number, Parser = c, Index = index })); } catch (Exception) { return(new BindableCollection <ChapterInstance>()); } }