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 void OnElementPrepared(Microsoft.UI.Xaml.Controls.ItemsRepeater sender, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs args) { var button = args.Element as Button; var content = button.Content as Grid; var chat = button.DataContext as Chat; var title = content.Children[1] as TextBlock; title.Text = ViewModel.ProtoService.GetTitle(chat); //if (ViewModel.CacheService.TryGetSupergroup(chat, out Supergroup supergroup)) //{ // var subtitle = content.Children[2] as TextBlock; // subtitle.Text = string.Format("{0}, {1}", BindConvert.Distance(nearby.Distance), Locale.Declension("Members", supergroup.MemberCount)); //} //else //{ // var subtitle = content.Children[2] as TextBlock; // subtitle.Text = BindConvert.Distance(nearby.Distance); //} var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36); //button.Command = ViewModel.OpenChatCommand; //button.CommandParameter = nearby; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as StackPanel; var user = args.Item as User; if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = user.GetFullName(); } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(_protoService, user, 48); } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
private void OnElementPrepared(Microsoft.UI.Xaml.Controls.ItemsRepeater sender, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs args) { var button = args.Element as Button; var content = button.Content as Grid; var chat = sender.ItemsSourceView.GetAt(args.Index) as Chat; var title = content.Children[1] as TextBlock; title.Text = ViewModel.ProtoService.GetTitle(chat); if (ViewModel.CacheService.TryGetSupergroup(chat, out Supergroup supergroup)) { var subtitle = content.Children[2] as TextBlock; if (string.IsNullOrEmpty(supergroup.Username)) { subtitle.Text = Locale.Declension(supergroup.IsChannel ? "Subscribers" : "Members", supergroup.MemberCount); } else { subtitle.Text = $"@{supergroup.Username}"; } } var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36); button.Command = ViewModel.LinkCommand; button.CommandParameter = chat; }
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)))); } }
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(); } } } }
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 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); } }
public async void UpdateFile(MessageViewModel message, File file) { var sticker = GetContent(message.Content); if (sticker == null) { return; } if (sticker.StickerValue.Id != file.Id) { return; } if (file.Local.IsDownloadingCompleted) { Source = await PlaceholderHelper.GetWebPFrameAsync(file.Local.Path); ElementCompositionPreview.SetElementChildVisual(this, null); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { message.ProtoService.DownloadFile(file.Id, 1); } }
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(); } }
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 UpdateChatInviteLinkCount(ChatInviteLinkCount count, Grid content, uint phase) { var user = ViewModel.ProtoService.GetUser(count.UserId); if (user == null) { return; } if (phase == 0) { var title = content.Children[1] as TextBlock; title.Text = user.GetFullName(); } else if (phase == 1) { var subtitle = content.Children[2] as TextBlock; subtitle.Text = Locale.Declension("InviteLinkCount", count.InviteLinkCount); } else if (phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); } }
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 IEnumerable <Match> MatchSingleValue(JValue input, JValue pattern) { switch (pattern.Type) { case JTokenType.String: var patternValue = pattern.Value <string>(); if (PlaceholderHelper.IsPlaceholder(patternValue, out var placeholder)) { return(MatchCollectionHelper.CreateWithSingleGroup(new CapturingGroup { Key = placeholder, Value = (input as JValue).GetPrimitiveAsObject(), Path = input.Path })); } else { return(string.Equals(input.Value <string>(), PlaceholderHelper.Unescape(patternValue), this.stringComparison) ? MatchCollectionHelper.CreateWithEmptyMatch() : null); } case JTokenType.Integer: return(input.Value <long>() == pattern.Value <long>() ? MatchCollectionHelper.CreateWithEmptyMatch() : null); case JTokenType.Boolean: return(input.Value <bool>() == pattern.Value <bool>() ? MatchCollectionHelper.CreateWithEmptyMatch() : null); default: throw new NotSupportedJTokenTypeException(pattern); } }
public void Handle(UpdateFile update) { this.BeginOnUIThread(() => { var panel = List.ItemsPanelRoot as ItemsStackPanel; if (panel == null) { return; } if (panel.FirstCacheIndex < 0) { return; } //for (int i = panel.FirstCacheIndex; i <= panel.LastCacheIndex; i++) for (int i = 0; i < ViewModel.Items.Count; i++) { var chat = ViewModel.Items[i]; if (chat.UpdateFile(update.File)) { var container = List.ContainerFromItem(chat) as ListViewItem; if (container == null) { return; } var content = container.ContentTemplateRoot as Grid; var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetChat(null, chat, 36); } } }); }
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) { var chat = ViewModel.Chat; if (chat != null && chat.UpdateFile(file)) { Photo.Source = PlaceholderHelper.GetChat(null, chat, 64, 64); } for (int i = 0; i < ScrollingHost.Items.Count; i++) { var member = ScrollingHost.Items[i] as ChatMember; var user = ViewModel.ProtoService.GetUser(member.UserId); if (user == null) { return; } if (user.UpdateFile(file)) { var container = ScrollingHost.ContainerFromIndex(i) as ListViewItem; if (container == null) { return; } var content = container.ContentTemplateRoot as Grid; var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(null, user, 36, 36); } } }
public SettingsStorageOptimizationPage(IProtoService protoService, ContentDialogBase dialog, StorageStatisticsByChat statistics) { InitializeComponent(); _dialog = dialog; var chat = protoService.GetChat(statistics.ChatId); Title.Text = chat == null ? "Other Chats" : protoService.GetTitle(chat); Subtitle.Text = FileSizeConverter.Convert(statistics.Size); Photo.Source = chat == null ? null : PlaceholderHelper.GetChat(protoService, chat, 36, 36); Photo.Visibility = chat == null ? Visibility.Collapsed : Visibility.Visible; List.ItemsSource = statistics.ByFileType.OrderByDescending(x => x.Size).ToList(); foreach (var fileType in statistics.ByFileType) { switch (fileType.FileType) { case FileTypeAnimation animation: case FileTypeAudio audio: case FileTypeDocument document: case FileTypeNone none: case FileTypePhoto photo: case FileTypeUnknown unknown: case FileTypeVideo video: case FileTypeVideoNote videoNote: case FileTypeVoiceNote voiceNote: List.SelectedItems.Add(fileType); break; } } }
private void UpdateThumbnail(MessageViewModel message, Thumbnail thumbnail, Minithumbnail minithumbnail) { if (thumbnail != null) { var file = thumbnail.File; if (file.Local.IsDownloadingCompleted && thumbnail.Format is ThumbnailFormatJpeg) { //Texture.Source = new BitmapImage(UriEx.GetLocal(file.Local.Path)); Texture.Source = PlaceholderHelper.GetBlurred(file.Local.Path); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { if (minithumbnail != null) { Texture.Source = PlaceholderHelper.GetBlurred(minithumbnail.Data); } message.ProtoService.DownloadFile(file.Id, 1); } } else if (minithumbnail != null) { Texture.Source = PlaceholderHelper.GetBlurred(minithumbnail.Data); } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as ChatShareCell; var messageSender = args.Item as MessageSender; content.UpdateState(false, false); var photo = content.Photo; var title = content.Children[1] as TextBlock; if (_protoService.TryGetUser(messageSender, out User user)) { photo.Source = PlaceholderHelper.GetUser(_protoService, user, 36); title.Text = user.GetFullName(); } else if (_protoService.TryGetChat(messageSender, out Chat chat)) { photo.Source = PlaceholderHelper.GetChat(_protoService, chat, 36); title.Text = _protoService.GetTitle(chat); } }
public void UpdateFile(Telegram.Td.Api.File file) { foreach (MessageSender sender in ScrollingHost.Items) { if (ViewModel.CacheService.TryGetUser(sender, out User user) && user.UpdateFile(file)) { var container = ScrollingHost.ContainerFromItem(sender) as SelectorItem; if (container == null) { return; } var content = container.ContentTemplateRoot as Grid; var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(null, user, 36); } else if (ViewModel.CacheService.TryGetChat(sender, out Chat chat) && chat.UpdateFile(file)) { var container = ScrollingHost.ContainerFromItem(sender) as SelectorItem; if (container == null) { return; } var content = container.ContentTemplateRoot as Grid; var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetChat(null, chat, 36); } } }
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 void UpdateMessage(MessageViewModel message) { _message = message; var contact = message.Content as MessageContact; if (contact == null || !_templateApplied) { return; } var user = message.ProtoService.GetUser(contact.Contact.UserId); if (user != null) { Photo.SetUser(message.ProtoService, user, 48); } else { Photo.Source = PlaceholderHelper.GetNameForUser(contact.Contact.FirstName, contact.Contact.LastName, 48); } Title.Text = contact.Contact.GetFullName(); Subtitle.Text = PhoneNumber.Format(contact.Contact.PhoneNumber); Button.Visibility = string.IsNullOrEmpty(contact.Contact.Vcard) ? Visibility.Collapsed : Visibility.Visible; }
public void UpdateUser(IProtoService protoService, ContainerContentChangingEventArgs args, TypedEventHandler <ListViewBase, ContainerContentChangingEventArgs> callback) { var user = args.Item as User; if (user == null) { return; } if (args.Phase == 0) { TitleLabel.Text = user.GetFullName(); } else if (args.Phase == 1) { SubtitleLabel.Text = LastSeenConverter.GetLabel(user, false); } else if (args.Phase == 2) { Photo.Source = PlaceholderHelper.GetUser(protoService, user, 36); } if (args.Phase < 2) { args.RegisterUpdateCallback(callback); } args.Handled = true; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Grid; var user = args.Item as User; content.Tag = user; if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = user.GetFullName(); } else if (args.Phase == 1) { var subtitle = content.Children[2] as TextBlock; subtitle.Text = string.IsNullOrEmpty(user.PhoneNumber) ? Strings.Resources.NumberUnknown : PhoneNumber.Format(user.PhoneNumber); } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
private void OnElementPrepared(Microsoft.UI.Xaml.Controls.ItemsRepeater sender, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs args) { var item = sender.ItemsSourceView.GetAt(args.Index); if (item is User user) { var button = args.Element as Button; var content = button.Content as Grid; var title = content.Children[1] as TextBlock; title.Text = user.GetFullName(); var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(_protoService, user, 36); button.Click += User_Click; } else if (item is PollResultViewModel option) { var headered = args.Element as HeaderedControl; headered.Header = $"{option.Text} — {option.VotePercentage}%"; headered.Footer = Locale.Declension(option.Type is PollTypeQuiz ? "Answer" : "Vote", option.VoterCount); headered.Visibility = option.VoterCount > 0 ? Visibility.Visible : Visibility.Collapsed; } }
public JoinChatPopup(IProtoService protoService, ChatInviteLinkInfo info) { InitializeComponent(); _protoService = protoService; Photo.Source = PlaceholderHelper.GetChat(protoService, info, 72); Title.Text = info.Title; Subtitle.Text = ConvertCount(info.MemberCount, info.MemberUserIds.Count == 0); PrimaryButtonText = Strings.Resources.ChannelJoin; SecondaryButtonText = Strings.Resources.Cancel; if (info.MemberUserIds.Count > 0) { FooterPanel.Visibility = ConvertMoreVisibility(info.MemberCount, info.MemberUserIds.Count); Footer.Text = ConvertMore(info.MemberCount, info.MemberUserIds.Count); Members.Visibility = Visibility.Visible; Members.ItemsSource = protoService.GetUsers(info.MemberUserIds); } else { Members.Visibility = Visibility.Collapsed; } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; var chat = args.Item as Chat; if (args.Phase == 0) { var title = content.Children[1] as TextBlock; title.Text = ViewModel.ProtoService.GetTitle(chat); } else if (args.Phase == 1) { } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36); } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
public void UpdateMessage(MessageViewModel message) { _message = message; var contact = message.Content as MessageContact; if (contact == null) { return; } var user = message.ProtoService.GetUser(contact.Contact.UserId); if (user != null) { Photo.Source = PlaceholderHelper.GetUser(message.ProtoService, user, 48, 48); Title.Text = user.GetFullName(); Subtitle.Text = PhoneNumber.Format(contact.Contact.PhoneNumber); } else { var fullName = string.IsNullOrEmpty(contact.Contact.LastName) ? contact.Contact.FirstName : $"{contact.Contact.FirstName} {contact.Contact.LastName}"; Photo.Source = PlaceholderHelper.GetBadge(fullName, Colors.Red, 48, 48); Title.Text = fullName; Subtitle.Text = PhoneNumber.Format(contact.Contact.PhoneNumber); } Button.Visibility = string.IsNullOrEmpty(contact.Contact.Vcard) ? Visibility.Collapsed : Visibility.Visible; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var button = args.ItemContainer.ContentTemplateRoot as Button; var message = args.Item as Message; var content = button.Content as Grid; var title = content.Children[1] as TextBlock; var subtitle = content.Children[2] as TextBlock; var photo = content.Children[0] as ProfilePicture; var chat = ViewModel.CacheService.GetChat(message.ChatId); if (chat == null) { return; } title.Text = chat.Title; subtitle.Text = Locale.Declension("Views", message.InteractionInfo?.ViewCount ?? 0); photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36); button.CommandParameter = message; button.Command = ViewModel.OpenPostCommand; }