private void LoadStickersAsync() { LoadingProgressBar.Visibility = Visibility.Visible; var mtProtoService = IoC.Get <IMTProtoService>(); mtProtoService.GetAllStickersAsync(TLString.Empty, result => { var allStickers = result as TLAllStickers43; if (allStickers != null) { var stateService = IoC.Get <IStateService>(); stateService.SaveAllStickersAsync(allStickers); Execute.BeginOnUIThread(() => { LoadingProgressBar.Visibility = Visibility.Collapsed; _stickers = result as TLAllStickers; CreateSets(_stickers); UpdateButtons(_stickers, StickersPanel, _recentStickersButton, _stickersButtons); if (StickersScrollViewer.Visibility == Visibility.Visible) { LoadSprites(_stickers, _stickersButtons); } }); } }, error => Execute.BeginOnUIThread(() => { Execute.ShowDebugMessage("messages.getAllStickers error " + error); LoadingProgressBar.Visibility = Visibility.Collapsed; })); }
public StickersControl(TLAllStickers masks, TLAllStickers stickers) { InitializeComponent(); LayoutRoot.Opacity = 0.0; VirtPanel.InitializeWithScrollViewer(CSV); Loaded += OnLoaded; _masks = masks; _stickers = stickers; if (_masks == null) { LoadMasksAsync(); } if (_stickers == null) { LoadStickersAsync(); } LoadButtons(); CreateSetsAndUpdatePanel(); }
public void ClearAllStickersAsync() { Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => { _allStickers = null; FileUtils.Delete(_allStickersRoot, Constants.AllStickersFileName); }); }
public void ClearMasksAsync() { Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => { _masks = null; FileUtils.Delete(_masksRoot, Constants.MasksFileName); }); }
public TLAllStickers GetMasks() { if (_masks != null) { return(_masks); } _masks = TLUtils.OpenObjectFromMTProtoFile <TLAllStickers>(_masksRoot, Constants.MasksFileName); return(_masks); }
private void LoadSprites(TLAllStickers allStickers, List <Button> buttons) { if (VirtPanel.Children.Count > 0) { return; } var selectRecentlyUsedStickers = false; var selectFirstStickerSet = false; var allStickers43 = allStickers as TLAllStickers43; if (allStickers43 != null && (allStickers43.RecentlyUsed == null || allStickers43.RecentlyUsed.Count == 0)) { if (buttons.Count > 0) { selectFirstStickerSet = true; } } if (!selectFirstStickerSet) { selectRecentlyUsedStickers = true; } if (selectFirstStickerSet) { Execute.BeginOnUIThread(() => { StickerSetButtonOnClick(buttons[0], null); LoadingProgressBar.Visibility = Visibility.Collapsed; return; }); } if (selectRecentlyUsedStickers) { Execute.BeginOnUIThread(() => { if (allStickers == _masks) { RecentMasksButtonOnClick(_recentMasksButton, null); } else if (allStickers == _stickers) { RecentStickersButtonOnClick(_recentStickersButton, null); } LoadingProgressBar.Visibility = Visibility.Collapsed; return; }); } }
public TLAllStickers GetAllStickers() { if (_allStickers != null) { return(_allStickers); } _allStickers = TLUtils.OpenObjectFromMTProtoFile <TLAllStickers>(_allStickersRoot, Constants.AllStickersFileName); ProcessAllStickers(); return(_allStickers); }
public void GetAllStickersAsync(Action <TLAllStickers> callback) { if (_allStickers != null) { callback(_allStickers); return; } Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => { _allStickers = TLUtils.OpenObjectFromMTProtoFile <TLAllStickers>(_allStickersRoot, Constants.AllStickersFileName); callback(_allStickers); }); }
public void SaveAllStickersAsync(TLAllStickers allStickers) { Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => { _allStickers = allStickers; if (allStickers != null) { var allStickers29 = allStickers as TLAllStickers29; if (allStickers29 != null && allStickers29.RecentlyUsed != null) { allStickers29.RecentlyUsed = new TLVector <TLRecentlyUsedSticker>(allStickers29.RecentlyUsed.Take(20).ToList()); } } TLUtils.SaveObjectToMTProtoFile(_allStickersRoot, Constants.AllStickersFileName, allStickers); }); }
private void UpdateAllStickersAsync(TLAllStickers cachedStickers) { var hash = cachedStickers != null ? cachedStickers.Hash : TLString.Empty; IsWorking = true; MTProtoService.GetAllStickersAsync(hash, result => BeginOnUIThread(() => { Execute.ShowDebugMessage(result.ToString()); Status = string.Empty; IsWorking = false; var allStickers = result as TLAllStickers43; if (allStickers != null) { Items.Clear(); var cachedStickers29 = cachedStickers as TLAllStickers29; if (cachedStickers29 != null) { allStickers.ShowStickersTab = cachedStickers29.ShowStickersTab; allStickers.RecentlyUsed = cachedStickers29.RecentlyUsed; allStickers.Date = TLUtils.DateToUniversalTimeTLInt(0, DateTime.Now); } var cachedStickers43 = cachedStickers as TLAllStickers43; if (cachedStickers43 != null) { allStickers.RecentStickers = cachedStickers43.RecentStickers; allStickers.FavedStickers = cachedStickers43.FavedStickers; } cachedStickers = allStickers; StateService.SaveAllStickersAsync(cachedStickers); UpdateSets(allStickers, () => { }); } }), error => BeginOnUIThread(() => { Status = string.Empty; IsWorking = false; Execute.ShowDebugMessage("messages.getAllStickers error " + error); })); }
public void ForwardInAnimationComplete() { StateService.GetAllStickersAsync(cachedAllStickers => BeginOnUIThread(() => { _allStickers = cachedAllStickers; var allStickers = _allStickers as TLAllStickers43; if (allStickers != null) { UpdateSets(allStickers, () => UpdateAllStickersAsync(allStickers)); Status = string.Empty; } else { UpdateAllStickersAsync(null); } })); }
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); }
public void GetAllStickersAsync() { StateService.GetAllStickersAsync(cachedStickers => { Stickers = cachedStickers; var cachedStickers43 = cachedStickers as TLAllStickers43; if (cachedStickers43 != null && cachedStickers43.FavedStickers == null) { MTProtoService.GetFavedStickersAsync(new TLInt(0), result => { var favedStickers = result as TLFavedStickers; if (favedStickers != null) { cachedStickers43.FavedStickers = favedStickers; StateService.SaveAllStickersAsync(cachedStickers43); } }, error => { }); } var featuredStickers = StateService.GetFeaturedStickers(); if (featuredStickers == null) { MTProtoService.GetFeaturedStickersAsync(true, new TLInt(0), result => { featuredStickers = result as TLFeaturedStickers; if (featuredStickers != null) { StateService.SaveFeaturedStickersAsync(featuredStickers); } }, error => { }); } var cachedStickers29 = cachedStickers as TLAllStickers29; if (cachedStickers29 != null && cachedStickers29.Date != null && cachedStickers29.Date.Value != 0) { var date = TLUtils.ToDateTime(cachedStickers29.Date); if ( date < DateTime.Now.AddSeconds(Constants.GetAllStickersInterval)) { return; } } var hash = cachedStickers != null ? cachedStickers.Hash ?? TLString.Empty : TLString.Empty; MTProtoService.GetAllStickersAsync(hash, result => { var allStickers = result as TLAllStickers43; if (allStickers != null) { if (cachedStickers29 != null) { allStickers.ShowStickersTab = cachedStickers29.ShowStickersTab; allStickers.RecentlyUsed = cachedStickers29.RecentlyUsed; allStickers.Date = TLUtils.DateToUniversalTimeTLInt(0, DateTime.Now); } if (cachedStickers43 != null) { allStickers.RecentStickers = cachedStickers43.RecentStickers; allStickers.FavedStickers = cachedStickers43.FavedStickers; } Stickers = allStickers; cachedStickers = allStickers; StateService.SaveAllStickersAsync(cachedStickers); } }, error => { Execute.ShowDebugMessage("messages.getAllStickers error " + error); }); }); }
private void UpdateButtons(TLAllStickers allStickersBase, Panel panel, Button recentStickersButton, List <Button> allButtons) { panel.Children.Clear(); if (allStickersBase == null) { return; } var allStickers43 = allStickersBase as TLAllStickers43; if (allStickers43 != null) { recentStickersButton.Visibility = allStickers43.RecentlyUsed == null || allStickers43.RecentlyUsed.Count == 0 ? Visibility.Collapsed : Visibility.Visible; } panel.Children.Add(recentStickersButton); var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible; var buttonStyleResourceKey = isLightTheme ? "CategoryButtonLightThemeStyle" : "CategoryButtonDarkThemeStyle"; var buttonStyle = (Style)Resources[buttonStyleResourceKey]; allButtons.Clear(); var allStickers = allStickersBase as TLAllStickers29; if (allStickers != null) { foreach (var stickerSet in allStickers.Sets) { var key = stickerSet.Id.Value.ToString(CultureInfo.InvariantCulture); List <TLDocument22> stickers; if (_stickerSets.TryGetValue(key, out stickers)) { var image = new Image { Width = 53.0, Height = 53.0, DataContext = new TLStickerItem { Document = stickers.FirstOrDefault() } }; var binding = new Binding("Self") { Converter = new DefaultPhotoConverter(), ConverterParameter = 64.0 }; image.SetBinding(Image.SourceProperty, binding); var button = new Button { Width = 78.0, Height = 78.0, Style = buttonStyle, Content = image, DataContext = key }; button.Click += StickerSetButtonOnClick; button.Tap += StickerSetButtonOnTap; panel.Children.Add(button); allButtons.Add(button); } } } }
private void CreateSets(TLAllStickers allStickers) { if (allStickers == null) { return; } var recentlyUsedSetId = allStickers == _masks? RecentlyUsedMasksKey : RecentlyUsedStickersKey; _stickerSets[recentlyUsedSetId] = new List <TLDocument22>(); var documentsCache = new Dictionary <long, TLDocument22>(); for (var i = 0; i < allStickers.Documents.Count; i++) { var document22 = allStickers.Documents[i] as TLDocument22; if (document22 != null) { documentsCache[document22.Id.Value] = document22; if (document22.StickerSet != null) { var setId = document22.StickerSet.Name; List <TLDocument22> stickers; if (_stickerSets.TryGetValue(setId, out stickers)) { stickers.Add(document22); } else { _stickerSets[setId] = new List <TLDocument22> { document22 }; } } } } var allStickers43 = allStickers as TLAllStickers43; if (allStickers43 != null) { if (allStickers43.RecentlyUsed != null) { var documentsDict = new Dictionary <long, TLDocumentBase>(); foreach (var document in allStickers43.Documents) { documentsDict[document.Id.Value] = document; } for (var i = 0; i < allStickers43.RecentlyUsed.Count; i++) { TLDocumentBase document; var recentlyUsedDocument = allStickers43.RecentlyUsed[i]; if (documentsDict.TryGetValue(recentlyUsedDocument.Id.Value, out document)) { var document22 = document as TLDocument22; if (document22 != null) { documentsCache[document22.Id.Value] = document22; List <TLDocument22> stickers; if (_stickerSets.TryGetValue(recentlyUsedSetId, out stickers)) { stickers.Add(document22); } else { _stickerSets[recentlyUsedSetId] = new List <TLDocument22> { document22 }; } } } } } } }