public TrimmerViewModel() { _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) }; _timer.Tick += (Sender, Args) => { if (IsDragging) { return; } RaisePropertyChanged(nameof(PlaybackPosition)); if (IsPlaying && _player.Position > To || _player.Position < From) { Stop(); } }; OpenCommand = _isTrimming .Select(M => !M) .ToReactiveCommand() .WithSubscribe(Open); PlayCommand = new[] { _isOpened, _isTrimming .Select(M => !M) } .CombineLatestValuesAreAllTrue() .ToReactiveCommand() .WithSubscribe(Play); TrimCommand = new[] { _isOpened, _isTrimming .Select(M => !M) } .CombineLatestValuesAreAllTrue() .ToReactiveCommand() .WithSubscribe(Trim); }
public ShopUnitModel(int initialId, ICashModel cashModel, IBenchPreparationUnitPool benchPreparationUnitPool, IPreparationUnitFactory preparationUnitFactory, IShopConfig shopConfig, IDisposer disposer) { _id = new ReactiveProperty <int>(initialId); _hasBeenBought = new ReactiveProperty <bool>(false); Cost = _id.Select(shopConfig.GetCost) .ToReadOnlyReactiveProperty() .AddToDisposer(disposer); _cashModel = cashModel; _preparationUnitFactory = preparationUnitFactory; CanBeBought = benchPreparationUnitPool.IsBenchFull .CombineLatest(cashModel.CurrentCash, Cost, _hasBeenBought, (benchFull, cash, cost, purchased) => !benchFull && cash >= cost && !purchased) .ToReadOnlyReactiveProperty() .AddToDisposer(disposer); }
public static IDisposable Bind <T1, T2>(Func <T1> propertyAGetter, Action <T1> propertyASetter, IReactiveProperty <T2> propertyB, IConverter <T1, T2> converter, BindingTypes bindingTypes = BindingTypes.Default, params IFilter <T1>[] filters) { var propertyBBinding = propertyB .Select(converter.From) .ApplyInputFilters(filters) .DistinctUntilChanged() .Subscribe(propertyASetter); if (bindingTypes == BindingTypes.OneWay) { return(propertyBBinding); } var propertyABinding = Observable.EveryUpdate() .Select(x => propertyAGetter()) .ApplyOutputFilters(filters) .DistinctUntilChanged() .Subscribe(x => propertyB.Value = converter.From(propertyAGetter())); return(new CompositeDisposable(propertyABinding, propertyBBinding)); }
public static IDisposable Bind <T1, T2>(IReactiveProperty <T1> propertyA, IReactiveProperty <T2> propertyB, IConvertor <T1, T2> convertor, BindingTypes bindingTypes = BindingTypes.Default, params IFilter <T1>[] filters) { var propertyBBinding = propertyB .Select(convertor.From) .ApplyInputFilters(filters) .DistinctUntilChanged() .Subscribe(x => propertyA.Value = x); if (bindingTypes == BindingTypes.OneWay) { return(propertyBBinding); } var propertyABinding = propertyA .ApplyOutputFilters(filters) .DistinctUntilChanged() .Select(convertor.From) .Subscribe(x => propertyB.Value = x); return(new CompositeDisposable(propertyABinding, propertyBBinding)); }
public static ReactiveProperty <string> ToTextualProperty <T>(this IReactiveProperty <T> nonStringProperty) { return(nonStringProperty.Select(x => x.ToString()).ToReactiveProperty() as ReactiveProperty <string>); }
public FFmpegDownloadViewModel(FFmpegSettings FFmpegSettings, FFmpegDownloadModel DownloadModel, IFFmpegViewsProvider FFmpegViewsProvider, IMessageProvider MessageProvider) { this.FFmpegSettings = FFmpegSettings; _downloadModel = DownloadModel; _messageProvider = MessageProvider; StartCommand = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Ready) .ToReactiveCommand() .WithSubscribe(async() => { var progress = new Progress <FFmpegDownloaderProgress>(M => _downloaderProgress.Value = M); _downloadTask = DownloadModel.Start(progress, _cancellationTokenSource.Token); var result = await _downloadTask; AfterDownload?.Invoke(result); }); CanCancel = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Downloading) .ToReadOnlyReactivePropertySlim(); SelectFolderCommand = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Ready) .ToReactiveCommand() .WithSubscribe(FFmpegViewsProvider.PickFolder); OpenFolderCommand = new ReactiveCommand() .WithSubscribe(() => { var path = FFmpegSettings.GetFolderPath(); if (Directory.Exists(path)) { Process.Start(path); } }); Status = _downloaderProgress .Select(M => { switch (M.State) { case FFmpegDownloaderState.Error: return(M.ErrorMessage); case FFmpegDownloaderState.Downloading: return($"{FFmpegDownloaderState.Downloading} ({M.DownloadProgress}%)"); default: return(M.State.ToString()); } }) .ToReadOnlyReactivePropertySlim(); Progress = _downloaderProgress .Where(M => M.State == FFmpegDownloaderState.Downloading) .Select(M => M.DownloadProgress) .ToReadOnlyReactivePropertySlim(); Progress.Subscribe(M => ProgressChanged?.Invoke(M)); InProgress = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Downloading || M == FFmpegDownloaderState.Extracting) .ToReadOnlyReactivePropertySlim(); IsDone = _downloaderProgress .Select(M => M.State) .Select(M => M == FFmpegDownloaderState.Done || M == FFmpegDownloaderState.Cancelled || M == FFmpegDownloaderState.Error) .ToReadOnlyReactivePropertySlim(); }