public void OnForwardInAnimationComplete() { if (ChooseAttachment == null) { ChooseAttachment = new ChooseAttachmentViewModel(With, CacheService, EventAggregator, NavigationService, StateService, false); NotifyOfPropertyChange(() => ChooseAttachment); } if (StateService.RemoveBackEntry) { NavigationService.RemoveBackEntry(); StateService.RemoveBackEntry = false; } if (StateService.RemoveBackEntries) { var backEntry = NavigationService.BackStack.FirstOrDefault(); while (backEntry != null && !backEntry.Source.ToString().Contains("ShellView.xaml")) { NavigationService.RemoveBackEntry(); backEntry = NavigationService.BackStack.FirstOrDefault(); } StateService.RemoveBackEntries = false; } //if (PrivateBetaIdentityToVisibilityConverter.IsPrivateBeta) { SecretChatDebug = new SecretChatDebugViewModel(Chat, Rekey); NotifyOfPropertyChange(() => SecretChatDebug); } }
public void Attach() { if (ChooseAttachment == null) { ChooseAttachment = new ChooseAttachmentViewModel(With, CacheService, EventAggregator, NavigationService, StateService); NotifyOfPropertyChange(() => ChooseAttachment); } BeginOnUIThread(() => ChooseAttachment.Open()); }
public void Attach() { if (ChooseAttachment == null) { ChooseAttachment = new ChooseAttachmentViewModel(With, OpenInlineBot, SendDocument, SendVideo, SendPhoto, SendLocation, OpenContact, CacheService, EventAggregator, NavigationService, StateService); NotifyOfPropertyChange(() => ChooseAttachment); } BeginOnUIThread(() => ChooseAttachment.Open()); }
public async void PickPhoto() { #if WP81 var photoPickerSettings = IoC.Get <IStateService>().GetPhotoPickerSettings(); if (photoPickerSettings != null && photoPickerSettings.External) { ((App)Application.Current).ChooseFileInfo = new ChooseFileInfo(DateTime.Now); var fileOpenPicker = new FileOpenPicker(); fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.FileTypeFilter.Clear(); fileOpenPicker.FileTypeFilter.Add(".bmp"); fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.FileTypeFilter.Add(".jpeg"); fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.ContinuationData.Add("From", IsSecretChat ? "SecretDialogDetailsView" : "DialogDetailsView"); fileOpenPicker.ContinuationData.Add("Type", "Image"); if (Environment.OSVersion.Version.Major >= 10) { var result = await fileOpenPicker.PickMultipleFilesAsync(); if (result.Count > 0) { Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => { _sendPhotosAction.SafeInvoke(result); }); } } else { fileOpenPicker.PickMultipleFilesAndContinue(); } } else { ChooseAttachmentViewModel.OpenPhotoPicker(false, (r1, r2) => _sendPhotosAction(r1)); } #endif }
private void OnContractActivated(object sender, IActivatedEventArgs e) { var saveArgs = e as FileSavePickerContinuationEventArgs; if (saveArgs != null) { object from; if (saveArgs.ContinuationData != null && saveArgs.ContinuationData.TryGetValue("From", out from)) { if (string.Equals(from, "DialogDetailsView")) { Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => DialogDetailsViewModel.SaveFile(saveArgs.File)); return; } } } var args = e as FileOpenPickerContinuationEventArgs; if (args != null) { object from; if (args.ContinuationData != null && args.ContinuationData.TryGetValue("From", out from)) { if (string.Equals(from, "DialogDetailsView")) { var contentControl = RootVisual as ContentControl; if (contentControl != null) { var dialogDetailsView = contentControl.Content as DialogDetailsView; if (dialogDetailsView != null) { var dialogDetailsViewModel = dialogDetailsView.DataContext as DialogDetailsViewModel; if (dialogDetailsViewModel != null) { object type; if (!args.ContinuationData.TryGetValue("Type", out type)) { type = "Document"; } if (string.Equals(type, "Video")) { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.SendVideo(file)); } else if (string.Equals(type, "Image")) { var file = args.Files.FirstOrDefault(); if (file != null) { #if MULTIPLE_PHOTOS Photos = args.Files; return; #endif #if WP81 Telegram.Api.Helpers.Execute.BeginOnThreadPool(async() => { var randomStream = await file.OpenReadAsync(); await ChooseAttachmentViewModel.Handle(IoC.Get <IStateService>(), randomStream, file.Name); //MessageBox.Show("OnContractActivated after handle"); dialogDetailsViewModel.BackwardInAnimationComplete(); }); #else Telegram.Api.Helpers.Execute.BeginOnThreadPool(async() => { var randomStream = await file.OpenReadAsync(); var chosenPhoto = randomStream.AsStreamForRead(); //MessageBox.Show("OnContractActivated stream"); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => { ChooseAttachmentViewModel.Handle(IoC.Get <IStateService>(), chosenPhoto, file.Name); //MessageBox.Show("OnContractActivated after handle"); dialogDetailsViewModel.BackwardInAnimationComplete(); }); }); #endif } } else { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.SendDocument(file)); } return; } } } } else if (string.Equals(from, "SecretDialogDetailsView")) { var contentControl = RootVisual as ContentControl; if (contentControl != null) { var dialogDetailsView = contentControl.Content as SecretDialogDetailsView; if (dialogDetailsView != null) { var secretDialogDetailsViewModel = dialogDetailsView.DataContext as SecretDialogDetailsViewModel; if (secretDialogDetailsViewModel != null) { object type; if (!args.ContinuationData.TryGetValue("Type", out type)) { type = "Document"; } if (string.Equals(type, "Video")) //{ // var file = args.Files.FirstOrDefault(); // Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => dialogDetailsViewModel.EditVideo(file)); //} //else { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => secretDialogDetailsViewModel.SendDocument(file)); } else if (string.Equals(type, "Image")) { var file = args.Files.FirstOrDefault(); if (file != null) { #if MULTIPLE_PHOTOS Photos = args.Files; return; #endif #if WP81 Telegram.Api.Helpers.Execute.BeginOnThreadPool(async() => { var randomStream = await file.OpenReadAsync(); await ChooseAttachmentViewModel.Handle(IoC.Get <IStateService>(), randomStream, file.Name); secretDialogDetailsViewModel.OnBackwardInAnimationComplete(); }); #else Telegram.Api.Helpers.Execute.BeginOnThreadPool(async() => { var randomStream = await file.OpenReadAsync(); var chosenPhoto = randomStream.AsStreamForRead(); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => { ChooseAttachmentViewModel.Handle(IoC.Get <IStateService>(), chosenPhoto, file.Name); }); }); #endif } } else { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => secretDialogDetailsViewModel.SendDocument(file)); } return; } } } } else if (string.Equals(from, "ResidentialAddressView")) { var contentControl = RootVisual as ContentControl; if (contentControl != null) { var view = contentControl.Content as ResidentialAddressView; if (view != null) { object type; if (!args.ContinuationData.TryGetValue("Type", out type)) { type = "Document"; } if (type is string) { var viewModel = view.DataContext as ResidentialAddressViewModel; if (viewModel != null) { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => viewModel.SendDocument(type.ToString(), file)); return; } } } } } else if (string.Equals(from, "PersonalDetailsView")) { var contentControl = RootVisual as ContentControl; if (contentControl != null) { object type; if (!args.ContinuationData.TryGetValue("Type", out type)) { type = "Document"; } if (type is string) { var view = contentControl.Content as PersonalDetailsView; if (view != null) { var viewModel = view.DataContext as PersonalDetailsViewModel; if (viewModel != null) { var file = args.Files.FirstOrDefault(); Telegram.Api.Helpers.Execute.BeginOnThreadPool(() => viewModel.SendDocument(type.ToString(), file)); return; } } } } } } } }
public static void EditPhoto(Action <byte[]> callback) { var photoPickerSettings = IoC.Get <IStateService>().GetPhotoPickerSettings(); if (photoPickerSettings != null && photoPickerSettings.External) { var photoChooserTask = new PhotoChooserTask { ShowCamera = true, PixelHeight = 800, PixelWidth = 800 }; photoChooserTask.Completed += (o, e) => { if (e.TaskResult == TaskResult.OK) { byte[] bytes; var sourceStream = e.ChosenPhoto; using (var memoryStream = new MemoryStream()) { sourceStream.CopyTo(memoryStream); bytes = memoryStream.ToArray(); } callback.SafeInvoke(bytes); } }; photoChooserTask.Show(); } else { ChooseAttachmentViewModel.OpenPhotoPicker(true, (result1, result2) => { Execute.BeginOnUIThread(TimeSpan.FromSeconds(0.4), () => { var frame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage page = null; if (frame != null) { page = frame.Content as PhoneApplicationPage; if (page != null) { var applicationBar = page.ApplicationBar; if (applicationBar != null) { applicationBar.IsVisible = false; } } } if (page == null) { return; } var popup = new Popup(); var cropControl = new CropControl { Width = page.ActualWidth, Height = page.ActualHeight }; _cropControl = cropControl; page.SizeChanged += PageOnSizeChanged; cropControl.Close += (sender, args) => { _cropControl = null; popup.IsOpen = false; popup.Child = null; frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame != null) { page = frame.Content as PhoneApplicationPage; if (page != null) { page.SizeChanged -= PageOnSizeChanged; var applicationBar = page.ApplicationBar; if (applicationBar != null) { applicationBar.IsVisible = true; } } } }; cropControl.Crop += (sender, args) => { callback.SafeInvoke(args.File); cropControl.TryClose(); }; cropControl.SetFile(result1.FirstOrDefault(), result2.FirstOrDefault()); popup.Child = cropControl; popup.IsOpen = true; }); }); } }
private static async Task <Tuple <TLPhotoSizeBase, TLPhotoSizeBase> > GetFilePreviewAndThumbAsync(StorageFile file) { try { var preview = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 480, ThumbnailOptions.ResizeThumbnail); var thumbLocation = new TLFileLocation { DCId = new TLInt(0), VolumeId = TLLong.Random(), LocalId = TLInt.Random(), Secret = TLLong.Random(), }; var thumbFileName = String.Format("{0}_{1}_{2}.jpg", thumbLocation.VolumeId, thumbLocation.LocalId, thumbLocation.Secret); var previewLocation = new TLFileLocation { DCId = new TLInt(0), VolumeId = TLLong.Random(), LocalId = TLInt.Random(), Secret = TLLong.Random(), }; var previewFileName = String.Format("{0}_{1}_{2}.jpg", previewLocation.VolumeId, previewLocation.LocalId, previewLocation.Secret); var previewFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(previewFileName, CreationCollisionOption.ReplaceExisting); var previewBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(preview.Size)); var iBuf = await preview.ReadAsync(previewBuffer, previewBuffer.Capacity, InputStreamOptions.None); var filePreview = new TLPhotoSize { W = new TLInt((int)preview.OriginalWidth), H = new TLInt((int)preview.OriginalHeight), Size = new TLInt((int)preview.Size), Type = TLString.Empty, Location = previewLocation, }; Photo thumb; using (var previewStream = await previewFile.OpenAsync(FileAccessMode.ReadWrite)) { await previewStream.WriteAsync(iBuf); thumb = await ChooseAttachmentViewModel.ResizeJpeg(previewStream, 90, thumbFileName); } var thumbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(thumbFileName, CreationCollisionOption.ReplaceExisting); var iBuf2 = thumb.Bytes.AsBuffer(); using (var thumbStream = await thumbFile.OpenAsync(FileAccessMode.ReadWrite)) { await thumbStream.WriteAsync(iBuf2); } var fileThumb = new TLPhotoSize { W = new TLInt(thumb.Width), H = new TLInt(thumb.Height), Size = new TLInt(thumb.Bytes.Length), Type = new TLString("s"), Location = thumbLocation, }; return(new Tuple <TLPhotoSizeBase, TLPhotoSizeBase>(filePreview, fileThumb)); } catch (Exception ex) { Telegram.Api.Helpers.Execute.ShowDebugMessage("GetFilePreviewAndThumbAsync exception " + ex); } return(new Tuple <TLPhotoSizeBase, TLPhotoSizeBase>(null, null)); }