public async void UpdateFile(MessageViewModel message, File file) { var sticker = GetContent(message.Content); if (sticker == null) { return; } if (sticker.Thumbnail != null && sticker.Thumbnail.Photo.Id == file.Id) { UpdateThumbnail(message, file); return; } else if (sticker.StickerValue.Id != file.Id) { return; } if (file.Local.IsDownloadingCompleted) { Texture.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
public async void UpdateFile(File file) { if (!file.Local.IsDownloadingCompleted) { return; } if (_stickers.TryGetValue(file.Id, out List <ViewModels.Dialogs.StickerViewModel> items) && items.Count > 0) { foreach (var item in items) { item.UpdateFile(file); var container = Stickers.ContainerFromItem(item) as SelectorItem; if (container == null) { continue; } var content = container.ContentTemplateRoot as Image; content.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path); } } foreach (MosaicMediaRow line in GifsView.Items) { var any = false; foreach (var item in line) { if (item.Item is Animation animation && animation.UpdateFile(file)) { any = 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); } }
private async void UpdateThumbnail(MessageViewModel message, File file) { if (file.Local.IsDownloadingCompleted) { Background = new ImageBrush { ImageSource = await PlaceholderHelper.GetWebpAsync(file.Local.Path) }; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
private async void List_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Image; if (args.InRecycleQueue) { content.Source = null; return; } var sticker = args.Item as StickerViewModel; if (sticker == null || sticker.Thumbnail == null) { content.Source = null; return; } args.ItemContainer.Tag = args.Item; content.Tag = args.Item; //if (args.Phase < 2) //{ // content.Source = null; // args.RegisterUpdateCallback(Stickers_ContainerContentChanging); //} //else if (args.Phase == 0) { Debug.WriteLine("Loading sticker " + sticker.StickerValue.Id + " for sticker set id " + sticker.SetId); var file = sticker.Thumbnail.Photo; if (file.Local.IsDownloadingCompleted) { content.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { //DownloadFile(file.Id, sticker); } } else { throw new System.Exception("We should be in phase 0, but we are not."); } args.Handled = true; }
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; content.Tag = args.ItemContainer.Tag = new ViewModels.Dialogs.StickerViewModel(ViewModel.ProtoService, ViewModel.Aggregator, sticker); if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = sticker.Emoji; } else if (args.Phase == 1) { } else if (args.Phase == 2) { var photo = content.Children[0] as Image; if (sticker == null || sticker.Thumbnail == null) { return; } var file = sticker.Thumbnail.Photo; if (file.Local.IsDownloadingCompleted) { 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); } } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
public async void UpdateFile(File file) { foreach (Sticker sticker in List.Items) { if (sticker.UpdateFile(file) && file.Id == sticker.Thumbnail?.Photo.Id) { var container = List.ContainerFromItem(sticker) as SelectorItem; if (container == null) { continue; } var content = container.ContentTemplateRoot as Grid; if (content == null) { continue; } var photo = content.Children[0] as Image; photo.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path); } } }
private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Image; var sticker = args.Item as Sticker; if (sticker == null || sticker.Thumbnail == null) { content.Source = null; return; } if (args.Phase < 2) { content.Source = null; args.RegisterUpdateCallback(OnContainerContentChanging); } else { var file = sticker.Thumbnail.Photo; if (file.Local.IsDownloadingCompleted) { content.Source = await PlaceholderHelper.GetWebpAsync(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } } args.Handled = true; }
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; 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.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); } } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }