private void Button_Click(object sender, RoutedEventArgs e) { var video = GetContent(_message.Content); if (video == null) { return; } if (_message.IsSecret()) { return; } var file = video.VideoValue; if (file.Local.IsDownloadingActive) { _message.ProtoService.CancelDownloadFile(file.Id); } else if (file.Remote.IsUploadingActive || _message.SendingState is MessageSendingStateFailed) { _message.ProtoService.Send(new DeleteMessages(_message.ChatId, new[] { _message.Id }, true)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && !file.Local.IsDownloadingCompleted) { _message.ProtoService.DownloadFile(file.Id, 32); } else { _message.Delegate.OpenMedia(_message, this); } }
public void UpdateFile(MessageViewModel message, File file) { var videoNote = GetContent(message.Content); if (videoNote == null) { return; } if (videoNote.Thumbnail != null && videoNote.Thumbnail.Photo.Id == file.Id) { UpdateThumbnail(message, file); return; } else if (videoNote.Video.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; } 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; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { //Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; if (message.Delegate.CanBeDownloaded(message)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { if (message.IsSecret()) { //Button.Glyph = Icons.Ttl; Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; } else { //Button.Glyph = Icons.Play; Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 1; } } }
public void UpdateMessage(MessageViewModel message) { _message = message; var photo = GetContent(message.Content); if (photo == null || !_templateApplied) { return; } LayoutRoot.Constraint = message; LayoutRoot.Background = null; Texture.Source = null; Texture.Stretch = _album ? Stretch.UniformToFill : Stretch.Uniform; //UpdateMessageContentOpened(message); var small = photo.GetSmall()?.Photo; var big = photo.GetBig(); if (small == null || big == null) { return; } if (!big.Photo.Local.IsFileExisting() || message.IsSecret()) { UpdateThumbnail(message, small, photo.Minithumbnail, true); } UpdateManager.Subscribe(this, message, big.Photo, ref _fileToken, UpdateFile); UpdateFile(message, big.Photo); }
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(); } } }
private void UpdateFile(MessageViewModel message, File file) { var videoNote = GetContent(message.Content); if (videoNote == null || !_templateApplied) { return; } if (videoNote.Video.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; 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; Player.Source = null; } else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting()) { //Button.Glyph = Icons.Download; Button.SetGlyph(file.Id, MessageContentState.Download); Button.Progress = 0; Player.Source = null; if (message.Delegate.CanBeDownloaded(videoNote, file)) { _message.ProtoService.DownloadFile(file.Id, 32); } } else { if (message.IsSecret()) { //Button.Glyph = Icons.Ttl; Button.SetGlyph(file.Id, MessageContentState.Ttl); Button.Progress = 1; Player.Source = null; } else { //Button.Glyph = Icons.Play; Button.SetGlyph(file.Id, MessageContentState.Play); Button.Progress = 1; Player.Source = new LocalVideoSource(file); message.Delegate.ViewVisibleMessages(false); } } }
public void UpdateMessage(MessageViewModel message) { _message = message; var photo = GetContent(message.Content); if (photo == null) { return; } Constraint = message; Background = null; Texture.Source = null; //UpdateMessageContentOpened(message); var small = photo.GetSmall(); var big = photo.GetBig(); if (small != null && !big.Photo.Local.IsDownloadingCompleted /*&& small.Photo.Id != big.Photo.Id*/ && !message.IsSecret()) { UpdateThumbnail(message, small.Photo); } UpdateFile(message, big.Photo); }
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; }