Пример #1
0
        public async void UpdateFile(MessageViewModel message, File file)
        {
            var sticker = GetContent(message.Content);

            if (sticker == null)
            {
                return;
            }

            if (sticker.StickerValue.Id != file.Id)
            {
                return;
            }

            if (file.Local.IsDownloadingCompleted)
            {
                Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path);

                ElementCompositionPreview.SetElementChildVisual(this, null);
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                message.ProtoService.DownloadFile(file.Id, 1);
            }
        }
        private async void UpdateFile(object target, File file)
        {
            var content = target as Grid;

            if (content == null)
            {
                return;
            }

            if (content.Children[0] is Image photo)
            {
                photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 48);

                ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
            }
            else if (content.Children[0] is LottieView lottie)
            {
                lottie.Source = UriEx.ToLocal(file.Local.Path);
                _handler.ThrottleVisibleItems();
            }
            else if (content.Children[0] is AnimationView animation)
            {
                animation.Source = new LocalVideoSource(file);
                _handler.ThrottleVisibleItems();
            }
        }
Пример #3
0
        private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;
            var sticker = args.Item as Sticker;

            var file = sticker.StickerValue;

            if (file.Local.IsDownloadingCompleted)
            {
                if (content.Children[0] is Border border && border.Child is Image photo)
                {
                    photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 60);

                    ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
                }
                else if (args.Phase == 0 && content.Children[0] is LottieView lottie)
                {
                    lottie.Source = UriEx.ToLocal(file.Local.Path);
                }
            }
Пример #4
0
        public async void UpdateFile(File file)
        {
            if (_stickers.TryGetValue(file.Id, out List <StickerViewModel> items) && items.Count > 0)
            {
                foreach (var sticker in items.ToImmutableHashSet())
                {
                    sticker.UpdateFile(file);

                    var container = List.ContainerFromItem(sticker) as SelectorItem;
                    if (container == null)
                    {
                        continue;
                    }

                    var content = container.ContentTemplateRoot as Border;
                    if (content == null)
                    {
                        continue;
                    }

                    if (content.Child is Border border && border.Child is Image photo)
                    {
                        photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 68);

                        ElementCompositionPreview.SetElementChildVisual(content.Child, null);
                    }
                    else if (content.Child is LottieView lottie)
                    {
                        lottie.Source = UriEx.ToLocal(file.Local.Path);
                        _handler.ThrottleVisibleItems();
                    }
                }
        private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

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

            var title = content.Children[1] as TextBlock;

            title.Text = stickerSet.Title;

            var subtitle = content.Children[2] as TextBlock;

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

            var file = stickerSet.GetThumbnail(out var outline, out _);

            if (file == null)
            {
                return;
            }

            if (file.Local.IsDownloadingCompleted)
            {
                if (content.Children[0] is Image photo)
                {
                    photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 48);

                    ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
                }
                else if (args.Phase == 0 && content.Children[0] is LottieView lottie)
                {
                    lottie.Source = UriEx.ToLocal(file.Local.Path);
                }
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                if (content.Children[0] is Image photo)
                {
                    photo.Source = null;
                }
                else if (args.Phase == 0 && content.Children[0] is LottieView lottie)
                {
                    lottie.Source = null;
                }

                CompositionPathParser.ParseThumbnail(outline, out ShapeVisual visual, false);
                ElementCompositionPreview.SetElementChildVisual(content.Children[0], visual);

                _filesMap[file.Id].Add(stickerSet);
                ViewModel.ProtoService.DownloadFile(file.Id, 1);
            }

            args.Handled = true;
        }
Пример #6
0
        private async void UpdateSticker(object target, File file)
        {
            var content = target as Grid;

            if (content == null)
            {
                return;
            }

            if (content.Children[0] is Border border && border.Child is Image photo)
            {
                photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 68);

                ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
            }
Пример #7
0
        private async void UpdateFile(MessageViewModel message, File file)
        {
            var sticker = GetContent(message);

            if (sticker == null)
            {
                return;
            }

            if (sticker.StickerValue.Id != file.Id)
            {
                return;
            }

            if (file.Local.IsFileExisting())
            {
                var size = 180 * WindowContext.Current.RasterizationScale;
                if (size > 512)
                {
                    size = 512;
                }

                Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, size);

                ElementCompositionPreview.SetElementChildVisual(this, null);

                UpdateManager.Unsubscribe(this, ref _fileToken);
            }
            else
            {
                Source = null;
                UpdateThumbnail(message, sticker);

                UpdateManager.Subscribe(this, message, sticker.StickerValue, ref _fileToken, UpdateFile, true);

                if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                {
                    message.ProtoService.DownloadFile(file.Id, 1);
                }
            }
        }
        public void Handle(UpdateFile update)
        {
            if (!update.File.Local.IsDownloadingCompleted)
            {
                return;
            }

            if (_filesMap.TryGetValue(update.File.Id, out List <StickerSetInfo> stickers))
            {
                this.BeginOnUIThread(async() =>
                {
                    foreach (var stickerSet in stickers.ToImmutableHashSet())
                    {
                        stickerSet.UpdateFile(update.File);

                        var container = List.ContainerFromItem(stickerSet) as SelectorItem;
                        if (container == null)
                        {
                            continue;
                        }

                        var content = container.ContentTemplateRoot as Grid;
                        if (content == null)
                        {
                            continue;
                        }

                        if (content.Children[0] is Image photo)
                        {
                            photo.Source = await PlaceholderHelper.GetWebPFrameAsync(update.File.Local.Path, 48);
                            ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
                        }
                        else if (content.Children[0] is LottieView lottie)
                        {
                            lottie.Source = UriEx.ToLocal(update.File.Local.Path);
                            _handler.ThrottleVisibleItems();
                        }
                    }
                });
            }
        }
        private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

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

            var title = content.Children[1] as TextBlock;

            title.Text = stickerSet.Title;

            var subtitle = content.Children[2] as TextBlock;

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

            var cover = stickerSet.GetThumbnail();

            if (cover == null)
            {
                return;
            }

            var file = cover.StickerValue;

            if (file.Local.IsFileExisting())
            {
                if (content.Children[0] is Image photo)
                {
                    photo.Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path, 48);

                    ElementCompositionPreview.SetElementChildVisual(content.Children[0], null);
                }
                else if (args.Phase == 0 && content.Children[0] is LottieView lottie)
                {
                    lottie.Source = UriEx.ToLocal(file.Local.Path);
                }
                else if (args.Phase == 0 && content.Children[0] is AnimationView animation)
                {
                    animation.Source = new LocalVideoSource(file);
                }
            }
            else
            {
                if (content.Children[0] is Image photo)
                {
                    photo.Source = null;
                }
                else if (args.Phase == 0 && content.Children[0] is LottieView lottie)
                {
                    lottie.Source = null;
                }
                else if (args.Phase == 0 && content.Children[0] is AnimationView animation)
                {
                    animation.Source = null;
                }

                CompositionPathParser.ParseThumbnail(cover, out ShapeVisual visual, false);
                ElementCompositionPreview.SetElementChildVisual(content.Children[0], visual);

                UpdateManager.Subscribe(content, ViewModel.ProtoService, file, UpdateFile, true);

                if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                {
                    ViewModel.ProtoService.DownloadFile(file.Id, 1);
                }
            }

            args.Handled = true;
        }