public TasksViewModel(ITasksService tasksService, IPlaybackControl playbackControl, IEventLog eventLog, ILogger logger) { this.tasksService = tasksService; this.playbackControl = playbackControl; this.eventLog = eventLog; this.logger = logger; this.ModalitiesSelection = Selection <Modality> .FromEnum(); this.Genders = Selection <Gender> .FromEnum(); this.Proband = new Proband(); this.Tasks = new ReactiveList <TvControlTaskViewModel> { ChangeTrackingEnabled = true }; this.Reset = ReactiveCommand.Create(ResetImplementation); this.Save = ReactiveCommand.CreateFromTask(this.SaveAsync); this.Add = ReactiveCommand.Create(this.AddImpl); this.StartStop = ReactiveCommand.Create(this.StartStopImpl); this.SetFinished = ReactiveCommand.Create <bool, Unit>(this.SetFinishedImpl, this.WhenAnyValue(model => model.CurrentTask).Select(model => model != null)); this.InitAsync(); }
public TvControlViewModel(ITvStations tvStations, IPlaybackControl control) { this.tvStations = tvStations; this.control = control; Current = this; this.InitAsync(); this.Volume = control.Volume; this.WhenAnyValue(model => model.SelectedIndex) //.Where(i => i >= 0) .ObserveOnDispatcher() .Select(i => this.TvStations.ElementAtOrDefault(i)) .ToProperty(this, model => model.SelectedStation, out this.selectedStation); this.WhenAnyValue(model => model.SelectedStation).ObserveOnDispatcher().Subscribe(station => { this.control.SetStation(station); }); this.WhenAnyValue(model => model.Volume).Subscribe(vol => this.DisplayVolume = Math.Round(100 * vol, 0, MidpointRounding.AwayFromZero).ToString()); this.ChangeStationCommand = ReactiveCommand.Create <int>(dir => { int newIndexAbsolute = this.SelectedIndex + (dir > 0 ? 1 : -1); this.SelectedIndex = newIndexAbsolute < 0 ? this.TvStations.Count - 1 : newIndexAbsolute >= this.TvStations.Count ? 0 : newIndexAbsolute; }); this.ChangeVolumeCommand = ReactiveCommand.Create <int, Unit>(dir => { RxApp.MainThreadScheduler.Schedule(() => { this.Volume = this.control.ChangeVolume(dir); }); return(Unit.Default); }); this.ToggleInfoCommand = ReactiveCommand.Create <TvStation, Unit>(station => { station = station ?? this.SelectedStation; bool show = !(this.infoStation?.Id?.Equals(station?.Id) ?? false); this.infoStation = station; RxApp.MainThreadScheduler.Schedule(async() => { try { await this.control.ToggleInfoAsync(station, show); } catch { } this.infoStation = null; }); return(Unit.Default); }); this.ToggleOnOff = ReactiveCommand.Create(() => { var isOn = this.SelectedStation != null; if (isOn) { this.SelectedIndex = -1; } else { this.SelectedIndex = 0; } }); }