public RenbanVm(RenbanDownLoader renbanDownLoader) { _renbanDownLoader = renbanDownLoader; Address = new ReactiveProperty <string>(string.Empty); UrlsPreview = new ReactivePropertySlim <string>(string.Empty).AddTo(Disposables); TextInput = new ReactiveProperty <string>(string.Empty).AddTo(Disposables); // ダウンロードコマンド { DownLoadCommand = UrlsPreview .Select(x => ToUrls()) .Select(urls => urls.Any() && urls.All(url => Uri.TryCreate(url, UriKind.Absolute, out _))) .ToAsyncReactiveCommand(); DownLoadCommand.Subscribe(async() => { DownloadLogInfo.Value = string.Empty; await _renbanDownLoader.DownLoad(ToUrls()); }) .AddTo(Disposables); } // Vmの入力を RenbanDownloaderで処理し、データを加工する Address.Throttle(TimeSpan.FromMilliseconds(100), UIDispatcherScheduler.Default) .Subscribe(x => { _renbanDownLoader.SetAddressWithAutoUpdateProperties(x); Address.Value = renbanDownLoader.Address.Value; }) .AddTo(Disposables); // 各パラメータの更新に併せてダウンロード候補一覧表示を更新する Observable.Merge(Address.ToUnit(), TextInput.ToUnit(), Start.ToUnit(), End.ToUnit(), FillZero.ToUnit()) .Throttle(TimeSpan.FromMilliseconds(250), UIDispatcherScheduler.Default) .Select(_ => CreateDownloadCandidate()) .Subscribe(x => UrlsPreview.Value = x).AddTo(Disposables); UrlsPreview.Throttle(TimeSpan.FromMilliseconds(500), UIDispatcherScheduler.Default) .Subscribe(async _ => await CreatePreviewThumbnailsAsync()).AddTo(Disposables); }
public MainWindowVm() { FilterText = new ReactivePropertySlim <string>(string.Empty).AddTo(CompositeDisposable); ShowMegaEvolution = new ReactivePropertySlim <bool>().AddTo(CompositeDisposable); ShowBanLegend = new ReactivePropertySlim <bool>().AddTo(CompositeDisposable); ShowDetailCommand = new DelegateCommand <PokemonListItemVm>(x => Messenger.Raise(new TransitionMessage(new PokemonDetailVm(x.Model), "ShowDetail"))); var abilities = DataLoader.LoadAbilities(); var types = DataLoader.LoadTypes(); var persons = DataLoader.LoadPersonarities(); var pokemons = DataLoader.LoadPokemons(); var moves = DataLoader.LoadMoves(); var forms = DataLoader.LoadForms(); var db = DataBase.Build(abilities, types, persons, pokemons, moves, forms); DataBaseService.Initialize(db); ItemsSource = db.Pokemons .Select(x => new PokemonListItemVm(x)) .Concat(db.Forms.Select(x => new PokemonListItemVm(x))) .OrderBy(x => x.ID) .ToList(); IdFilter = new List <FilterVm>() { new FilterVm("全国", (x) => true), new FilterVm("ガラル", (x) => x.GalarID != null), }; IdFilter .Select(x => x.ObserveProperty(filterVm => filterVm.IsEnabled)) .Merge() .StartWith() .Where(x => IdFilter.Any(filterVm => filterVm.IsEnabled)) .Select(_ => IdFilter.FirstOrDefault(x => x.IsEnabled)) .Throttle(TimeSpan.FromMilliseconds(50)) .ObserveOnUIDispatcher() .Do(x => { switch (x.Label) { case "全国": foreach (var item in ItemsSource) { item.ID = item.Model.Id; } break; case "ガラル": foreach (var item in ItemsSource) { item.ID = item.Model.GalarID ?? -1; } break; } }) .Do(x => ApplyFilters()) .Subscribe() .AddTo(CompositeDisposable); FilterText .Throttle(TimeSpan.FromMilliseconds(50)) .ObserveOnUIDispatcher() .Subscribe(_ => Messenger.Raise(new InteractionMessage("RaiseFilter"))) .AddTo(CompositeDisposable); ShowMegaEvolution .Merge(ShowBanLegend) .Throttle(TimeSpan.FromMilliseconds(5)) .ObserveOnDispatcher() .Do(_ => ApplyFilters()) .Subscribe(); }