Example #1
0
        public CacheViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            Spans = new List <TimerSpan>
            {
                new TimerSpan(AppResources.WeekNominativeSingular, "1", (int)TimeSpan.FromDays(7.0).TotalSeconds, string.Format("{0} {1}", "1", AppResources.WeekNominativeSingular).ToLowerInvariant()),
                new TimerSpan(AppResources.MonthNominativeSingular, "1", (int)TimeSpan.FromDays(30.0).TotalSeconds, string.Format("{0} {1}", "1", AppResources.MonthNominativeSingular).ToLowerInvariant()),
                new TimerSpan(AppResources.Forever, string.Empty, int.MaxValue, AppResources.Forever),
            };
            _selectedSpan = Spans[2];


            Files = new ObservableCollection <TelegramFileInfo>();

            _timer.Interval = TimeSpan.FromSeconds(30.0);
            _timer.Tick    += OnTimerTick;

            CalculateCacheSizeAsync((size1, size2) => BeginOnUIThread(() =>
            {
                Status = FileSizeConverter.Convert(size1);
                LocalDatabaseStatus = FileSizeConverter.Convert(size2);
                _settings.NotifyOfPropertyChange(() => _settings.Self);
            }));

            PropertyChanged += (sender, e) =>
            {
                if (Property.NameEquals(e.PropertyName, () => IsWorking))
                {
                    NotifyOfPropertyChange(() => CanClearCache);
                }
            };
        }
        public ChooseGeoLivePeriodViewModel(IStateService stateService)
        {
            _stateService = stateService;

            var selectedTimerSpan = _stateService.SelectedTimerSpan;

            _stateService.SelectedTimerSpan = null;

            var timerSpans = _stateService.TimerSpans;

            _stateService.TimerSpans = null;

            TimerSpan defaultSpan = null;

            Items = new LoopingObservableCollection <TimerSpan>();
            if (timerSpans != null)
            {
                foreach (var timerSpan in timerSpans)
                {
                    Items.Add(timerSpan);
                }
            }
            defaultSpan = Items[0];

            if (selectedTimerSpan != null)
            {
                Items.SelectedItem = Items.FirstOrDefault(x => x.Seconds == selectedTimerSpan.Seconds);
            }
            if (Items.SelectedItem == null)
            {
                Items.SelectedItem = defaultSpan;
            }
        }
        public ChooseVideoQualityViewModel(IStateService stateService)
        {
            _stateService = stateService;

            var selectedTimerSpan = _stateService.SelectedTimerSpan;

            _stateService.SelectedTimerSpan = null;

            var timerSpans = _stateService.TimerSpans;

            _stateService.TimerSpans = null;

            TimerSpan defaultSpan = null;

            Items = new LoopingObservableCollection <TimerSpan>();
            if (timerSpans != null)
            {
                foreach (var timerSpan in timerSpans)
                {
                    Items.Add(timerSpan);
                }
            }
            else
            {
                Items.Add(new TimerSpan(string.Empty, AppResources.Auto, 0));
                Items.Add(new TimerSpan(string.Empty, "240", 240));
                Items.Add(new TimerSpan(string.Empty, "360", 360));
                Items.Add(new TimerSpan(string.Empty, "480", 480));
                Items.Add(new TimerSpan(string.Empty, "720", 720));
                Items.Add(new TimerSpan(string.Empty, "1080", 1080));
            }
            defaultSpan = Items[0];

            if (selectedTimerSpan != null)
            {
                Items.SelectedItem = Items.FirstOrDefault(x => x.Seconds == selectedTimerSpan.Seconds);
            }
            if (Items.SelectedItem == null)
            {
                Items.SelectedItem = defaultSpan;
            }
        }
        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();
                }
            };
        }
