public LoginViewModel(ICTimeService cTimeService, IApplicationStateService applicationStateService, IShell shell, IDialogService dialogService, IBiometricsService biometricsService) { Guard.NotNull(cTimeService, nameof(cTimeService)); Guard.NotNull(applicationStateService, nameof(applicationStateService)); Guard.NotNull(shell, nameof(shell)); Guard.NotNull(dialogService, nameof(dialogService)); Guard.NotNull(biometricsService, nameof(biometricsService)); this._cTimeService = cTimeService; this._applicationStateService = applicationStateService; this._shell = shell; this._dialogService = dialogService; this._biometricsService = biometricsService; var canLogin = this.WhenAnyValue(f => f.EmailAddress, f => f.Password, (email, password) => string.IsNullOrWhiteSpace(email) == false && string.IsNullOrWhiteSpace(password) == false); this.Login = UwCoreCommand.Create(canLogin, this.LoginImpl) .ShowLoadingOverlay(CTime2Resources.Get("Loading.LoggingIn")) .HandleExceptions() .TrackEvent("Login"); var deviceAvailable = this._biometricsService.BiometricAuthDeviceIsAvailableAsync().ToObservable(); var userAvailable = this._biometricsService.HasUserForBiometricAuthAsync().ToObservable(); var canRememberedLogin = deviceAvailable .CombineLatest(userAvailable, (deviceAvail, userAvail) => deviceAvail && userAvail) .ObserveOnDispatcher(); this.RememberedLogin = UwCoreCommand.Create(canRememberedLogin, this.RememberedLoginImpl) .ShowLoadingOverlay(CTime2Resources.Get("Loading.LoggingIn")) .HandleExceptions() .TrackEvent("LoginRemembered"); this.DisplayName = CTime2Resources.Get("Navigation.Login"); }
public SettingsViewModel(IBiometricsService biometricsService, IApplicationStateService applicationStateService, IBandService bandService, IShell shell) { Guard.NotNull(biometricsService, nameof(biometricsService)); Guard.NotNull(applicationStateService, nameof(applicationStateService)); Guard.NotNull(bandService, nameof(bandService)); this._biometricsService = biometricsService; this._applicationStateService = applicationStateService; this._bandService = bandService; this._shell = shell; var hasUser = new ReplaySubject<bool>(1); hasUser.OnNext(this._applicationStateService.GetCurrentUser() != null); var deviceAvailable = this._biometricsService.BiometricAuthDeviceIsAvailableAsync().ToObservable(); var canRememberLogin = hasUser.CombineLatest(deviceAvailable, (hasUsr, deviceAvail) => hasUsr && deviceAvail); this.RememberLogin = UwCoreCommand.Create(canRememberLogin, this.RememberLoginImpl) .ShowLoadingOverlay(CTime2Resources.Get("Loading.RememberedLogin")) .HandleExceptions() .TrackEvent("SetupRememberLogin"); var canToggleTile = this.WhenAnyValue(f => f.State, state => state != BandState.NotConnected); this.ToggleBandTile = UwCoreCommand.Create(canToggleTile, this.ToggleTileImpl) .ShowLoadingOverlay(() => this.State == BandState.Installed ? CTime2Resources.Get("Loading.RemoveTileFromBand") : CTime2Resources.Get("Loading.AddTileToBand")) .HandleExceptions() .TrackEvent("ToggleBandTile"); this.Reload = UwCoreCommand.Create(this.ReloadImpl) .ShowLoadingOverlay(CTime2Resources.Get("Loading.Settings")) .HandleExceptions() .TrackEvent("ReloadSettings"); this.Theme = this._applicationStateService.GetApplicationTheme(); this.SelectedWorkTime = this._applicationStateService.GetWorkDayHours(); this.SelectedBreakTime = this._applicationStateService.GetWorkDayBreak(); this.CompanyId = this._applicationStateService.GetCompanyId(); this.WhenAnyValue(f => f.Theme) .Subscribe(theme => { this._shell.Theme = theme; this._applicationStateService.SetApplicationTheme(theme); }); this.WhenAnyValue(f => f.SelectedWorkTime) .Subscribe(workTime => { this._applicationStateService.SetWorkDayHours(workTime); }); this.WhenAnyValue(f => f.SelectedBreakTime) .Subscribe(breakTime => { this._applicationStateService.SetWorkDayBreak(breakTime); }); this.WhenAnyValue(f => f.CompanyId) .Subscribe(companyId => { this._applicationStateService.SetCompanyId(companyId); }); this.DisplayName = CTime2Resources.Get("Navigation.Settings"); this.WorkTimes = new ReactiveList<TimeSpan>(Enumerable .Repeat((object)null, 4 * 24) .Select((_, i) => TimeSpan.FromHours(0.25 * i))); this.BreakTimes = new ReactiveList<TimeSpan>(Enumerable .Repeat((object)null, 4 * 24) .Select((_, i) => TimeSpan.FromHours(0.25 * i))); }