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 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 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 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; }
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.Source = PlaceholderHelper.GetUser(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; }
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(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); } } }
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; }
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); } } }
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; }
public void UpdateUser(Chat chat, User user, bool secret) { Title.Text = user.GetFullName(); Subtitle.Text = LastSeenConverter.GetLabel(user, true); Photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 64); Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; var member = args.Item as ChatMember; content.Tag = member; var user = ViewModel.ProtoService.GetUser(member.UserId); if (user == null) { return; } if (args.Phase == 0) { var photo = content.Children[0] as ProfilePicture; photo.Source = null; 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 = LastSeenConverter.GetLabel(user, false); if (member.Status is ChatMemberStatusAdministrator administrator) { var label = content.Children[3] as TextBlock; label.Text = string.IsNullOrEmpty(administrator.CustomTitle) ? Strings.Resources.ChannelAdmin : administrator.CustomTitle; } else if (member.Status is ChatMemberStatusCreator creator) { var label = content.Children[3] as TextBlock; label.Text = string.IsNullOrEmpty(creator.CustomTitle) ? Strings.Resources.ChannelCreator : creator.CustomTitle; } } 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; }
public void UpdateUser(Chat chat, User user, bool secret) { Photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 64, 64); Title.Text = user.GetFullName(); Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed; PhoneNumber.Content = Telegram.Helpers.PhoneNumber.Format(user.PhoneNumber); Username.Content = string.IsNullOrEmpty(user.Username) ? Strings.Resources.UsernameEmpty : $"@{user.Username}"; }
public void UpdateMessage(MessageViewModel message) { _message = message; var location = message.Content as MessageLocation; if (location == null) { return; } var latitude = location.Location.Latitude.ToString(CultureInfo.InvariantCulture); var longitude = location.Location.Longitude.ToString(CultureInfo.InvariantCulture); Texture.Source = new BitmapImage(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, "320,200"))); Texture.Constraint = message; //VenueDot.Visibility = Visibility.Visible; //VenueGlyph.UriSource = null; if (location.LivePeriod > 0) { var expired = BindConvert.Current.DateTime(message.Date + location.LivePeriod) < DateTime.Now; if (expired) { LivePanel.Visibility = Visibility.Collapsed; PinDot.Visibility = Visibility.Visible; PinPhoto.Source = null; } else { LivePanel.Visibility = Visibility.Visible; PinDot.Visibility = Visibility.Collapsed; if (_message.ProtoService.TryGetUser(message.Sender, out User senderUser)) { PinPhoto.Source = PlaceholderHelper.GetUser(message.ProtoService, senderUser, 32); } else if (_message.ProtoService.TryGetChat(message.Sender, out Chat senderChat)) { PinPhoto.Source = PlaceholderHelper.GetChat(message.ProtoService, senderChat, 32); } Title.Text = Strings.Resources.AttachLiveLocation; Subtitle.Text = Locale.FormatLocationUpdateDate(message.EditDate > 0 ? message.EditDate : message.Date); } } else { LivePanel.Visibility = Visibility.Collapsed; PinDot.Visibility = Visibility.Visible; PinPhoto.Source = null; } }
public void UpdateCall(IProtoService protoService, TLCallGroup call) { _call = call; DisplayLabel.Text = ConvertCount(call); DateLabel.Text = Converter.DateExtended(call.Message.Date); TypeLabel.Text = call.DisplayType; Photo.Source = PlaceholderHelper.GetUser(protoService, call.Peer, 36); VisualStateManager.GoToState(LayoutRoot, call.IsFailed ? "Missed" : "Default", false); }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; var member = args.Item as ChatMember; content.Tag = member; var user = ViewModel.ProtoService.GetUser(member.UserId); if (user == null) { return; } if (args.Phase == 0) { var photo = content.Children[0] as ProfilePicture; photo.Source = null; var title = content.Children[1] as TextBlock; if (title.Inlines.Count > 0) { var label = title.Inlines[0] as Run; label.Text = user.GetFullName(); } else { title.Text = user.GetFullName(); } } else if (args.Phase == 1) { var subtitle = content.Children[2] as TextBlock; subtitle.Text = LastSeenConverter.GetLabel(user, false); } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36, 36); } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
public void UpdateUser(Chat chat, User user, bool secret) { Photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 64); Title.Text = user.GetFullName(); Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed; #if DEBUG PhoneNumber.Badge = "+39 --- --- ----"; #else PhoneNumber.Badge = Common.PhoneNumber.Format(user.PhoneNumber); #endif Username.Badge = string.IsNullOrEmpty(user.Username) ? Strings.Resources.UsernameEmpty : $"{user.Username}"; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; var member = args.Item as ChatMember; if (member == null) { return; } content.Tag = args.Item; var user = ViewModel.ProtoService.GetUser(member.UserId); if (user == null) { return; } 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 = ChannelParticipantToTypeConverter.Convert(ViewModel.ProtoService, member); } 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; }
public void UpdateConnectedWebsite(IProtoService protoService, ConnectedWebsite session) { var bot = protoService.GetUser(session.BotUserId); if (bot == null) { return; } Photo.Source = PlaceholderHelper.GetUser(protoService, bot, 18, 18); Domain.Text = session.DomainName; Title.Text = string.Format("{0}, {1}, {2}", bot.FirstName, session.Browser, session.Platform); Subtitle.Text = string.Format("{0} — {1}", session.Ip, session.Location); LastActiveDate.Text = BindConvert.Current.DateExtended(session.LastActiveDate); }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var content = args.ItemContainer.ContentTemplateRoot as Grid; var messageSender = args.Item as MessageSender; content.Tag = messageSender; User user = null; Chat chat = null; ViewModel.CacheService.TryGetUser(messageSender, out user); ViewModel.CacheService.TryGetChat(messageSender, out chat); if (args.Phase == 0) { var title = content.Children[1] as TextBlock; if (user != null) { title.Text = user.GetFullName(); } else if (chat != null) { title.Text = ViewModel.ProtoService.GetTitle(chat); } } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; if (user != null) { photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); } else if (chat != null) { photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36); } } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } args.Handled = true; }
public void UpdateFile(Telegram.Td.Api.File file) { foreach (User user in ScrollingHost.Items) { if (user.UpdateFile(file)) { var container = ScrollingHost.ContainerFromItem(user) 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); } } }
public void InitializeParent(UIElement parent, IProtoService protoService) { _parent = parent; ElementCompositionPreview.SetIsTranslationEnabled(parent, true); RecentUsers.GetPicture = sender => { if (protoService.TryGetUser(sender, out User user)) { return(PlaceholderHelper.GetUser(protoService, user, 32)); } else if (protoService.TryGetChat(sender, out Chat chat)) { return(PlaceholderHelper.GetChat(protoService, chat, 32)); } return(null); }; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; if (args.Item is User user) { var photo = content.Children[0] as ProfilePicture; var title = content.Children[1] as TextBlock; var name = title.Inlines[0] as Run; var username = title.Inlines[1] as Run; name.Text = user.GetFullName(); username.Text = string.IsNullOrEmpty(user.Username) ? string.Empty : $" @{user.Username}"; photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); } else if (args.Item is ChatSearchMediaFilter filter) { var child = content.Children[0] as Border; var glyph = child.Child as TextBlock; var title = content.Children[1] as TextBlock; glyph.Text = filter.Glyph; title.Text = filter.Text; if (filter.Filter is SearchMessagesFilterVideoNote) { glyph.FontFamily = App.Current.Resources["TelegramThemeFontFamily"] as FontFamily; } else { glyph.FontFamily = App.Current.Resources["SymbolThemeFontFamily"] as FontFamily; } } }
public void UpdateFile(File file) { var chat = ViewModel.Chat; if (chat == null) { return; } var user = ViewModel.CacheService.GetUser(chat); if (user == null) { return; } if (user.UpdateFile(file)) { Photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 64); } }
private async 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 title = content.Children[1] as TextBlock; var subtitle = content.Children[2] as TextBlock; if (button.DataContext is MessageInteractionCounters counters) { var photo = content.Children[0] as Image; var views = content.Children[3] as TextBlock; var shares = content.Children[4] as TextBlock; var caption = counters.Message.GetCaption(); if (string.IsNullOrEmpty(caption?.Text)) { var message = counters.Message; if (message.Content is MessageVoiceNote) { title.Text = Strings.Resources.AttachAudio; } else if (message.Content is MessageVideo) { title.Text = Strings.Resources.AttachVideo; } else if (message.Content is MessageAnimation) { title.Text = Strings.Resources.AttachGif; } else if (message.Content is MessageAudio audio) { var performer = string.IsNullOrEmpty(audio.Audio.Performer) ? null : audio.Audio.Performer; var titloe = string.IsNullOrEmpty(audio.Audio.Title) ? null : audio.Audio.Title; if (performer == null || titloe == null) { title.Text = Strings.Resources.AttachMusic; } else { title.Text = $"\uD83C\uDFB5 {performer} - {titloe}"; } } else if (message.Content is MessageDocument document) { if (string.IsNullOrEmpty(document.Document.FileName)) { title.Text = Strings.Resources.AttachDocument; } else { title.Text = document.Document.FileName; } } else if (message.Content is MessageInvoice invoice) { title.Text = invoice.Title; } else if (message.Content is MessageContact) { title.Text = Strings.Resources.AttachContact; } else if (message.Content is MessageLocation location) { title.Text = location.LivePeriod > 0 ? Strings.Resources.AttachLiveLocation : Strings.Resources.AttachLocation; } else if (message.Content is MessageVenue) { title.Text = Strings.Resources.AttachLocation; } else if (message.Content is MessagePhoto) { title.Text = Strings.Resources.AttachPhoto; } else if (message.Content is MessagePoll poll) { title.Text = "\uD83D\uDCCA " + poll.Poll.Question; } else if (message.Content is MessageCall call) { title.Text = call.ToOutcomeText(message.IsOutgoing); } else if (message.Content is MessageUnsupported) { title.Text = Strings.Resources.UnsupportedAttachment; } } else { title.Text = caption.Text.Replace('\n', ' '); } subtitle.Text = Converter.DateAt(counters.Message.Date); views.Text = Locale.Declension("Views", counters.ViewCount); shares.Text = Locale.Declension("Shares", counters.ForwardCount); var thumbnail = counters.Message.GetMinithumbnail(); if (thumbnail != null) { double ratioX = (double)36 / thumbnail.Width; double ratioY = (double)36 / thumbnail.Height; double ratio = Math.Max(ratioX, ratioY); var width = (int)(thumbnail.Width * ratio); var height = (int)(thumbnail.Height * ratio); var bitmap = new BitmapImage { DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical }; var bytes = thumbnail.Data.ToArray(); using (var stream = new System.IO.MemoryStream(bytes)) { var random = System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(stream); await bitmap.SetSourceAsync(random); } photo.Source = bitmap; photo.Visibility = Visibility.Visible; } else { photo.Visibility = Visibility.Collapsed; photo.Source = null; } button.CommandParameter = counters.Message; button.Command = ViewModel.OpenPostCommand; } else { var photo = content.Children[0] as ProfilePicture; if (button.DataContext is ChatStatisticsMessageSenderInfo senderInfo) { var user = ViewModel.CacheService.GetUser(senderInfo.UserId); if (user == null) { return; } var stringBuilder = new StringBuilder(); if (senderInfo.SentMessageCount > 0) { stringBuilder.Append(Locale.Declension("messages", senderInfo.SentMessageCount)); } if (senderInfo.AverageCharacterCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.AppendFormat(Strings.Resources.CharactersPerMessage, Locale.Declension("Characters", senderInfo.AverageCharacterCount)); } title.Text = user.GetFullName(); subtitle.Text = stringBuilder.ToString(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.CommandParameter = senderInfo.UserId; button.Command = ViewModel.OpenProfileCommand; } else if (button.DataContext is ChatStatisticsAdministratorActionsInfo adminInfo) { var user = ViewModel.CacheService.GetUser(adminInfo.UserId); if (user == null) { return; } var stringBuilder = new StringBuilder(); if (adminInfo.DeletedMessageCount > 0) { stringBuilder.Append(Locale.Declension("Deletions", adminInfo.DeletedMessageCount)); } if (adminInfo.BannedUserCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(Locale.Declension("Bans", adminInfo.BannedUserCount)); } if (adminInfo.RestrictedUserCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(Locale.Declension("Restrictions", adminInfo.RestrictedUserCount)); } title.Text = user.GetFullName(); subtitle.Text = stringBuilder.ToString(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.CommandParameter = adminInfo.UserId; button.Command = ViewModel.OpenProfileCommand; } else if (button.DataContext is ChatStatisticsInviterInfo inviterInfo) { var user = ViewModel.CacheService.GetUser(inviterInfo.UserId); if (user == null) { return; } if (inviterInfo.AddedMemberCount > 0) { subtitle.Text = Locale.Declension("Invitations", inviterInfo.AddedMemberCount); } else { subtitle.Text = string.Empty; } title.Text = user.GetFullName(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.CommandParameter = inviterInfo.UserId; button.Command = ViewModel.OpenProfileCommand; } } }
private void Search_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { //var photo = content.Children[0] as ProfilePicture; //photo.Source = null; return; } var result = args.Item as SearchResult; var chat = result.Chat; var user = result.User ?? ViewModel.ProtoService.GetUser(chat); if (user == null) { return; } var content = args.ItemContainer.ContentTemplateRoot as Grid; if (content == null) { return; } 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; if (result.IsPublic) { subtitle.Text = $"@{user.Username}"; } else { subtitle.Text = LastSeenConverter.GetLabel(user, true); } if (ApiInfo.CanUseTextHighlighters) { if (subtitle.Text.StartsWith($"@{result.Query}", StringComparison.OrdinalIgnoreCase)) { var highligher = new TextHighlighter(); highligher.Foreground = new SolidColorBrush(Colors.Red); highligher.Background = new SolidColorBrush(Colors.Transparent); highligher.Ranges.Add(new TextRange { StartIndex = 1, Length = result.Query.Length }); subtitle.TextHighlighters.Add(highligher); } else { subtitle.TextHighlighters.Clear(); } } } 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(Search_ContainerContentChanging); } args.Handled = true; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue) { return; } if (args.Item is ISessionService session) { var content = args.ItemContainer.ContentTemplateRoot as Grid; if (content == null) { return; } var user = session.ProtoService.GetUser(session.UserId); if (user == null) { return; } if (args.Phase == 0) { var title = content.Children[2] as TextBlock; title.Text = user.GetFullName(); Automation.SetToolTip(content, user.GetFullName()); } else if (args.Phase == 2) { var photo = content.Children[0] as ProfilePicture; photo.Source = PlaceholderHelper.GetUser(session.ProtoService, user, 28); } if (args.Phase < 2) { args.RegisterUpdateCallback(OnContainerContentChanging); } } else if (args.Item is RootDestination destination) { var content = args.ItemContainer as Controls.NavigationViewItem; if (content != null) { content.IsChecked = destination == _navigationViewSelected; if (destination == RootDestination.SavedMessages) { content.FontFamily = new FontFamily("ms-appx:///Assets/Fonts/Telegram.ttf#Telegram"); } else { content.FontFamily = new FontFamily("Segoe MDL2 Assets"); } } switch (destination) { case RootDestination.AddAccount: content.Text = Strings.Resources.AddAccount; content.Glyph = "\uE109"; break; case RootDestination.NewChat: content.Text = Strings.Resources.NewGroup; content.Glyph = "\uE902"; break; case RootDestination.NewSecretChat: content.Text = Strings.Resources.NewSecretChat; content.Glyph = "\uE1F6"; break; case RootDestination.NewChannel: content.Text = Strings.Resources.NewChannel; content.Glyph = "\uE789"; break; case RootDestination.Chats: content.Text = Strings.Resources.FilterChats; content.Glyph = "\uE8BD"; break; case RootDestination.Contacts: content.Text = Strings.Resources.Contacts; content.Glyph = "\uE716"; break; case RootDestination.Calls: content.Text = Strings.Resources.Calls; content.Glyph = "\uE717"; break; case RootDestination.Settings: content.Text = Strings.Resources.Settings; content.Glyph = "\uE115"; break; case RootDestination.SavedMessages: content.Text = Strings.Resources.SavedMessages; content.Glyph = "\uE907"; break; case RootDestination.News: content.Text = "News"; content.Glyph = "\uE789"; break; } } }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { if (args.InRecycleQueue == true) { // XAML has indicated that the item is no longer being shown, so add it to the recycle queue var tag = args.ItemContainer.Tag as string; #if ENABLE_DEBUG_SPEW Debug.WriteLine($"Adding {args.ItemContainer.GetHashCode()} to {tag}"); #endif // ENABLE_DEBUG_SPEW var added = _typeToItemHashSetMapping[tag].Add(args.ItemContainer); #if ENABLE_DEBUG_SPEW Debug.Assert(added == true, "Recycle queue should never have dupes. If so, we may be incorrectly reusing a container that is already in use!"); #endif // ENABLE_DEBUG_SPEW return; } var message = args.Item as MessageViewModel; var content = args.ItemContainer.ContentTemplateRoot as FrameworkElement; if (content is Grid grid) { var photo = grid.FindName("Photo") as ProfilePicture; if (photo != null) { photo.Tag = message; if (message.IsSaved()) { if (message.ForwardInfo is MessageForwardedFromUser fromUser) { var user = message.ProtoService.GetUser(fromUser.SenderUserId); if (user != null) { photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32); } } else if (message.ForwardInfo is MessageForwardedPost post) { var chat = message.ProtoService.GetChat(post.ForwardedFromChatId); if (chat != null) { photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 32, 32); } } } else { var user = message.GetSenderUser(); if (user != null) { photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32); } } } content = grid.FindName("Bubble") as FrameworkElement; } if (content is MessageBubble bubble) { bubble.UpdateMessage(args.Item as MessageViewModel); args.Handled = true; } else if (content is MessageService service) { service.UpdateMessage(args.Item as MessageViewModel); 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 title = content.Children[1] as TextBlock; var subtitle = content.Children[2] as TextBlock; var photo = content.Children[0] as ProfilePicture; if (button.DataContext is ChatStatisticsMessageSenderInfo senderInfo) { var user = ViewModel.CacheService.GetUser(senderInfo.UserId); if (user == null) { return; } var stringBuilder = new StringBuilder(); if (senderInfo.SentMessageCount > 0) { stringBuilder.Append(Locale.Declension("messages", senderInfo.SentMessageCount)); } if (senderInfo.AverageCharacterCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.AppendFormat(Strings.Resources.CharactersPerMessage, Locale.Declension("Characters", senderInfo.AverageCharacterCount)); } title.Text = user.GetFullName(); subtitle.Text = stringBuilder.ToString(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.Command = ViewModel.OpenProfileCommand; button.CommandParameter = senderInfo.UserId; } else if (button.DataContext is ChatStatisticsAdministratorActionsInfo adminInfo) { var user = ViewModel.CacheService.GetUser(adminInfo.UserId); if (user == null) { return; } var stringBuilder = new StringBuilder(); if (adminInfo.DeletedMessageCount > 0) { stringBuilder.Append(Locale.Declension("Deletions", adminInfo.DeletedMessageCount)); } if (adminInfo.BannedUserCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(Locale.Declension("Bans", adminInfo.BannedUserCount)); } if (adminInfo.RestrictedUserCount > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(Locale.Declension("Restrictions", adminInfo.RestrictedUserCount)); } title.Text = user.GetFullName(); subtitle.Text = stringBuilder.ToString(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.Command = ViewModel.OpenProfileCommand; button.CommandParameter = adminInfo.UserId; } else if (button.DataContext is ChatStatisticsInviterInfo inviterInfo) { var user = ViewModel.CacheService.GetUser(inviterInfo.UserId); if (user == null) { return; } if (inviterInfo.AddedMemberCount > 0) { subtitle.Text = Locale.Declension("Invitations", inviterInfo.AddedMemberCount); } else { subtitle.Text = string.Empty; } title.Text = user.GetFullName(); photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36); button.Command = ViewModel.OpenProfileCommand; button.CommandParameter = inviterInfo.UserId; } }
public void Update(Call call, DateTime started) { if (_disposed) { return; } var user = _cacheService.GetUser(call.UserId); if (user != null) { Image.Source = PlaceholderHelper.GetUser(_protoService, user, 144); //if (user.ProfilePhoto != null) //{ // var file = user.ProfilePhoto.Big; // if (file.Local.IsDownloadingCompleted) // { // Image.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); // BackgroundPanel.Background = new SolidColorBrush(Colors.Transparent); // } // else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) // { // Image.Source = null; // BackgroundPanel.Background = PlaceholderHelper.GetBrush(user.Id); // _protoService?.DownloadFile(file.Id, 1, 0); // } //} //else //{ // Image.Source = null; // BackgroundPanel.Background = PlaceholderHelper.GetBrush(user.Id); //} FromLabel.Text = user.GetFullName(); DescriptionLabel.Text = string.Format(Strings.Resources.CallEmojiKeyTooltip, user.FirstName); AudioOffText.Text = string.Format(Strings.Resources.VoipUserMicrophoneIsOff, user.FirstName); VideoOffText.Text = string.Format(Strings.Resources.VoipUserCameraIsOff, user.FirstName); } if (call.State is CallStateReady ready) { _emojis = ready.Emojis; for (int i = 0; i < ready.Emojis.Count; i++) { var imageLarge = FindName($"LargeEmoji{i}") as Image; var source = Emoji.BuildUri(_emojis[i]); imageLarge.Source = new BitmapImage(new Uri(source)); } } switch (call.State) { case CallStatePending pending: if (call.IsOutgoing) { ResetUI(); } else { Audio.Visibility = Visibility.Collapsed; Video.Visibility = Visibility.Collapsed; Close.Visibility = Visibility.Collapsed; Close.Margin = new Thickness(); Accept.Margin = new Thickness(0, 0, 6, 0); Accept.Visibility = Visibility.Visible; Discard.Margin = new Thickness(6, 0, 0, 0); Discard.Visibility = Visibility.Visible; } break; case CallStateDiscarded discarded: if (call.IsOutgoing && discarded.Reason is CallDiscardReasonDeclined) { Audio.Visibility = Visibility.Collapsed; Video.Visibility = Visibility.Collapsed; Close.Margin = new Thickness(0, 0, 6, 0); Close.Visibility = Visibility.Visible; Accept.Margin = new Thickness(6, 0, 0, 0); Accept.Visibility = Visibility.Visible; Discard.Visibility = Visibility.Collapsed; Discard.Margin = new Thickness(); } break; default: ResetUI(); break; } switch (call.State) { case CallStatePending pending: StateLabel.Content = call.IsOutgoing ? pending.IsReceived ? Strings.Resources.VoipRinging : pending.IsCreated ? Strings.Resources.VoipWaiting : Strings.Resources.VoipRequesting : Strings.Resources.VoipIncoming; break; case CallStateExchangingKeys exchangingKeys: StateLabel.Content = Strings.Resources.VoipConnecting; break; case CallStateHangingUp hangingUp: StateLabel.Content = Strings.Resources.VoipHangingUp; break; case CallStateDiscarded discarded: StateLabel.Content = discarded.Reason is CallDiscardReasonDeclined ? Strings.Resources.VoipBusy : Strings.Resources.VoipCallEnded; break; } }