예제 #1
0
        protected override void OnDeactivate(bool close)
        {
            if (!PasscodeEnabled)
            {
                PasscodeUtils.Reset();
            }

            base.OnDeactivate(close);
        }
예제 #2
0
        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();
                }
            };
        }