private void OnContainerContentChanged(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var element = args.ItemContainer.ContentTemplateRoot as FrameworkElement; var reaction = args.Item as SupergroupReactionOption; var player = element.FindName("Player") as LottieView; if (player != null) { player.FrameSize = new Size(48, 48); var file = reaction.Reaction.CenterAnimation.StickerValue; if (file.Local.IsFileExisting()) { player.Source = UriEx.ToLocal(file.Local.Path); } else { player.Source = null; UpdateManager.Subscribe(player, ViewModel.ProtoService, file, UpdateFile, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 16); } } } }
private void UpdateThumbnail(object target, File file) { if (target is AnimationView view) { view.Thumbnail = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } }
private void UpdateThumbnail(MessageWithOwner message, Thumbnail thumbnail, File file) { if (file.Local.IsFileExisting()) { double ratioX = (double)48 / thumbnail.Width; double ratioY = (double)48 / thumbnail.Height; double ratio = Math.Max(ratioX, ratioY); var width = (int)(thumbnail.Width * ratio); var height = (int)(thumbnail.Height * ratio); Texture.Background = new ImageBrush { ImageSource = new BitmapImage(UriEx.ToLocal(file.Local.Path)) { DecodePixelWidth = width, DecodePixelHeight = height }, Stretch = Stretch.UniformToFill, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center }; Button.Style = BootStrapper.Current.Resources["ImmersiveFileButtonStyle"] as Style; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); Texture.Background = null; Button.Style = BootStrapper.Current.Resources["InlineFileButtonStyle"] as Style; } }
private static async Task <ImageSource> GetLottieFrame(string path, int frame, int width, int height) { var dpi = WindowContext.Current.RasterizationScale; width = (int)(width * dpi); height = (int)(height * dpi); var cache = $"{path}.{width}x{height}.png"; if (System.IO.File.Exists(cache)) { return(new BitmapImage(UriEx.ToLocal(cache))); } await Task.Run(() => { var frameSize = new Windows.Graphics.SizeInt32 { Width = width, Height = height }; var animation = LottieAnimation.LoadFromFile(path, frameSize, false, null); if (animation != null) { animation.RenderSync(cache, frame); animation.Dispose(); } }); return(new BitmapImage(UriEx.ToLocal(cache))); }
private void UpdateFile(object target, File file) { if (target is LottieView lottie) { lottie.Source = UriEx.ToLocal(file.Local.Path); } }
private void UpdateThumbnail(MessageViewModel message, Video video, File file, bool download) { var thumbnail = video.Thumbnail; var minithumbnail = video.Minithumbnail; if (thumbnail != null && thumbnail.Format is ThumbnailFormatJpeg) { if (file.Local.IsFileExisting()) { Texture.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } else if (download) { if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { if (minithumbnail != null) { Texture.Source = PlaceholderHelper.GetBlurred(minithumbnail.Data); } message.ProtoService.DownloadFile(file.Id, 1); } UpdateManager.Subscribe(this, message, file, ref _thumbnailToken, UpdateThumbnail, true); } } else if (minithumbnail != null) { Texture.Source = PlaceholderHelper.GetBlurred(minithumbnail.Data); } else { Texture.Source = null; } }
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(); } }
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 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); } }
private void UpdateFile(object target, File file) { if (target is LottieView player && player.IsLoaded) { player.Source = UriEx.ToLocal(file.Local.Path); } }
public void UpdateFile(MessageViewModel message, File file) { var sticker = GetContent(message); if (sticker == null || !_templateApplied) { return; } if (sticker.StickerValue.Id != file.Id) { return; } if (file.Local.IsDownloadingCompleted) { Player.IsLoopingEnabled = message.Content is MessageSticker && SettingsService.Current.Stickers.IsLoopingEnabled; Player.Source = UriEx.ToLocal(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { Player.Source = null; message.ProtoService.DownloadFile(file.Id, 1); } }
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; }
private void Play(Grid parent, GalleryContent item, File file) { if (_unloaded) { return; } try { if (!file.Local.IsDownloadingCompleted && !SettingsService.Current.IsStreamingEnabled) { return; } if (_surface != null && _mediaPlayerElement != null) { _surface.Children.Remove(_mediaPlayerElement); _surface = null; } if (_mediaPlayer == null) { _mediaPlayer = Task.Run(() => new MediaPlayer()).Result; _mediaPlayer.VolumeChanged += OnVolumeChanged; _mediaPlayer.SourceChanged += OnSourceChanged; _mediaPlayer.MediaOpened += OnMediaOpened; _mediaPlayer.PlaybackSession.PlaybackStateChanged += OnPlaybackStateChanged; _mediaPlayerElement.SetMediaPlayer(_mediaPlayer); } var dpi = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f; _mediaPlayer.SetSurfaceSize(new Size(parent.ActualWidth * dpi, parent.ActualHeight * dpi)); _surface = parent; _surface.Children.Add(_mediaPlayerElement); //Transport.DownloadMaximum = file.Size; //Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; var streamable = SettingsService.Current.IsStreamingEnabled && item.IsStreamable /*&& !file.Local.IsDownloadingCompleted*/; if (streamable) { _fileStream = new RemoteFileStream(item.ProtoService, file, item.Duration); _mediaPlayer.Source = MediaSource.CreateFromStream(_fileStream, item.MimeType); //Transport.DownloadMaximum = file.Size; //Transport.DownloadValue = file.Local.DownloadOffset + file.Local.DownloadedPrefixSize; } else { _mediaPlayer.Source = MediaSource.CreateFromUri(UriEx.ToLocal(file.Local.Path)); } _mediaPlayer.IsLoopingEnabled = item.IsLoop; _mediaPlayer.Play(); } catch { } }
public void PlayPremium(MessageViewModel message, Sticker sticker) { if (Interactions == null) { InteractionsPopup = GetTemplateChild(nameof(InteractionsPopup)) as Popup; Interactions = GetTemplateChild(nameof(Interactions)) as Grid; } var file = sticker.PremiumAnimation; if (file.Local.IsFileExisting() && Interactions.Children.Count < 1) { var dispatcher = DispatcherQueue.GetForCurrentThread(); var player = new LottieView(); player.Width = 270; player.Height = 270; player.IsFlipped = !message.IsOutgoing; player.IsLoopingEnabled = false; player.IsHitTestVisible = false; player.FrameSize = new Size(270 * 2, 270 * 2); player.Source = UriEx.ToLocal(file.Local.Path); player.PositionChanged += (s, args) => { if (args == 1) { dispatcher.TryEnqueue(() => { Interactions.Children.Remove(player); InteractionsPopup.IsOpen = false; }); } }; var left = 75; var right = 15; var top = 45; var bottom = 45; if (message.IsOutgoing) { player.Margin = new Thickness(-left, -top, -right, -bottom); } else { player.Margin = new Thickness(-right, -top, -left, -bottom); } Interactions.Children.Add(player); InteractionsPopup.IsOpen = true; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.Delegate.DownloadFile(message, file); UpdateManager.Subscribe(this, message, file, ref _interactionToken, UpdateFile, true); } }
private void UpdateThumbnail(object target, File file) { if (target is Image photo) { photo.Source = new BitmapImage { UriSource = UriEx.ToLocal(file.Local.Path), DecodePixelWidth = 40, DecodePixelHeight = 40 }; } }
private void UpdateThumbnail(MessageViewModel message, File file) { if (file.Local.IsFileExisting()) { Texture.Source = new BitmapImage(UriEx.ToLocal(file.Local.Path)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Border; var animation = args.Item as Animation; if (args.InRecycleQueue) { if (content.Child is AnimationView recycle) { recycle.Source = null; } return; } var view = content.Child as AnimationView; var file = animation.AnimationValue; if (file == null) { return; } if (file.Local.IsDownloadingCompleted) { view.Source = new LocalVideoSource(file); view.Thumbnail = null; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { view.Source = null; DownloadFile(file.Id, animation); var thumbnail = animation.Thumbnail?.File; if (thumbnail != null) { if (thumbnail.Local.IsDownloadingCompleted) { view.Thumbnail = new BitmapImage(UriEx.ToLocal(thumbnail.Local.Path)); } else if (thumbnail.Local.CanBeDownloaded && !thumbnail.Local.IsDownloadingActive) { view.Thumbnail = null; DownloadFile(thumbnail.Id, animation); } } } }
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 UpdateFile(object target, File file) { if (target is Grid content) { if (content.Children[0] is LottieView stickerView) { stickerView.Source = UriEx.ToLocal(file.Local.Path); } else if (content.Children[0] is AnimationView animationView) { animationView.Source = new LocalVideoSource(file); } } _handler.ThrottleVisibleItems(); }
public void UpdateSticker() { var index = _index + 1; if (index >= _stickers.Count) { index = 0; } var sticker = _stickers[index]; Animation1.Source = UriEx.ToLocal(sticker.StickerValue.Local.Path); PremiumAnimation1.Source = UriEx.ToLocal(sticker.PremiumAnimation.Local.Path); _index = index; PreloadSticker(); }
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)); } }
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 void Reaction_Click(object sender, RoutedEventArgs e) { if (sender is HyperlinkButton button && button.Tag is Reaction reaction && button.Content is LottieView centerView) { var center = reaction.CenterAnimation.StickerValue; var around = reaction.AroundAnimation.StickerValue; if (center.Local.IsFileExisting() && around.Local.IsFileExisting()) { var transform = button.TransformToVisual(this); var point = transform.TransformPoint(new Windows.Foundation.Point()); var dispatcher = DispatcherQueue.GetForCurrentThread(); var aroundView = new LottieView(); aroundView.Width = 64 * 3; aroundView.Height = 64 * 3; aroundView.IsLoopingEnabled = false; aroundView.FrameSize = new Size(64 * 3, 64 * 3); aroundView.DecodeFrameType = DecodePixelType.Logical; aroundView.Source = UriEx.ToLocal(around.Local.Path); aroundView.Margin = new Thickness(point.X - 64, point.Y - 64, 0, 0); aroundView.HorizontalAlignment = HorizontalAlignment.Left; aroundView.VerticalAlignment = VerticalAlignment.Top; aroundView.PositionChanged += (s, args) => { if (args == 1) { dispatcher.TryEnqueue(() => Overlay.Children.Remove(aroundView)); } }; centerView.Play(); Overlay.Children.Add(aroundView); } } }
private void UpdateFile(MessageViewModel message, File file) { var sticker = GetContent(message, out _); if (sticker == null || !_templateApplied) { return; } if (sticker.StickerValue.Id != file.Id) { if (message.Interaction?.StickerValue.Id == file.Id && file.Local.IsFileExisting()) { PlayInteraction(message, message.Interaction); } else if (sticker.PremiumAnimation?.Id == file.Id && file.Local.IsFileExisting()) { PlayPremium(message, sticker); } return; } if (file.Local.IsFileExisting()) { Player.IsLoopingEnabled = message.Content is MessageSticker && SettingsService.Current.Stickers.IsLoopingEnabled; Player.Source = UriEx.ToLocal(file.Local.Path); message.Delegate.ViewVisibleMessages(false); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { Player.Source = null; message.ProtoService.DownloadFile(file.Id, 1); } }
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; }
public void UpdateFeature(IProtoService protoService) { var reactions = protoService.Reactions.Values.Where(x => x.IsPremium).ToList(); var cols = 4; var rows = (int)Math.Ceiling((double)reactions.Count / cols); Presenter.ColumnDefinitions.Clear(); Presenter.RowDefinitions.Clear(); for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { var i = x + y * cols; var button = Presenter.Children[i] as HyperlinkButton; if (button == null) { if (i < reactions.Count) { var item = reactions[i]; var view2 = new LottieView(); view2.AutoPlay = false; view2.IsLoopingEnabled = false; view2.FrameSize = new Size(64, 64); view2.DecodeFrameType = DecodePixelType.Logical; view2.Width = 64; view2.Height = 64; protoService.DownloadFile(item.AroundAnimation.StickerValue.Id, 32); var file = item.CenterAnimation.StickerValue; if (file.Local.IsFileExisting()) { view2.Source = UriEx.ToLocal(file.Local.Path); } else { view2.Source = null; UpdateManager.Subscribe(view2, protoService, file, /*UpdateReaction*/ UpdateFile, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService.DownloadFile(file.Id, 32); } } button = new HyperlinkButton { Tag = reactions[i], Content = view2, Style = BootStrapper.Current.Resources["EmptyHyperlinkButtonStyle"] as Style }; button.Click += Reaction_Click; Presenter.Children.Add(button); } else { continue; } } Grid.SetColumn(button, x); Grid.SetRow(button, y); if (y == 0) { Presenter.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); } } Presenter.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); } }
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); } } } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var radio = args.ItemContainer.ContentTemplateRoot as RadioButton; var content = radio.Content as Grid; var emojiPack = args.Item as EmojiSet; radio.Click -= EmojiSet_Click; radio.Click += EmojiSet_Click; radio.IsChecked = SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id; if (SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id) { _selectedSet = emojiPack; } radio.Tag = emojiPack; content.Tag = emojiPack; if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = emojiPack.Title; } else if (args.Phase == 1) { var subtitle = content.Children[2] as TextBlock; var file = emojiPack.Document; var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { subtitle.Text = string.Format("{0} {1} / {2}", "Downloading", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { subtitle.Text = string.Format("{0} {1}", Strings.Resources.AccActionDownload, FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else { if (SettingsService.Current.Appearance.EmojiSet.Id == emojiPack.Id) { subtitle.Text = "Current Set"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlForegroundAccentBrush"] as Brush; } else { subtitle.Text = emojiPack.IsDefault ? Strings.Resources.Default : "Downloaded"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } } } else if (args.Phase == 2) { var photo = content.Children[0] as Image; var file = emojiPack.Thumbnail; if (file != null && file.Local.IsDownloadingCompleted) { photo.Source = new BitmapImage { UriSource = UriEx.ToLocal(file.Local.Path), DecodePixelWidth = 40, DecodePixelHeight = 40 }; } else if (file != null && file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { photo.Source = null; _protoService.DownloadFile(file.Id, 1); } } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
public async void Handle(UpdateFile update) { var emojiSet = _collection.FirstOrDefault(x => x.UpdateFile(update.File)); if (emojiSet == null) { return; } var file = update.File; var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("emoji", CreationCollisionOption.OpenIfExists); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (file.Id == _selectedSet?.Document.Id && !file.Local.IsDownloadingCompleted) { IsPrimaryButtonEnabled = false; } else { IsPrimaryButtonEnabled = true; } var container = List.ContainerFromItem(emojiSet) as SelectorItem; if (container == null) { return; } var radio = container.ContentTemplateRoot as RadioButton; if (radio == null) { return; } var content = radio.Content as Grid; if (content == null) { return; } radio.IsChecked = (_selectedSet?.Id ?? SettingsService.Current.Appearance.EmojiSet.Id) == emojiSet.Id; if (file.Id == emojiSet.Document.Id) { var subtitle = content.Children[2] as TextBlock; var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { subtitle.Text = string.Format("{0} {1} / {2}", "Downloading", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { subtitle.Text = string.Format("{0} {1}", Strings.Resources.AccActionDownload, FileSizeConverter.Convert(size)); subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } else { if (SettingsService.Current.Appearance.EmojiSet.Id == emojiSet.Id) { subtitle.Text = "Current Set"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlForegroundAccentBrush"] as Brush; } else { subtitle.Text = emojiSet.IsDefault ? Strings.Resources.Default : "Downloaded"; subtitle.Foreground = BootStrapper.Current.Resources["SystemControlDisabledChromeDisabledLowBrush"] as Brush; } } } if (file.Id == emojiSet.Thumbnail.Id) { var photo = content.Children[0] as Image; if (file.Local.IsDownloadingCompleted) { photo.Source = new BitmapImage { UriSource = UriEx.ToLocal(file.Local.Path), DecodePixelWidth = 40, DecodePixelHeight = 40 }; } else { photo.Source = null; } } }); }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Border; var animation = args.Item as Animation; if (args.InRecycleQueue) { if (content.Child is AnimationView recycle) { recycle.Source = null; } return; } var view = content.Child as AnimationView; var file = animation.AnimationValue; if (file == null) { return; } if (file.Local.IsFileExisting()) { view.Source = new LocalVideoSource(file); view.Thumbnail = null; } else { view.Source = null; UpdateManager.Subscribe(content, ViewModel.ProtoService, file, UpdateFile, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(file.Id, 1); } var thumbnail = animation.Thumbnail?.File; if (thumbnail != null) { if (thumbnail.Local.IsFileExisting()) { view.Thumbnail = new BitmapImage(UriEx.ToLocal(thumbnail.Local.Path)); } else { view.Thumbnail = null; UpdateManager.Subscribe(view, ViewModel.ProtoService, thumbnail, UpdateThumbnail, true); if (thumbnail.Local.CanBeDownloaded && !thumbnail.Local.IsDownloadingActive) { ViewModel.ProtoService.DownloadFile(thumbnail.Id, 1); } } } } }