コード例 #1
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var wallpaper = args.Item as Background;
            var root      = args.ItemContainer.ContentTemplateRoot as Grid;

            var preview = root.Children[0] as ChatBackgroundPreview;
            var content = root.Children[1] as Image;
            var check   = root.Children[2];

            check.Visibility = wallpaper == ViewModel.SelectedItem ? Visibility.Visible : Visibility.Collapsed;

            if (wallpaper.Document != null)
            {
                if (wallpaper.Type is BackgroundTypePattern pattern)
                {
                    content.Opacity = pattern.Intensity / 100d;
                    preview.Fill    = pattern.Fill;
                }
                else
                {
                    content.Opacity = 1;
                    preview.Fill    = null;
                }

                var small = wallpaper.Document.Thumbnail;
                if (small == null)
                {
                    return;
                }

                var file = small.File;
                if (file.Local.IsDownloadingCompleted)
                {
                    content.Source = UriEx.ToBitmap(file.Local.Path, wallpaper.Document.Thumbnail.Width, wallpaper.Document.Thumbnail.Height);
                }
                else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                {
                    content.Source = null;

                    _backgrounds[file.Id].Add(wallpaper);
                    ViewModel.ProtoService.DownloadFile(file.Id, 1);
                }
            }
            else if (wallpaper.Type is BackgroundTypeFill fill)
            {
                content.Opacity = 1;
                preview.Fill    = fill.Fill;
                content.Source  = null;
            }
        }
コード例 #2
0
        public void UpdateFile(MessageViewModel message, File file)
        {
            var text = message.Content as MessageText;

            if (text == null || !_templateApplied)
            {
                return;
            }

            var webPage = text.WebPage;

            if (webPage == null)
            {
                return;
            }

            var small = webPage.Photo?.GetSmall();

            if (small == null)
            {
                return;
            }

            if (small.Photo.Id != file.Id)
            {
                return;
            }

            if (file.Local.IsDownloadingCompleted)
            {
                double ratioX = (double)48 / small.Width;
                double ratioY = (double)48 / small.Height;
                double ratio  = Math.Max(ratioX, ratioY);

                var width  = (int)(small.Width * ratio);
                var height = (int)(small.Height * ratio);

                Texture.Source = UriEx.ToBitmap(file.Local.Path, width, height);
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                message.ProtoService.DownloadFile(file.Id, 1);
            }
        }
コード例 #3
0
        public void Handle(UpdateFile update)
        {
            var file = update.File;

            if (!file.Local.IsDownloadingCompleted)
            {
                return;
            }

            if (_backgrounds.TryGetValue(update.File.Id, out List <Background> items))
            {
                this.BeginOnUIThread(() =>
                {
                    foreach (var item in items)
                    {
                        item.UpdateFile(update.File);

                        var small = item.Document?.Thumbnail;
                        if (small == null)
                        {
                            continue;
                        }

                        var container = List.ContainerFromItem(item) as SelectorItem;
                        var root      = container?.ContentTemplateRoot as Grid;
                        var content   = root?.Children[1] as Image;

                        if (content == null)
                        {
                            continue;
                        }

                        content.Source = UriEx.ToBitmap(file.Local.Path, small.Width, small.Height);
                    }
                });
            }
        }