private async void Camera_Click(object sender, RoutedEventArgs e) { var capture = new CameraCaptureUI(); capture.PhotoSettings.AllowCropping = true; capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga; capture.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; capture.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.StandardDefinition; var file = await capture.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo); if (file != null) { if (file.ContentType.Equals("video/mp4")) { await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("WIN_yyyyMMdd_HH_mm_ss") + ".mp4", NameCollisionOption.GenerateUniqueName); ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StorageVideo.CreateAsync(file, true), false)); } else { await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("WIN_yyyyMMdd_HH_mm_ss") + ".jpg", NameCollisionOption.GenerateUniqueName); ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StoragePhoto.CreateAsync(file, true), false)); } } }
private async void Camera_Click(object sender, RoutedEventArgs e) { var capture = new CameraCaptureUI(); //capture.PhotoSettings.AllowCropping = true; capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable; capture.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; capture.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.HighestAvailable; var file = await capture.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo); if (file != null) { if (file.ContentType.Equals("video/mp4")) { if (Services.SettingsService.Current.SaveCameraMediaInGallery) { await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("UM_yyyyMMdd_HH_mm_ss") + ".mp4", NameCollisionOption.GenerateUniqueName); } ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StorageVideo.CreateAsync(file), false)); } else { if (Services.SettingsService.Current.SaveCameraMediaInGallery) { await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("UM_yyyyMMdd_HH_mm_ss") + ".jpg", NameCollisionOption.GenerateUniqueName); } ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StoragePhoto.CreateAsync(file), false)); } } }
private async void More_Click(object sender, RoutedEventArgs e) { var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.AddRange(Constants.MediaTypes); var files = await picker.PickMultipleFilesAsync(); if (files != null) { foreach (var file in files) { if (file.ContentType.Equals("video/mp4")) { Items.Add(await StorageVideo.CreateAsync(file, true)); } else { Items.Add(new StoragePhoto(file) { IsSelected = true }); } } } }
private async void OnPaste(object sender, TextControlPasteEventArgs e) { // If the user tries to paste RTF content from any TOM control (Visual Studio, Word, Wordpad, browsers) // we have to handle the pasting operation manually to allow plaintext only. var package = Clipboard.GetContent(); if (package.AvailableFormats.Contains(StandardDataFormats.Bitmap)) { if (e != null) { e.Handled = true; } var bitmap = await package.GetBitmapAsync(); var media = new ObservableCollection <StorageMedia>(); var fileName = string.Format("image_{0:yyyy}-{0:MM}-{0:dd}_{0:HH}-{0:mm}-{0:ss}.png", DateTime.Now); var cache = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName); using (var stream = await bitmap.OpenReadAsync()) { var result = await ImageHelper.TranscodeAsync(stream, cache, BitmapEncoder.PngEncoderId); var photo = await StoragePhoto.CreateAsync(result, true); if (photo == null) { return; } media.Add(photo); } if (package.AvailableFormats.Contains(StandardDataFormats.Text)) { media[0].Caption = new FormattedText(await package.GetTextAsync(), new TextEntity[0]); } ViewModel.SendMediaExecute(media, media[0]); } else if (package.AvailableFormats.Contains(StandardDataFormats.WebLink)) { } else if (package.AvailableFormats.Contains(StandardDataFormats.StorageItems)) { if (e != null) { e.Handled = true; } var items = await package.GetStorageItemsAsync(); var media = new ObservableCollection <StorageMedia>(); var files = new List <StorageFile>(items.Count); foreach (var file in items.OfType <StorageFile>()) { if (file.ContentType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase) || file.ContentType.Equals("image/png", StringComparison.OrdinalIgnoreCase) || file.ContentType.Equals("image/bmp", StringComparison.OrdinalIgnoreCase) || file.ContentType.Equals("image/gif", StringComparison.OrdinalIgnoreCase)) { var photo = await StoragePhoto.CreateAsync(file, true); if (photo != null) { media.Add(photo); } } else if (file.ContentType == "video/mp4") { var video = await StorageVideo.CreateAsync(file, true); if (video != null) { media.Add(video); } } files.Add(file); } // Send compressed __only__ if user is dropping photos and videos only if (media.Count > 0 && media.Count == files.Count) { ViewModel.SendMediaExecute(media, media[0]); } else if (files.Count > 0) { ViewModel.SendFileExecute(files); } } else if (package.AvailableFormats.Contains(StandardDataFormats.Text) && package.AvailableFormats.Contains("application/x-tl-field-tags")) { if (e != null) { e.Handled = true; } // This is our field format var text = await package.GetTextAsync(); var data = await package.GetDataAsync("application/x-tl-field-tags") as IRandomAccessStream; var reader = new DataReader(data.GetInputStreamAt(0)); var length = await reader.LoadAsync((uint)data.Size); var count = reader.ReadInt32(); var entities = new List <TextEntity>(count); for (int i = 0; i < count; i++) { var entity = new TextEntity { Offset = reader.ReadInt32(), Length = reader.ReadInt32() }; var type = reader.ReadByte(); switch (type) { case 1: entity.Type = new TextEntityTypeBold(); break; case 2: entity.Type = new TextEntityTypeItalic(); break; case 3: entity.Type = new TextEntityTypePreCode(); break; case 4: entity.Type = new TextEntityTypeTextUrl { Url = reader.ReadString(reader.ReadUInt32()) }; break; case 5: entity.Type = new TextEntityTypeMentionName { UserId = reader.ReadInt32() }; break; } entities.Add(entity); } InsertText(text, entities); } else if (package.AvailableFormats.Contains(StandardDataFormats.Text) && package.AvailableFormats.Contains("application/x-td-field-tags")) { // This is Telegram Desktop mentions format } else if (package.AvailableFormats.Contains(StandardDataFormats.Text) /*&& package.Contains("Rich Text Format")*/) { if (e != null) { e.Handled = true; } var text = await package.GetTextAsync(); var start = Document.Selection.StartPosition; var result = Emoticon.Pattern.Replace(text, (match) => { var emoticon = match.Groups[1].Value; var emoji = Emoticon.Replace(emoticon); if (match.Value.StartsWith(" ")) { emoji = $" {emoji}"; } return(emoji); }); Document.Selection.SetText(TextSetOptions.None, result); Document.Selection.SetRange(start + result.Length, start + result.Length); } }
private async void SendMediaExecute(ObservableCollection <StorageMedia> media) { if (MediaLibrary.SelectedCount > 0) { foreach (var storage in MediaLibrary.Where(x => x.IsSelected)) { if (storage is StoragePhoto photo) { await SendPhotoAsync(storage.File, storage.Caption, storage.TTLSeconds); } else if (storage is StorageVideo video) { await SendVideoAsync(storage.File, storage.Caption, false, await video.GetEncodingAsync()); } } return; } ObservableCollection <StorageMedia> storages = media; if (media == null) { var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.AddRange(Constants.MediaTypes); var files = await picker.PickMultipleFilesAsync(); if (files != null) { storages = new ObservableCollection <StorageMedia>(); foreach (var file in files) { if (file.ContentType.Equals("video/mp4")) { storages.Add(await StorageVideo.CreateAsync(file, true)); } else { storages.Add(new StoragePhoto(file) { IsSelected = true }); } } } } //else //{ // storages = new ObservableCollection<StorageMedia>(media); //} if (storages != null && storages.Count > 0) { var dialog = new SendPhotosView { ViewModel = this, Items = storages, SelectedItem = storages[0], IsTTLEnabled = _peer is TLInputPeerUser }; var dialogResult = await dialog.ShowAsync(); TextField.FocusMaybe(FocusState.Keyboard); if (dialogResult == ContentDialogBaseResult.OK) { foreach (var storage in dialog.Items.Where(x => x.IsSelected)) { if (storage is StoragePhoto photo) { await SendPhotoAsync(storage.File, storage.Caption, storage.TTLSeconds); } else if (storage is StorageVideo video) { await SendVideoAsync(storage.File, storage.Caption, false, await video.GetEncodingAsync()); } } } } }