Example #5
0
        public ChatDetailsViewModel(IUploadFileManager uploadManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            Spans = new List <TimerSpan>
            {
                new TimerSpan(AppResources.Enabled, string.Empty, 0, AppResources.Enabled),
                new TimerSpan(AppResources.HourNominativeSingular, "1", (int)TimeSpan.FromHours(1.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "1", AppResources.HourNominativeSingular).ToLowerInvariant())),
                new TimerSpan(AppResources.HourGenitivePlural, "8", (int)TimeSpan.FromHours(8.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "8", AppResources.HourGenitivePlural).ToLowerInvariant())),
                new TimerSpan(AppResources.DayNominativePlural, "2", (int)TimeSpan.FromDays(2.0).TotalSeconds, string.Format(AppResources.MuteFor, string.Format("{0} {1}", "2", AppResources.DayNominativePlural).ToLowerInvariant())),
                new TimerSpan(AppResources.Disabled, string.Empty, int.MaxValue, AppResources.Disabled),
            };
            _selectedSpan = Spans[0];

            _notificationTimer          = new DispatcherTimer();
            _notificationTimer.Interval = TimeSpan.FromSeconds(Constants.NotificationTimerInterval);
            _notificationTimer.Tick    += OnNotificationTimerTick;

            _uploadManager = uploadManager;
            eventAggregator.Subscribe(this);

            DisplayName = LowercaseConverter.Convert(AppResources.Profile);

            Items = new ObservableCollection <TLUserBase>();

            PropertyChanged += (sender, args) =>
            {
                if (Property.NameEquals(args.PropertyName, () => MuteUntil) &&
                    !_suppressUpdating)
                {
                    UpdateNotifySettingsAsync();
                }

                if (Property.NameEquals(args.PropertyName, () => SelectedSound) &&
                    !_suppressUpdating)
                {
                    NotificationsViewModel.PlaySound(SelectedSound);

                    UpdateNotifySettingsAsync();
                }
            };
        }
Example #6
0
        public void AttachGeoLive(GeoCoordinate location, TimerSpan timer)
        {
            if (location == null)
            {
                return;
            }
            if (location.Latitude == 0.0 && location.Longitude == 0.0)
            {
                return;
            }

            var mediaGeoLive = new TLMessageMediaGeoLive
            {
                Geo = new TLGeoPoint {
                    Lat = new TLDouble(location.Latitude), Long = new TLDouble(location.Longitude)
                },
                Period = new TLInt(timer.Seconds)
            };

            CloseEditor();
            ContinueAction.SafeInvoke(mediaGeoLive);
        }
Example #7
0
        public ChooseTTLViewModel(INavigationService navigationService, IStateService stateService)
        {
            _navigationService = navigationService;
            _stateService      = stateService;

            var isEncryptedTimer = _stateService.IsEncryptedTimer;

            _stateService.IsEncryptedTimer = false;

            var selectedTimerSpan = _stateService.SelectedTimerSpan;

            _stateService.SelectedTimerSpan = null;

            Items = new LoopingObservableCollection <TimerSpan>();
            TimerSpan defaultSpan = null;

            if (isEncryptedTimer)
            {
                Items.Add(new TimerSpan(AppResources.OffMasculine, string.Empty, 0));
                for (var i = 1; i <= 15; i++)
                {
                    Items.Add(new TimerSpan(
                                  Language.Declension2(
                                      i,
                                      AppResources.SecondNominativeSingular,
                                      AppResources.SecondNominativePlural,
                                      AppResources.SecondGenitiveSingular,
                                      AppResources.SecondGenitivePlural),
                                  i.ToString(), i));
                }
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "30", 30));
                Items.Add(new TimerSpan(AppResources.MinuteNominativeSingular, "1", 60));
                Items.Add(new TimerSpan(AppResources.HourNominativeSingular, "1", (int)TimeSpan.FromHours(1.0).TotalSeconds));
                Items.Add(new TimerSpan(AppResources.DayNominativeSingular, "1", (int)TimeSpan.FromDays(1.0).TotalSeconds));
                Items.Add(new TimerSpan(AppResources.WeekNominativeSingular, "1", (int)TimeSpan.FromDays(7.0).TotalSeconds));

                defaultSpan = Items[0];
            }
            else
            {
                Items.Add(new TimerSpan(AppResources.OffMasculine, string.Empty, 0));
                for (var i = 1; i <= 30; i++)
                {
                    Items.Add(new TimerSpan(
                                  Language.Declension2(
                                      i,
                                      AppResources.SecondNominativeSingular,
                                      AppResources.SecondNominativePlural,
                                      AppResources.SecondGenitiveSingular,
                                      AppResources.SecondGenitivePlural),
                                  i.ToString(), i));
                }
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "35", 35));
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "40", 40));
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "45", 45));
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "50", 50));
                Items.Add(new TimerSpan(AppResources.SecondGenitivePlural, "55", 55));
                Items.Add(new TimerSpan(AppResources.MinuteNominativeSingular, "1", 60));

                defaultSpan = Items[10];
            }

            if (selectedTimerSpan != null)
            {
                Items.SelectedItem = Items.FirstOrDefault(x => x.Seconds == selectedTimerSpan.Seconds);
            }
            if (Items.SelectedItem == null)
            {
                Items.SelectedItem = defaultSpan;
            }
        }
Example #8
0
 public void SelectSpan(TimerSpan selectedSpan)
 {
     SelectedSpan = selectedSpan;
 }