示例#1
0
 public LoginViewModel(Action refreshLoginBindings, Action refreshSignupBindings)
     : base(RxApp.TaskpoolScheduler)
 {
     _refreshLoginBindings     = refreshLoginBindings;
     _refreshSignupBindings    = refreshSignupBindings;
     Toggl.OnDisplayCountries += OnDisplayCountries;
     Toggl.OnSettings         += OnSettings;
     this.WhenAnyValue(x => x.SelectedConfirmAction,
                       x => x == ConfirmAction.LogIn ? "Log in" : "Sign up")
     .ToPropertyEx(this, x => x.ConfirmButtonText);
     this.WhenAnyValue(x => x.SelectedConfirmAction,
                       x => x == ConfirmAction.LogIn ? "Log in with Google" : "Sign up with Google")
     .ToPropertyEx(this, x => x.GoogleLoginButtonText);
     this.WhenAnyValue(x => x.SelectedConfirmAction,
                       x => x == ConfirmAction.LogIn ? "Sign up for free" : "Back to Log in")
     .ToPropertyEx(this, x => x.SignupLoginToggleText);
     this.ObservableForProperty(x => x.SelectedConfirmAction)
     .Where(x => x.Value == ConfirmAction.SignUp)
     .Take(1)
     .ObserveOn(RxApp.TaskpoolScheduler)
     .Subscribe(_ => Toggl.GetCountries());
     ConfirmLoginSignupCommand       = ReactiveCommand.CreateFromTask(ConfirmLoginSignupAsync);
     ConfirmGoogleLoginSignupCommand = ReactiveCommand.Create(ConfirmGoogleLoginSignup);
     IsLoginSignupExecuting          = ConfirmLoginSignupCommand.IsExecuting
                                       .CombineLatest(ConfirmGoogleLoginSignupCommand.IsExecuting,
                                                      (isExecuting1, isExecuting2) => isExecuting1 || isExecuting2);
     IsLoginSignupExecuting
     .ToPropertyEx(this, x => x.IsLoading);
     IsLoginSignupExecuting
     .Select(x => !x)
     .ToPropertyEx(this, x => x.IsViewEnabled);
 }
示例#2
0
        public LoginViewModel(Action refreshLoginBindings, Action refreshSignupBindings)
            : base(RxApp.TaskpoolScheduler)
        {
            _refreshLoginBindings     = refreshLoginBindings;
            _refreshSignupBindings    = refreshSignupBindings;
            Toggl.OnDisplayCountries += OnDisplayCountries;
            Toggl.OnSettings         += OnSettings;
            this.WhenAnyValue(x => x.SelectedConfirmAction,
                              x => x == ConfirmAction.LogIn ? "Log in" : "Sign up")
            .ToPropertyEx(this, x => x.ConfirmButtonText);
            this.WhenAnyValue(x => x.SelectedConfirmAction,
                              x => x == ConfirmAction.LogIn ? "Log in with Google" : "Sign up with Google")
            .ToPropertyEx(this, x => x.GoogleLoginButtonText);
            this.WhenAnyValue(x => x.SelectedConfirmAction,
                              x => x == ConfirmAction.LogIn ? "Sign up for free" : "Back to Log in")
            .ToPropertyEx(this, x => x.SignupLoginToggleText);
            this.ObservableForProperty(x => x.SelectedConfirmAction)
            .Where(x => x.Value == ConfirmAction.SignUp)
            .Take(1)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(_ => Toggl.GetCountries());
            ConfirmLoginSignupCommand       = ReactiveCommand.CreateFromTask(ConfirmLoginSignupAsync);
            ConfirmGoogleLoginSignupCommand = ReactiveCommand.Create(ConfirmGoogleLoginSignup);
            IsLoginSignupExecuting          = ConfirmLoginSignupCommand.IsExecuting
                                              .CombineLatest(ConfirmGoogleLoginSignupCommand.IsExecuting,
                                                             (isExecuting1, isExecuting2) => isExecuting1 || isExecuting2);
            IsLoginSignupExecuting
            .ToPropertyEx(this, x => x.IsLoading);
            IsLoginSignupExecuting
            .Select(x => !x)
            .ToPropertyEx(this, x => x.IsViewEnabled);

            // password rules
            var passwordObservable = this.WhenAnyValue(x => x.Password).Where(x => x != null);

            passwordObservable.Select(PasswordEx.IsEightCharactersOrMore)
            .ToPropertyEx(this, x => x.IsEightCharactersOrMore);
            passwordObservable.Select(PasswordEx.IsLowercaseAndUppercase)
            .ToPropertyEx(this, x => x.IsLowercaseAndUppercase);
            passwordObservable.Select(PasswordEx.IsAtLeastOneNumber)
            .ToPropertyEx(this, x => x.IsAtLeastOneNumber);
            var canShowPasswordStrength = this.WhenAnyValue(x => x.IsPasswordFocused,
                                                            x => x.SelectedConfirmAction,
                                                            (isFocused, confirmAction) => isFocused && confirmAction == ConfirmAction.SignUp);
            var shouldHidePasswordStrength = passwordObservable.Select(PasswordEx.AllRulesSatisfied)
                                             .Delay(satisfied => satisfied ? Observable.Timer(TimeSpan.FromSeconds(1)) : Observable.Return(0L));

            canShowPasswordStrength.CombineLatest(shouldHidePasswordStrength, (canShow, shouldHide) => canShow && !shouldHide)
            .ToPropertyEx(this, x => x.ShowPasswordStrength);
        }