private void UpdateFile(ViewModels.Drawers.StickerViewModel sticker, File file, ref Image thumbnail, ref ImageView texture, ref Border container) { if (file.Local.IsDownloadingCompleted) { if (sticker.IsAnimated) { thumbnail.Opacity = 0; texture.Source = null; container.Child = new LottieView { Source = new Uri("file:///" + file.Local.Path) }; } else { thumbnail.Opacity = 0; texture.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); container.Child = new Border(); } } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { thumbnail.Opacity = 1; texture.Source = null; container.Child = new Border(); sticker.ProtoService.DownloadFile(file.Id, 32); } }
public void UpdateFile(File file) { foreach (Sticker sticker in List.Items) { if (sticker.UpdateFile(file) && file.Local.IsDownloadingCompleted) { if (file.Id == sticker.Thumbnail?.File.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 = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Id == sticker.StickerValue.Id) { _throttler.Stop(); _throttler.Start(); } } } }
public void UpdateFile(MessageViewModel message, File file) { var sticker = GetContent(message.Content); if (sticker == null) { return; } if (sticker.Thumbnail != null && sticker.Thumbnail.File.Id == file.Id) { UpdateThumbnail(message, sticker.Thumbnail, file); return; } else if (sticker.StickerValue.Id != file.Id) { return; } if (file.Local.IsDownloadingCompleted) { Texture.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
public async Task <InputMessageFactory> CreateDocumentAsync(StorageFile file, bool asFile) { var generated = await file.ToGeneratedAsync(); var thumbnail = new InputThumbnail(await file.ToGeneratedAsync(ConversionType.DocumentThumbnail), 0, 0); if (!asFile && file.FileType.Equals(".webp", StringComparison.OrdinalIgnoreCase)) { try { //var buffer = await FileIO.ReadBufferAsync(file); //var webp = WebPImage.DecodeFromBuffer(buffer); // This isn't supposed to work. var webp = PlaceholderHelper.GetWebPFrame(file.Path) as Windows.UI.Xaml.Media.Imaging.BitmapImage; var width = webp.PixelWidth; var height = webp.PixelHeight; return(new InputMessageFactory { InputFile = generated, Type = new FileTypeSticker(), Delegate = (inputFile, caption) => new InputMessageSticker(inputFile, null, width, height, string.Empty) }); } catch { // Not really a sticker, go on sending as a file } } else if (!asFile && file.FileType.Equals(".tgs", StringComparison.OrdinalIgnoreCase)) { // TODO } else if (!asFile && file.ContentType.StartsWith("audio/", StringComparison.OrdinalIgnoreCase)) { var props = await file.Properties.GetMusicPropertiesAsync(); var duration = (int)props.Duration.TotalSeconds; var title = props.Title; var performer = string.IsNullOrEmpty(props.AlbumArtist) ? props.Artist : props.AlbumArtist; return(new InputMessageFactory { InputFile = generated, Type = new FileTypeAudio(), Delegate = (inputFile, caption) => new InputMessageAudio(inputFile, thumbnail, duration, title, performer, caption) }); } return(new InputMessageFactory { InputFile = generated, Type = new FileTypeDocument(), Delegate = (inputFile, caption) => new InputMessageDocument(inputFile, thumbnail, true, caption) }); }
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); } } }
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 void UpdateThumbnail(MessageViewModel message, File file) { if (file.Local.IsDownloadingCompleted) { Player.Thumbnail = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
private void UpdateThumbnail(File file, ref Image thumbnail) { if (file.Local.IsDownloadingCompleted) { thumbnail.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { thumbnail.Source = null; Logs.Logger.Warning(Logs.Target.API, "Thumbnail not downloaded yet.", "MenuFlyoutMediaItem"); // If ever called - implement download & update here } }
private void UpdateThumbnail(MessageViewModel message, Thumbnail thumbnail, File file) { if (file.Local.IsDownloadingCompleted && thumbnail.Format is ThumbnailFormatWebp) { Background = new ImageBrush { ImageSource = PlaceholderHelper.GetWebPFrame(file.Local.Path) }; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
public void UpdateFile(File file) { if (!file.Local.IsDownloadingCompleted) { return; } if (_thumbnails.TryGetValue(file.Id, out List <InlineQueryResult> items) && items.Count > 0) { foreach (var result in items) { result.UpdateFile(file); var index = ViewModel.InlineBotResults?.IndexOf(result) ?? -1; if (index < 0) { continue; } var button = Repeater.TryGetElement(index) as Button; if (button == null) { continue; } var content = button.Content as Grid; if (content.Children[0] is Image image) { if (result is InlineQueryResultPhoto or InlineQueryResultVideo) { image.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } else if (result is InlineQueryResultSticker) { image.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } } else if (content.Children[0] is AnimationView animationView) { animationView.Thumbnail = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } else if (content.Children[0] is Grid presenter) { //var presenter = content.Children[0] as Grid; var thumb = presenter.Children[0] as Image; thumb.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } }
private 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.Drawers.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.File; if (file.Local.IsDownloadingCompleted) { 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 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.File; if (file.Local.IsDownloadingCompleted) { if (stickerSet.IsAnimated) { 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); } }
private void UpdateThumbnail(object target, File file) { if (target is Image image) { if (image.Tag is InlineQueryResultSticker) { image.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else { image.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } } else if (target is AnimationView animationView) { animationView.Thumbnail = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } }
private 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.File; if (file.Local.IsDownloadingCompleted) { content.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } } args.Handled = true; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Grid; var photo = content.Children[0] as Image; if (args.InRecycleQueue) { while (content.Children.Count > 1) { content.Children.RemoveAt(1); } photo.Opacity = 1; photo.Source = null; return; } var sticker = args.Item as StickerViewModel; args.ItemContainer.Tag = args.Item; args.ItemContainer.Content = args.Item; content.Tag = args.Item; if (sticker == null || sticker.Thumbnail == null) { while (content.Children.Count > 1) { content.Children[0].Opacity = 1; content.Children.RemoveAt(1); } photo.Source = null; return; } if (args.Phase < 2) { while (content.Children.Count > 1) { content.Children.RemoveAt(1); } photo.Opacity = 1; photo.Source = null; args.RegisterUpdateCallback(OnContainerContentChanging); var file = sticker.Thumbnail.File; if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && !file.Local.IsDownloadingCompleted) { DownloadFile(_stickers, file.Id, sticker); } } else if (args.Phase == 2) { //Debug.WriteLine("Loading sticker " + sticker.StickerValue.Id + " for sticker set id " + sticker.SetId); var file = sticker.Thumbnail.File; if (file.Local.IsDownloadingCompleted) { photo.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { DownloadFile(_stickers, file.Id, sticker); } } args.Handled = true; }
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); }
private void OnElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { var button = args.Element as Button; var result = button.DataContext as InlineQueryResult; var content = button.Content as Grid; if (content.Children[0] is Image image) { if (result is InlineQueryResultAnimation || result is InlineQueryResultPhoto || result is InlineQueryResultVideo) { File file = null; if (result is InlineQueryResultAnimation animation) { file = animation.Animation.Thumbnail?.File; } else if (result is InlineQueryResultPhoto photo) { file = photo.Photo.GetSmall().Photo; } else if (result is InlineQueryResultVideo video) { file = video.Video.Thumbnail?.File; } if (file == null) { return; } if (file.Local.IsDownloadingCompleted) { image.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { image.Source = null; DownloadFile(_thumbnails, file.Id, result); } } else if (result is InlineQueryResultSticker sticker) { var file = sticker.Sticker.Thumbnail.File; if (file == null) { return; } if (file.Local.IsDownloadingCompleted) { image.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { image.Source = null; DownloadFile(_thumbnails, file.Id, result); } } } else if (content.Children[0] is Grid presenter) { //var presenter = content.Children[0] as Grid; var thumb = presenter.Children[0] as Image; var title = content.Children[1] as TextBlock; var description = content.Children[2] as TextBlock; File file = null; Uri uri = null; if (result is InlineQueryResultArticle article) { file = article.Thumbnail?.File; title.Text = article.Title; description.Text = article.Description; } else if (result is InlineQueryResultAudio audio) { file = audio.Audio.AlbumCoverThumbnail?.File; title.Text = audio.Audio.GetTitle(); description.Text = audio.Audio.GetDuration(); } else if (result is InlineQueryResultContact contact) { file = contact.Thumbnail?.File; title.Text = contact.Contact.GetFullName(); description.Text = PhoneNumber.Format(contact.Contact.PhoneNumber); } else if (result is InlineQueryResultDocument document) { file = document.Document.Thumbnail?.File; title.Text = document.Title; if (string.IsNullOrEmpty(document.Description)) { description.Text = FileSizeConverter.Convert(document.Document.DocumentValue.Size); } else { description.Text = document.Description; } } else if (result is InlineQueryResultGame game) { file = game.Game.Animation?.Thumbnail?.File ?? game.Game.Photo.GetSmall().Photo; title.Text = game.Game.Title; description.Text = game.Game.Description; } else if (result is InlineQueryResultLocation location) { var latitude = location.Location.Latitude.ToString(CultureInfo.InvariantCulture); var longitude = location.Location.Longitude.ToString(CultureInfo.InvariantCulture); uri = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{0},{1}/{2}?mapSize={3}&key=FgqXCsfOQmAn9NRf4YJ2~61a_LaBcS6soQpuLCjgo3g~Ah_T2wZTc8WqNe9a_yzjeoa5X00x4VJeeKH48wAO1zWJMtWg6qN-u4Zn9cmrOPcL", latitude, longitude, 15, "96,96")); file = location.Thumbnail?.File; title.Text = location.Title; description.Text = $"{location.Location.Latitude};{location.Location.Longitude}"; } else if (result is InlineQueryResultPhoto photo) { file = photo.Photo.GetSmall().Photo; title.Text = photo.Title; description.Text = photo.Description; } else if (result is InlineQueryResultVenue venue) { var latitude = venue.Venue.Location.Latitude.ToString(CultureInfo.InvariantCulture); var longitude = venue.Venue.Location.Longitude.ToString(CultureInfo.InvariantCulture); uri = new Uri(string.Format("https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{0},{1}/{2}?mapSize={3}&key=FgqXCsfOQmAn9NRf4YJ2~61a_LaBcS6soQpuLCjgo3g~Ah_T2wZTc8WqNe9a_yzjeoa5X00x4VJeeKH48wAO1zWJMtWg6qN-u4Zn9cmrOPcL", latitude, longitude, 15, "96,96")); file = venue.Thumbnail?.File; title.Text = venue.Venue.Title; description.Text = venue.Venue.Address; } else if (result is InlineQueryResultVideo video) { file = video.Video.Thumbnail?.File; title.Text = video.Title; description.Text = video.Description; } else if (result is InlineQueryResultVoiceNote voiceNote) { title.Text = voiceNote.Title; description.Text = voiceNote.VoiceNote.GetDuration(); } if (file != null) { if (file.Local.IsDownloadingCompleted) { thumb.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { thumb.Source = null; DownloadFile(_thumbnails, file.Id, result); } } else if (uri != null) { thumb.Source = new BitmapImage(uri); } else { thumb.Source = PlaceholderHelper.GetNameForChat(title.Text, 96, title.Text.GetHashCode()); } } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Grid; var result = args.Item as InlineQueryResult; if (content.Children[0] is Image image) { image.Tag = args.Item; if (result is InlineQueryResultPhoto or InlineQueryResultVideo) { File file = null; if (result is InlineQueryResultPhoto photo) { file = photo.Photo.GetSmall().Photo; } else if (result is InlineQueryResultVideo video) { file = video.Video.Thumbnail?.File; } if (file == null) { return; } if (file.Local.IsFileExisting()) { image.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } else { image.Source = null; UpdateManager.Subscribe(image, ViewModel.ProtoService, file, UpdateThumbnail, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } } } else if (result is InlineQueryResultSticker sticker) { var file = sticker.Sticker.StickerValue; if (file == null) { return; } if (file.Local.IsFileExisting()) { image.Source = PlaceholderHelper.GetWebPFrame(file.Local.Path); } else { image.Source = null; UpdateManager.Subscribe(image, ViewModel.ProtoService, file, UpdateThumbnail, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } } } }