public static string Format(int value) { if (value == 0) { return(Strings.Resources.ShortMessageLifetimeForever); } else if (value >= 1 && value < 16) { return(Locale.FormatTtl(value)); } else if (value == 16) { return(Locale.FormatTtl(30)); } else if (value == 17) { return(Locale.FormatTtl(60)); } else if (value == 18) { return(Locale.FormatTtl(60 * 60)); } else if (value == 19) { return(Locale.FormatTtl(60 * 60 * 24)); } else if (value == 20) { return(Locale.FormatTtl(60 * 60 * 24 * 7)); } return(string.Empty); }
public void UpdateSecretChat(Chat chat, SecretChat secretChat) { if (secretChat.State is SecretChatStateReady ready) { SecretLifetime.Badge = Locale.FormatTtl(secretChat.Ttl); //SecretIdenticon.Source = PlaceholderHelper.GetIdenticon(secretChat.KeyHash, 24); SecretLifetime.Visibility = Visibility.Visible; SecretHashKey.Visibility = Visibility.Visible; } else { SecretLifetime.Visibility = Visibility.Collapsed; SecretHashKey.Visibility = Visibility.Collapsed; } }
public void UpdateSecretChat(Chat chat, SecretChat secretChat) { if (secretChat.State is SecretChatStateReady ready) { SecretLifetime.Badge = chat.MessageTtlSetting > 0 ? Locale.FormatTtl(chat.MessageTtlSetting) : Strings.Resources.ShortMessageLifetimeForever; //SecretIdenticon.Source = PlaceholderHelper.GetIdenticon(secretChat.KeyHash, 24); MiscPanel.Visibility = Visibility.Visible; SecretLifetime.Visibility = Visibility.Visible; SecretHashKey.Visibility = Visibility.Visible; } else { MiscPanel.Visibility = Visibility.Collapsed; SecretLifetime.Visibility = Visibility.Collapsed; SecretHashKey.Visibility = Visibility.Collapsed; } }
private static string GetString(int seconds, object parameter) { var param = parameter as string; if (param != null && param.Equals("short")) { //if (seconds >= 1 && seconds < 21) //{ // return seconds.ToString(); //} //return ((seconds / 5) + 16).ToString(); return(seconds.ToString()); } if (seconds >= 1 && seconds < 21) { return(Locale.FormatTtl(seconds)); } return(Locale.FormatTtl((seconds - 16) * 5)); }
public void UpdateFile(MessageViewModel message, File file) { var photo = GetContent(message.Content); if (photo == null) { return; } var small = photo.Thumbnail; var big = photo.DocumentValue; //if (small != null && small.Photo.Id != big.Id && small.Photo.Id == file.Id) //{ // UpdateThumbnail(message, file); // return; //} //else if (big == null || big.Id != file.Id) //{ // return; //} var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)file.Remote.UploadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { //Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Button.Opacity = 1; Overlay.Opacity = 0; if (message.Delegate.CanBeDownloaded(photo, file)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { if (message.IsSecret()) { //Button.Glyph = Icons.Ttl; Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; Button.Opacity = 1; Overlay.Opacity = 1; Subtitle.Text = Locale.FormatTtl(message.Ttl, true); } else { //Button.Glyph = message.SendingState is MessageSendingStatePending ? Icons.Confirm : Icons.Photo; Button.SetGlyph(file.Id, message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? MessageContentState.Confirm : MessageContentState.Photo); Button.Progress = 1; if (message.Content is MessageText text && text.WebPage?.EmbedUrl?.Length > 0 || (message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0)) { Button.Opacity = 1; }
private void UpdateFile(MessageViewModel message, File file) { var video = GetContent(message.Content); if (video == null || !_templateApplied) { return; } if (video.VideoValue.Id != file.Id) { return; } if (message.IsSecret()) { Overlay.ProgressVisibility = Visibility.Collapsed; var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { var generating = file.Local.DownloadedSize < size; Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)(generating ? file.Local.DownloadedSize : file.Remote.UploadedSize) / size; if (generating) { Subtitle.Text = string.Format("{0}%", file.Local.DownloadedSize); } else { Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); } } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Subtitle.Text = string.Format("{0}, {1}", Locale.FormatTtl(message.Ttl, true), FileSizeConverter.Convert(size)); if (message.Delegate.CanBeDownloaded(video, file)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; Subtitle.Text = Locale.FormatTtl(message.Ttl, true); } } else { var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { if (message.Delegate.CanBeDownloaded(video, file)) { UpdateSource(message, file, video.Duration); } Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 0; Overlay.SetGlyph(file.Id, MessageContentState.Downloading); Overlay.Progress = (double)file.Local.DownloadedSize / size; Overlay.ProgressVisibility = Visibility.Visible; if (_source == null) { Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); } } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { var generating = file.Local.DownloadedSize < size; UpdateSource(null, null, 0); Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)(generating ? file.Local.DownloadedSize : file.Remote.UploadedSize) / size; Overlay.ProgressVisibility = Visibility.Collapsed; if (generating) { Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0}%", file.Local.DownloadedSize); } else { Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); } } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 0; Overlay.SetGlyph(file.Id, MessageContentState.Download); Overlay.Progress = 0; Overlay.ProgressVisibility = Visibility.Visible; Subtitle.Text = video.GetDuration() + Environment.NewLine + FileSizeConverter.Convert(size); if (message.Delegate.CanBeDownloaded(video, file)) { _message.ProtoService.DownloadFile(file.Id, 32); UpdateSource(message, file, video.Duration); } else { UpdateSource(null, null, 0); } } else { if (message.Delegate.CanBeDownloaded(video, file)) { UpdateSource(message, file, video.Duration); } Button.SetGlyph(file.Id, message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? MessageContentState.Confirm : MessageContentState.Play); Button.Progress = 0; Overlay.Progress = 1; Overlay.ProgressVisibility = Visibility.Collapsed; Subtitle.Text = video.GetDuration(); } } }
public void UpdateFile(MessageViewModel message, File file) { var animation = GetContent(message.Content); if (animation == null) { return; } if (animation.Thumbnail != null && animation.Thumbnail.Photo.Id == file.Id) { UpdateThumbnail(message, file); return; } else if (animation.AnimationValue.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.Glyph = "\uE10A"; Button.Progress = (double)file.Local.DownloadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); Overlay.Opacity = 1; } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { Button.Glyph = "\uE10A"; Button.Progress = (double)file.Remote.UploadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); Overlay.Opacity = 1; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Button.Glyph = "\uE118"; Button.Progress = 0; Subtitle.Text = Strings.Resources.AttachGif + ", " + FileSizeConverter.Convert(size); Overlay.Opacity = 1; if (message.Delegate.CanBeDownloaded(message)) { _message.ProtoService.Send(new DownloadFile(file.Id, 32)); } } else { if (message.IsSecret()) { Button.Glyph = "\uE60D"; Button.Progress = 1; Subtitle.Text = Locale.FormatTtl(Math.Max(message.Ttl, animation.Duration), true); Overlay.Opacity = 1; } else { Button.Glyph = "\uE906"; Button.Progress = 1; Overlay.Opacity = 0; } } }
private void UpdateFile(MessageViewModel message, File file) { var animation = GetContent(message.Content); if (animation == null || !_templateApplied) { return; } if (animation.AnimationValue.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); Overlay.Opacity = 1; Player.Source = null; } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)file.Remote.UploadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); Overlay.Opacity = 1; Player.Source = null; } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { //Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Subtitle.Text = Strings.Resources.AttachGif + ", " + FileSizeConverter.Convert(size); Overlay.Opacity = 1; Player.Source = null; if (message.Delegate.CanBeDownloaded(animation, file)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { if (message.IsSecret()) { //Button.Glyph = Icons.Ttl; Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; Subtitle.Text = Locale.FormatTtl(Math.Max(message.Ttl, animation.Duration), true); Overlay.Opacity = 1; Player.Source = null; } else { //Button.Glyph = Icons.Animation; Button.SetGlyph(file.Id, MessageContentState.Animation); Button.Progress = 1; Subtitle.Text = Strings.Resources.AttachGif; Overlay.Opacity = 1; Player.Source = new LocalVideoSource(file); message.Delegate.ViewVisibleMessages(false); } } }
public void UpdateFile(MessageViewModel message, File file) { var video = GetContent(message.Content); if (video == null) { return; } if (video.Thumbnail != null && video.Thumbnail.File.Id == file.Id) { UpdateThumbnail(message, video.Thumbnail, file); return; } else if (video.VideoValue.Id != file.Id) { return; } if (message.IsSecret()) { Overlay.ProgressVisibility = Visibility.Collapsed; var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.Glyph = Icons.Cancel; Button.Progress = (double)file.Local.DownloadedSize / size; Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { var generating = file.Local.DownloadedSize < size; Button.Glyph = Icons.Cancel; Button.Progress = (double)(generating ? file.Local.DownloadedSize : file.Remote.UploadedSize) / size; if (generating) { Subtitle.Text = string.Format("{0}%", file.Local.DownloadedSize); } else { Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); } } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Button.Glyph = Icons.Download; Button.Progress = 0; Subtitle.Text = string.Format("{0}, {1}", Locale.FormatTtl(message.Ttl, true), FileSizeConverter.Convert(size)); if (message.Delegate.CanBeDownloaded(message)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { Button.Glyph = Icons.Ttl; Button.Progress = 1; Subtitle.Text = Locale.FormatTtl(message.Ttl, true); } } else { var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.Glyph = Icons.Play; Button.Progress = 0; Overlay.Glyph = Icons.Cancel; Overlay.Progress = (double)file.Local.DownloadedSize / size; Overlay.ProgressVisibility = Visibility.Visible; Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size)); } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { var generating = file.Local.DownloadedSize < size; Button.Glyph = Icons.Cancel; Button.Progress = (double)(generating ? file.Local.DownloadedSize : file.Remote.UploadedSize) / size; Overlay.ProgressVisibility = Visibility.Collapsed; if (generating) { Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0}%", file.Local.DownloadedSize); } else { Subtitle.Text = video.GetDuration() + Environment.NewLine + string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size)); } } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Button.Glyph = Icons.Play; Button.Progress = 0; Overlay.Glyph = Icons.Download; Overlay.Progress = 0; Overlay.ProgressVisibility = Visibility.Visible; Subtitle.Text = video.GetDuration() + Environment.NewLine + FileSizeConverter.Convert(size); if (message.Delegate.CanBeDownloaded(message)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { Button.Glyph = message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? Icons.Confirm : Icons.Play; Button.Progress = 0; Overlay.Progress = 1; Overlay.ProgressVisibility = Visibility.Collapsed; Subtitle.Text = video.GetDuration(); } } }
public object Convert(object value, Type targetType, object parameter, string language) { return(Locale.FormatTtl(System.Convert.ToInt32(value))); }
public void UpdateFile(MessageViewModel message, File file) { var photo = GetContent(message.Content); if (photo == null) { return; } var small = photo.GetSmall(); var big = photo.GetBig(); if (small != null && small.Photo.Id != big.Photo.Id && small.Photo.Id == file.Id) { UpdateThumbnail(message, file); return; } else if (big == null || big.Photo.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Button.Glyph = "\uE10A"; Button.Progress = (double)file.Local.DownloadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { Button.Glyph = "\uE10A"; Button.Progress = (double)file.Remote.UploadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Button.Glyph = "\uE118"; Button.Progress = 0; Button.Opacity = 1; Overlay.Opacity = 0; if (message.Delegate.CanBeDownloaded(message)) { _message.ProtoService.Send(new DownloadFile(file.Id, 32)); } } else { if (message.IsSecret()) { Button.Glyph = "\uE60D"; Button.Progress = 1; Button.Opacity = 1; Overlay.Opacity = 1; Subtitle.Text = Locale.FormatTtl(message.Ttl, true); } else { Button.Glyph = "\uE102"; Button.Progress = 1; Button.Opacity = 0; Overlay.Opacity = 0; Texture.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } } }
private void UpdateFile(MessageViewModel message, File file) { var photo = GetContent(message.Content); if (photo == null || !_templateApplied) { return; } var big = photo.GetBig(); if (big == null || big.Photo.Id != file.Id) { return; } var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Downloading); Button.Progress = (double)file.Local.DownloadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; } else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed) { //Button.Glyph = Icons.Cancel; Button.SetGlyph(file.Id, MessageContentState.Uploading); Button.Progress = (double)file.Remote.UploadedSize / size; Button.Opacity = 1; Overlay.Opacity = 0; if (message.IsSecret()) { Texture.Source = null; } else { UpdateTexture(message, big, file); } } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { //Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Button.Opacity = 1; Overlay.Opacity = 0; if (message.Delegate.CanBeDownloaded(photo, file)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { if (message.IsSecret()) { //Button.Glyph = Icons.Ttl; Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; Button.Opacity = 1; Overlay.Opacity = 1; Texture.Source = null; Subtitle.Text = Locale.FormatTtl(message.Ttl, true); } else { //Button.Glyph = message.SendingState is MessageSendingStatePending ? Icons.Confirm : Icons.Play; Button.SetGlyph(file.Id, message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? MessageContentState.Confirm : MessageContentState.Play); Button.Progress = 1; if (message.Content is MessageText text && text.WebPage?.EmbedUrl?.Length > 0 || (message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0)) { Button.Opacity = 1; }