Exemple #1
0
        public void Done()
        {
            Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.1), () =>
            {
                if (!PasscodeUtils.Check(Passcode))
                {
                    Passcode = string.Empty;
                    RaisePasscodeIncorrect();

                    return;
                }

                var frame = Application.Current.RootVisual as TelegramTransitionFrame;
                if (frame != null)
                {
                    Execute.BeginOnUIThread(() =>
                    {
                        frame.CloseLockscreen();
                        PasscodeUtils.Unlock();     // will not invoke here ShellViewModel.UpdateDeviceLockedAsync()
                        var shellViewModel = IoC.Get <ShellViewModel>();
                        if (shellViewModel != null)
                        {
                            shellViewModel.NotifyOfPropertyChange(() => shellViewModel.PasscodeImageBrush);
                            shellViewModel.NotifyOfPropertyChange(() => shellViewModel.PasscodeImageSource);
                            shellViewModel.UpdateDeviceLockedAsync();
                        }

                        Passcode = string.Empty;
                    });
                }
            });
        }
        protected override void OnDeactivate(bool close)
        {
            if (!PasscodeEnabled)
            {
                PasscodeUtils.Reset();
            }

            base.OnDeactivate(close);
        }
        public bool CheckPasscode(string passcode)
        {
            if (string.IsNullOrEmpty(passcode))
            {
                return(false);
            }

            if (Simple)
            {
                return(PasscodeUtils.CheckSimple(passcode));
            }

            return(true);
        }
        public void Done()
        {
            if (!IsPasscodeValid)
            {
                return;
            }

            var isSimplePasscode = _selectedPasscodeType != null && _selectedPasscodeType.Type == PasscodeType.Pin;

            if (isSimplePasscode)
            {
                isSimplePasscode = PasscodeUtils.CheckSimple(Passcode);
            }

            PasscodeUtils.SetParams(Passcode, isSimplePasscode, _selectedAutolockTimeout);
            UpdateDeviceLockedAsync();
            NavigationService.GoBack();
        }
        public PasscodeViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            AutolockSpans = new List <TimerSpan>
            {
                new TimerSpan(AppResources.AutolockDisabled, string.Empty, int.MaxValue, AppResources.Disabled),
                new TimerSpan(AppResources.MinuteNominativeSingular, "1", (int)TimeSpan.FromMinutes(1.0).TotalSeconds, string.Format(AppResources.PasscodeAutolockIn, string.Format("{0} {1}", "1", AppResources.MinuteNominativeSingular).ToLowerInvariant())),
                new TimerSpan(AppResources.MinuteGenitivePlural, "5", (int)TimeSpan.FromMinutes(5.0).TotalSeconds, string.Format(AppResources.PasscodeAutolockIn, string.Format("{0} {1}", "5", AppResources.MinuteGenitivePlural).ToLowerInvariant())),
                new TimerSpan(AppResources.HourNominativeSingular, "1", (int)TimeSpan.FromHours(1.0).TotalSeconds, string.Format(AppResources.PasscodeAutolockIn, string.Format("{0} {1}", "1", AppResources.HourNominativeSingular).ToLowerInvariant())),
                new TimerSpan(AppResources.HourGenitivePlural, "5", (int)TimeSpan.FromHours(5.0).TotalSeconds, string.Format(AppResources.PasscodeAutolockIn, string.Format("{0} {1}", "5", AppResources.HourGenitivePlural).ToLowerInvariant())),
            };
            _selectedAutolockSpan = AutolockSpans.FirstOrDefault(x => x.Seconds == PasscodeUtils.AutolockTimeout) ?? AutolockSpans[AutolockSpanDefaultIndex];

            _passcodeEnabled = PasscodeUtils.IsEnabled;

            PropertyChanged += (o, e) =>
            {
                if (Property.NameEquals(e.PropertyName, () => PasscodeEnabled))
                {
                    if (PasscodeEnabled)
                    {
                        ChangePasscode();

                        if (!PasscodeUtils.IsEnabled)
                        {
                            PasscodeUtils.Reset();
                            SelectedAutolockSpan = AutolockSpans[AutolockSpanDefaultIndex];
                        }
                    }
                    else
                    {
                        PasscodeUtils.Reset();
                        UpdateDeviceLockedAsync();
                    }
                }
                else if (Property.NameEquals(e.PropertyName, () => SelectedAutolockSpan))
                {
                    UpdateDeviceLockedAsync();
                }
            };
        }