예제 #1
0
        private void Toolbar_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            if (args.Item is SupergroupStickerSetViewModel supergroup)
            {
                var chat = ViewModel.CacheService.GetChat(supergroup.ChatId);
                if (chat == null)
                {
                    return;
                }

                var content = args.ItemContainer.ContentTemplateRoot as ProfilePicture;
                if (content == null)
                {
                    return;
                }

                content.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36);
            }
            else if (args.Item is StickerSetViewModel sticker)
            {
                var content = args.ItemContainer.ContentTemplateRoot as Grid;
                var photo   = content?.Children[0] as Image;

                if (content == null || sticker == null || (sticker.Thumbnail == null && sticker.Covers == null))
                {
                    return;
                }

                var cover = sticker.Thumbnail ?? sticker.Covers.FirstOrDefault()?.Thumbnail;
                if (cover == null)
                {
                    photo.Source = null;
                    return;
                }

                var file = cover.File;
                if (file.Local.IsDownloadingCompleted)
                {
                    if (sticker.IsAnimated)
                    {
                        photo.Source = PlaceholderHelper.GetLottieFrame(file.Local.Path, 0, 36, 36);
                    }
                    else
                    {
                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                }
                else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                {
                    photo.Source = null;
                    DownloadFile(_stickerSets, file.Id, sticker);
                }
            }
        }
예제 #2
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content    = args.ItemContainer.ContentTemplateRoot as Grid;
            var stickerSet = args.Item as StickerSetInfo;

            content.Tag = stickerSet;

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = stickerSet.Title;
            }
            else if (args.Phase == 1)
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = Locale.Declension("Stickers", stickerSet.Size);
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as Image;

                var cover = stickerSet.Thumbnail ?? stickerSet.Covers.FirstOrDefault()?.Thumbnail;
                if (cover == null)
                {
                    return;
                }

                var file = cover.File;
                if (file.Local.IsDownloadingCompleted)
                {
                    if (cover.Format is ThumbnailFormatTgs)
                    {
                        photo.Source = PlaceholderHelper.GetLottieFrame(file.Local.Path, 0, 48, 48);
                    }
                    else
                    {
                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                }
                else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                {
                    photo.Source = null;
                    ViewModel.ProtoService.DownloadFile(file.Id, 1);
                }
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(OnContainerContentChanging);
            }

            args.Handled = true;
        }
        private async void Grid_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            var content    = sender as Grid;
            var stickerSet = args.NewValue as StickerSetInfo;

            var title    = content.Children[1] as TextBlock;
            var subtitle = content.Children[2] as TextBlock;
            var photo    = content.Children[0] as Image;

            if (stickerSet == null)
            {
                title.Text    = Strings.Resources.ChooseStickerSetNotFound;
                subtitle.Text = Strings.Resources.ChooseStickerSetNotFoundInfo;
                photo.Source  = null;
                return;
            }

            title.Text    = stickerSet.Title;
            subtitle.Text = Locale.Declension("Stickers", stickerSet.Size);

            var cover = stickerSet.Thumbnail ?? stickerSet.Covers.FirstOrDefault()?.Thumbnail;

            if (cover == null)
            {
                return;
            }

            var file = cover.Photo;

            if (file.Local.IsDownloadingCompleted)
            {
                if (stickerSet.IsAnimated)
                {
                    var bitmap = PlaceholderHelper.GetLottieFrame(file.Local.Path, 0, 48, 48);
                    if (bitmap == null)
                    {
                        bitmap = await PlaceholderHelper.GetWebpAsync(file.Local.Path);
                    }

                    photo.Source = bitmap;
                }
                else
                {
                    photo.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path);
                }
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                photo.Source = null;
                ViewModel.ProtoService.DownloadFile(file.Id, 1);
            }
        }
예제 #4
0
        public void UpdateFile(File file)
        {
            if (_stickers.TryGetValue(file.Id, out List <StickerViewModel> items) && items.Count > 0)
            {
                foreach (var item in items)
                {
                    item.UpdateFile(file);

                    if (item.Thumbnail?.File.Id == file.Id)
                    {
                        var container = Stickers.ContainerFromItem(item) as SelectorItem;
                        if (container == null)
                        {
                            continue;
                        }

                        var content = container.ContentTemplateRoot as Grid;
                        var photo   = content.Children[0] as Image;

                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                    else if (item.StickerValue.Id == file.Id)
                    {
                        _handler.ThrottleVisibleItems();
                    }
                }
            }

            if (_stickerSets.TryGetValue(file.Id, out List <StickerSetViewModel> sets) && sets.Count > 0)
            {
                foreach (var item in sets)
                {
                    var cover = item.Thumbnail ?? item.Covers.FirstOrDefault()?.Thumbnail;
                    if (cover == null)
                    {
                        continue;
                    }

                    cover.UpdateFile(file);

                    var container = Toolbar.ContainerFromItem(item) as SelectorItem;
                    if (container == null)
                    {
                        continue;
                    }

                    var content = container.ContentTemplateRoot as Grid;
                    var photo   = content?.Children[0] as Image;

                    if (content == null)
                    {
                        continue;
                    }

                    if (item.IsAnimated)
                    {
                        photo.Source = PlaceholderHelper.GetLottieFrame(file.Local.Path, 0, 36, 36);
                    }
                    else
                    {
                        photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path);
                    }
                }
            }

            _zoomer.UpdateFile(file);
        }