Ejemplo n.º 1
0
        private void UpdateStickersSubtitle(TLFeaturedStickers featuredStickers, TLAllStickers29 allStickers, TLAllStickers29 masks)
        {
            if (featuredStickers != null && featuredStickers.Unread.Count > 0)
            {
                var count = featuredStickers.Unread.Count;
                StickersSubtitle = Language.Declension(
                    count == 0 ? 1 : count,
                    AppResources.NewStickerPackNominativeSingular,
                    null,
                    AppResources.NewStickerPackGenitiveSingular,
                    AppResources.NewStickerPackGenitivePlural,
                    count < 2
                        ? string.Format("{1} {0}", AppResources.NewStickerPackNominativeSingular, 1).ToLowerInvariant()
                        : string.Format("{1} {0}", AppResources.NewStickerPackNominativePlural, Math.Abs(count))).ToLowerInvariant();
            }
            else if (allStickers != null || masks != null)
            {
                var parts = new List <string>();
                if (allStickers != null)
                {
                    var count = allStickers.Sets.Count;
                    var part  = Language.Declension(
                        count == 0 ? 1 : count,
                        AppResources.StickerPackNominativeSingular,
                        null,
                        AppResources.StickerPackGenitiveSingular,
                        AppResources.StickerPackGenitivePlural,
                        count < 2
                            ? string.Format("{1} {0}", AppResources.StickerPackNominativeSingular, 1).ToLowerInvariant()
                            : string.Format("{1} {0}", AppResources.StickerPackNominativePlural, Math.Abs(count))).ToLowerInvariant();

                    parts.Add(part);
                }
                if (masks != null)
                {
                    var count = masks.Sets.Count;
                    var part  = Language.Declension(
                        count == 0 ? 1 : count,
                        AppResources.MaskPackNominativePlural,
                        null,
                        AppResources.MaskPackGenitiveSingular,
                        AppResources.MaskPackGenitivePlural,
                        count < 2
                            ? string.Format("{1} {0}", AppResources.MaskPackNominativeSingular, 1).ToLowerInvariant()
                            : string.Format("{1} {0}", AppResources.MaskPackNominativePlural, Math.Abs(count))).ToLowerInvariant();

                    parts.Add(part);
                }
                StickersSubtitle = string.Join(", ", parts);
            }
        }
Ejemplo n.º 2
0
        private void UpdateSets(TLAllStickers29 allStickers, System.Action callback)
        {
            _allStickers = allStickers;

            _emoticons.Clear();
            _stickerSets.Clear();

            for (var i = 0; i < allStickers.Documents.Count; i++)
            {
                var document22 = allStickers.Documents[i] as TLDocument22;
                if (document22 != null)
                {
                    if (document22.StickerSet != null)
                    {
                        var setId = document22.StickerSet.Name;
                        TLVector <TLStickerItem> stickers;
                        if (_stickerSets.TryGetValue(setId, out stickers))
                        {
                            stickers.Add(new TLStickerItem {
                                Document = document22
                            });
                        }
                        else
                        {
                            _stickerSets[setId] = new TLVector <TLStickerItem> {
                                new TLStickerItem {
                                    Document = document22
                                }
                            };
                        }
                    }
                }
            }

            Items.Clear();

            var firstChunkSize = 10;
            var count          = 0;
            var delayedItems   = new List <TLStickerSetBase>();

            for (var i = 0; i < allStickers.Sets.Count; i++)
            {
                var set     = allStickers.Sets[i];
                var setName = set.Id.ToString();
                TLVector <TLStickerItem> stickers;
                if (_stickerSets.TryGetValue(setName, out stickers))
                {
                    var objects = new TLVector <TLObject>();
                    foreach (var sticker in stickers)
                    {
                        objects.Add(sticker);
                    }

                    set.IsSelected = StickerSet != null && TLString.Equals(StickerSet.ShortName, set.ShortName, StringComparison.OrdinalIgnoreCase);
                    set.Stickers   = objects;
                    if (set.Stickers.Count > 0)
                    {
                        if (count < firstChunkSize)
                        {
                            Items.Add(set);
                            count++;
                        }
                        else
                        {
                            delayedItems.Add(set);
                        }
                    }
                }
            }

            AddItemsChunk(25, delayedItems, callback);
        }
Ejemplo n.º 3
0
        public SettingsViewModel(ITransportService transportService, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            eventAggregator.Subscribe(this);

            TransportService = transportService;

            SuppressUpdateStatus = true;

            //tombstoning
            if (stateService.CurrentContact == null)
            {
                ShellViewModel.Navigate(NavigationService);
                return;
            }

            UpdateProxySubtitle(TransportService.GetProxyConfig());

            CurrentItem = stateService.CurrentContact;
            stateService.CurrentContact = null;

            _allStickers      = StateService.GetAllStickers() as TLAllStickers29;
            _masks            = StateService.GetMasks() as TLAllStickers29;
            _featuredStickers = StateService.GetFeaturedStickers();
            if (_featuredStickers != null)
            {
                UpdateSets(_featuredStickers, _featuredStickers.Unread);
            }
            UpdateStickersSubtitle(_featuredStickers, _allStickers, _masks);

            StateService.GetNotifySettingsAsync(
                settings =>
            {
                _saveIncomingPhotos = settings.SaveIncomingPhotos;
                _invisibleMode      = settings.InvisibleMode;
#if DISABLE_INVISIBLEMODE
                _invisibleMode = false;
#endif

                BeginOnUIThread(() =>
                {
                    NotifyOfPropertyChange(() => SaveIncomingPhotos);
                    NotifyOfPropertyChange(() => InvisibleMode);
                });
            });

            if (CurrentItem == null || CurrentItem.NotifySettings == null)
            {
                BeginOnThreadPool(() =>
                {
                    MTProtoService.GetFullUserAsync(new TLInputUserSelf(),
                                                    userFull =>
                    {
                        CurrentItem = userFull.User;

                        BeginOnUIThread(() =>
                        {
                            var user = CurrentItem as TLUser66;
                            if (user != null)
                            {
                                user.NotifyOfPropertyChange(() => user.About);
                            }
                        });
                    });
                });
            }
        }