} = new ReactiveCommand(); // いつでも実行可能 public MainViewModel(INavigationService navigationService, IPageDialogService dialogService, IStopWatchModel stopWatch) { // ■プロパティの実装 // StopWatchModel の各プロパティをそのまま公開してるだけ IsRunning = stopWatch.IsRunning; FormattedLaps = stopWatch.FormattedLaps; IsVisibleMillis = stopWatch.IsVisibleMillis; // 表示用にthrottleで20ms毎に間引き。View側でやってもよいかも。 FormattedTime = stopWatch.FormattedTime //.Do(x=> Debug.WriteLine($"Throttled:{x}")) .ToReadOnlyReactiveProperty(); //// STOP されたら、最速/最遅ラップを表示して、LapActivity へ遷移 IsRunning.Buffer(2, 1).Where(x => x[0] && !x[1]) .Subscribe(async _ => { // Alert を表示させる await dialogService.DisplayAlertAsync( "Fastest/Worst Lap", $"Fastest:{stopWatch.FormattedFastestLap.Value}\n" + $"Worst:{stopWatch.FormattedWorstLap.Value}", "Close"); // LapActivity へ遷移させる await navigationService.NavigateAsync("LapPage"); }) .AddTo(_subscriptions); // ■コマンドの実装 // 開始 or 終了 StartOrStopCommand = new ReactiveCommand(); // いつでも実行可能 StartOrStopCommand.Subscribe(_ => { stopWatch.StartOrStop(); }); // 経過時間の記録 LapCommand = IsRunning.ToReactiveCommand(); // 実行中のみ記録可能 LapCommand.Subscribe(_ => { stopWatch.Lap(); }); // ミリ秒以下表示の切り替え ToggleVisibleMillisCommand = new ReactiveCommand(); // いつでも実行可能 ToggleVisibleMillisCommand.Subscribe(_ => { stopWatch.ToggleVisibleMillis(); }); }
public LapViewModel(IStopWatchModel stopWatch) { // ■プロパティの実装 // StopWatchModel の各プロパティをそのまま公開してるだけ FormattedLaps = stopWatch.FormattedLaps; }