private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var wallpaper = args.Item as Wallpaper; if (wallpaper.Id == 1000001) { return; } else if (wallpaper.Sizes.Count > 0) { var small = wallpaper.GetSmall(); if (small == null) { return; } var content = args.ItemContainer.ContentTemplateRoot as Image; content.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 64, 64); } else { var content = args.ItemContainer.ContentTemplateRoot as Rectangle; content.Fill = new SolidColorBrush(Color.FromArgb(0xFF, (byte)((wallpaper.Color >> 16) & 0xFF), (byte)((wallpaper.Color >> 8) & 0xFF), (byte)((wallpaper.Color & 0xFF)))); } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var message = args.Item as Message; if (message.Content is MessagePhoto photoMessage) { if (args.ItemContainer.ContentTemplateRoot is SimpleHyperlinkButton content) { var small = photoMessage.Photo.GetSmall(); var photo = content.Content as Image; photo.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 0, 0); } } else if (message.Content is MessageVideo videoMessage && videoMessage.Video.Thumbnail != null) { if (args.ItemContainer.ContentTemplateRoot is SimpleHyperlinkButton content) { var photo = content.Content as Image; photo.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, videoMessage.Video.Thumbnail.Photo, 0, 0); } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var message = args.Item as Message; if (args.ItemContainer.ContentTemplateRoot is SimpleHyperlinkButton hyperlink) { if (message.Content is MessagePhoto photoMessage) { var small = photoMessage.Photo.GetSmall(); var photo = hyperlink.Content as Image; photo.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 0, 0); } else if (message.Content is MessageVideo videoMessage && videoMessage.Video.Thumbnail != null) { var grid = hyperlink.Content as Grid; var photo = grid.Children[0] as Image; photo.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, videoMessage.Video.Thumbnail.Photo, 0, 0); var panel = grid.Children[1] as Grid; var duration = panel.Children[1] as TextBlock; duration.Text = videoMessage.Video.GetDuration(); } } else if (args.ItemContainer.ContentTemplateRoot is SharedFileCell fileCell) { fileCell.UpdateMessage(ViewModel.ProtoService, ViewModel, message); } else if (args.ItemContainer.ContentTemplateRoot is SharedLinkCell linkCell) { linkCell.UpdateMessage(ViewModel.ProtoService, ViewModel.NavigationService, message); } else if (args.ItemContainer.ContentTemplateRoot is SharedAudioCell audioCell) { audioCell.UpdateMessage(ViewModel.PlaybackService, ViewModel.ProtoService, message); } else if (args.ItemContainer.ContentTemplateRoot is SharedVoiceCell voiceCell) { voiceCell.UpdateMessage(ViewModel.PlaybackService, ViewModel.ProtoService, message); } else if (message.Content is MessageHeaderDate && args.ItemContainer.ContentTemplateRoot is Border content && content.Child is TextBlock header) { header.Text = DateTimeToFormatConverter.ConvertMonthGrouping(Utils.UnixTimestampToDateTime(message.Date)); } if (args.ItemContainer.ContentTemplateRoot is FrameworkElement element) { element.Tag = message; } }
private ImageSource ConvertPhoto(Photo photo) { var small = photo?.GetSmall(); if (small == null) { Photo.Visibility = Visibility.Collapsed; return(null); } Photo.Visibility = Visibility.Visible; return(PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small)); }
private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var wallpaper = args.Item as Background; var root = args.ItemContainer.ContentTemplateRoot as Grid; var check = root.Children[1] as UIElement; check.Visibility = wallpaper.Id == ViewModel.SelectedItem?.Id ? Visibility.Visible : Visibility.Collapsed; if (wallpaper.Id == 1000001) { return; } else if (wallpaper.Id == Constants.WallpaperLocalId) { //var content = root.Children[0] as Image; //content.Source = new BitmapImage(new Uri($"ms-appdata:///local/{ViewModel.SessionId}/{Constants.WallpaperLocalFileName}")); var file = await ApplicationData.Current.LocalFolder.GetFileAsync($"{ViewModel.SessionId}\\{Constants.WallpaperLocalFileName}"); using (var stream = await file.OpenReadAsync()) { var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(stream); var content = root.Children[0] as Image; content.Source = bitmap; } } else if (wallpaper.Document != null) { var small = wallpaper.Document.Thumbnail; if (small == null) { return; } var content = root.Children[0] as Image; content.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 64, 64); } else if (wallpaper.Type is BackgroundTypeSolid solid) { var content = root.Children[0] as Rectangle; content.Fill = new SolidColorBrush(Color.FromArgb(0xFF, (byte)((solid.Color >> 16) & 0xFF), (byte)((solid.Color >> 8) & 0xFF), (byte)(solid.Color & 0xFF))); } }
public void Handle(UpdateFile update) { this.BeginOnUIThread(() => { foreach (var item in ViewModel.Items) { if (item.UpdateFile(update.File)) { var container = List.ContainerFromItem(item) as SelectorItem; if (container == null) { continue; } var root = container.ContentTemplateRoot as Grid; if (root == null) { continue; } var content = root.Children[0] as Image; if (content == null) { return; } var small = item.Document?.Thumbnail; if (small == null) { return; } content.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 64, 64); } } }); }
private async void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var wallpaper = args.Item as Background; var root = args.ItemContainer.ContentTemplateRoot as Grid; var check = root.Children[1] as UIElement; check.Visibility = wallpaper.Id == ViewModel.SelectedItem?.Id ? Visibility.Visible : Visibility.Collapsed; if (wallpaper.Id == 1000001) { return; } else if (wallpaper.Id == Constants.WallpaperLocalId) { //var content = root.Children[0] as Image; //content.Source = new BitmapImage(new Uri($"ms-appdata:///local/{ViewModel.SessionId}/{Constants.WallpaperLocalFileName}")); var file = await ApplicationData.Current.LocalFolder.GetFileAsync($"{ViewModel.SessionId}\\{Constants.WallpaperLocalFileName}"); using (var stream = await file.OpenReadAsync()) { var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(stream); var content = root.Children[0] as Image; content.Source = bitmap; } } else if (wallpaper.Document != null) { var small = wallpaper.Document.Thumbnail; if (small == null) { return; } var content = root.Children[0] as Image; content.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.File, wallpaper.Document.Thumbnail.Width, wallpaper.Document.Thumbnail.Height); if (wallpaper.Type is BackgroundTypePattern pattern) { content.Opacity = pattern.Intensity / 100d; root.Background = pattern.Fill.ToBrush(); } else { content.Opacity = 1; root.Background = null; } } else if (wallpaper.Type is BackgroundTypeFill fill) { var content = root.Children[0] as Rectangle; content.Fill = fill.ToBrush(); } }
public void UpdateFile(Telegram.Td.Api.File file) { var viewModel = ViewModel; if (viewModel == null) { return; } if (viewModel.Media != null && viewModel.Media.TryGetMessagesForFileId(file.Id, out IList <Message> messages)) { foreach (var message in messages) { message.UpdateFile(file); var container = ScrollingMedia.ContainerFromItem(message) as GridViewItem; if (container == null) { continue; } var content = container.ContentTemplateRoot as SimpleHyperlinkButton; if (content == null) { continue; } if (message.Content is MessagePhoto photo) { var small = photo.Photo.GetSmall(); if (small != null && small.Photo.Id == file.Id && file.Local.IsDownloadingCompleted) { var thumbnail = content.Content as Image; thumbnail.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, small.Photo, 0, 0); } } else if (message.Content is MessageVideo video) { var thumb = video.Video.Thumbnail; if (thumb != null && thumb.Photo.Id == file.Id && file.Local.IsDownloadingCompleted) { var grid = content.Content as Grid; var thumbnail = grid.Children[0] as Image; thumbnail.Source = PlaceholderHelper.GetBitmap(ViewModel.ProtoService, thumb.Photo, 0, 0); } } } if (file.Local.IsDownloadingCompleted && file.Remote.IsUploadingCompleted) { messages.Clear(); } } if (viewModel.Files != null && viewModel.Files.TryGetMessagesForFileId(file.Id, out messages)) { foreach (var message in messages) { message.UpdateFile(file); var container = ScrollingFiles.ContainerFromItem(message) as ListViewItem; if (container == null) { continue; } var document = message.GetFile(); var content = container.ContentTemplateRoot as SharedFileCell; if (document == null || content == null) { continue; } if (file.Id == document.Id) { content.UpdateFile(message, file); } } } if (viewModel.Music != null && viewModel.Music.TryGetMessagesForFileId(file.Id, out messages)) { foreach (var message in messages) { message.UpdateFile(file); var container = ScrollingMusic.ContainerFromItem(message) as ListViewItem; if (container == null) { continue; } var document = message.GetFile(); var content = container.ContentTemplateRoot as SharedFileCell; if (document == null || content == null) { continue; } if (file.Id == document.Id) { content.UpdateFile(message, file); } } } if (viewModel.Voice != null && viewModel.Voice.TryGetMessagesForFileId(file.Id, out messages)) { foreach (var message in messages) { message.UpdateFile(file); var container = ScrollingVoice.ContainerFromItem(message) as ListViewItem; if (container == null) { continue; } var document = message.GetFile(); var content = container.ContentTemplateRoot as SharedFileCell; if (document == null || content == null) { continue; } if (file.Id == document.Id) { content.UpdateFile(message, file); } } } }