internal static void OpenPhotoPreviewWindow(Photo photo, List <Photo> photoList, SearchResult searchResult, Window ownerWindow) { var photoPreview = new PhotoPreview(photo, photoList, searchResult) { Owner = ownerWindow }; photoPreview.Show(); }
void ReleaseDesignerOutlets() { if (BaseView != null) { BaseView.Dispose(); BaseView = null; } if (PhotoPreview != null) { PhotoPreview.Dispose(); PhotoPreview = null; } if (ResizePhotoButton != null) { ResizePhotoButton.Dispose(); ResizePhotoButton = null; } if (SelectPhotoButton != null) { SelectPhotoButton.Dispose(); SelectPhotoButton = null; } }
async void UploadButton_Clicked(object sender, System.EventArgs e) { if (PhotoPreview.Source == null) { return; } LoadingOverlay.IsVisible = true; LoadingAnimation.Play(); using (var stream = new MemoryStream()) { var croppedImage = await PhotoPreview.GetImageAsJpegAsync(); await croppedImage.CopyToAsync(stream); stream.Position = 0; // Upload photo var success = await viewModel.UploadPhoto(stream, file.Path); if (success) { PhotoPreview.Source = null; viewModel.Caption = string.Empty; // Navigate back to categories page App.AppShell.SelectedItem = null; // Hack: Xamarin.Forms Bug does not allow the same navigation twice otherwise App.AppShell.SelectedItem = App.AppShell.Children.First(); Analytics.TrackEvent("Photo uploaded"); } } LoadingOverlay.IsVisible = false; LoadingAnimation.Pause(); }
public PhotoPreviewViewModel(PhotoPreview photoPreviewWindow, Photo photo, List <Photo> photoList, SearchResult searchResult) { if (photoList is null) { throw new ArgumentNullException($"{photoList} is null"); } PreviewPhoto = new ReactiveProperty <Photo>(photo).AddTo(Disposable); _photoList = photoList; _previewPhotoIndex = _photoList.IndexOf(photo); Image = new ReactiveProperty <BitmapImage>(ImageHelper.GetNowLoadingImage()).AddTo(Disposable); PreviewPhoto.Subscribe(async p => { var task = new Task(() => { var filePath = p?.FilePath ?? string.Empty; if (!string.IsNullOrEmpty(filePath)) { try { Image.Value = ImageHelper.LoadBitmapImage(p.FilePath); } catch (IOException e) { Image.Value = ImageHelper.GetFailedImage(); } } }); task.Start(TaskScheduler.FromCurrentSynchronizationContext()); }); PreviousCommand = new ReactiveCommand().AddTo(Disposable); NextCommand = new ReactiveCommand().AddTo(Disposable); UserList = PreviewPhoto.SelectMany(p => p?.MetaData?.Users ?? Enumerable.Empty <User>()) .ToReadOnlyReactiveCollection( onReset: Observable .Merge( PreviousCommand, NextCommand) .Select(_ => Unit.Default)) .AddTo(Disposable); WorldName = PreviewPhoto.Select(p => "World: " + p?.MetaData?.World ?? string.Empty).ToReadOnlyReactiveProperty().AddTo(Disposable); PhotographerName = PreviewPhoto.Select(p => "Photographer: " + p?.MetaData?.Photographer ?? string.Empty).ToReadOnlyReactiveProperty().AddTo(Disposable); PhotoDateTime = PreviewPhoto.Select(p => p?.MetaData?.Date?.ToString("yyyy/MM/dd HH:mm:ss", new CultureInfo("en-US")) ?? string.Empty).ToReadOnlyReactiveProperty().AddTo(Disposable); PhotoNumber = PreviewPhoto.Select(_ => $"{_previewPhotoIndex + 1}/{_photoList.Count}").ToReadOnlyReactiveProperty().AddTo(Disposable); UseTestFunction = new ReactiveProperty <bool>().AddTo(Disposable); UseTestFunction.Value = Setting.Instance.Data.UseTestFunction; OpenTwitterCommand = new ReactiveCommand <string>().AddTo(Disposable); OpenExplorerCommand = new ReactiveCommand().AddTo(Disposable); RotateL90Command = new ReactiveCommand().AddTo(Disposable); RotateR90Command = new ReactiveCommand().AddTo(Disposable); Rotate180Command = new ReactiveCommand().AddTo(Disposable); FlipHorizontalCommand = new ReactiveCommand().AddTo(Disposable); ShareToTwitterCommand = new ReactiveCommand().AddTo(Disposable); UserSelectCommand = new ReactiveCommand <User>().AddTo(Disposable); WorldSelectCommand = new ReactiveCommand <string>().AddTo(Disposable); DateSelectCommand = new ReactiveCommand <DateTime>().AddTo(Disposable); WindowCloseCommand = new ReactiveCommand <PhotoPreview>().AddTo(Disposable); PreviousCommand.Subscribe(() => { Image.Value = ImageHelper.GetNowLoadingImage(); _previewPhotoIndex = (_previewPhotoIndex - 1 + _photoList.Count) % _photoList.Count; PreviewPhoto.Value = _photoList[_previewPhotoIndex]; }).AddTo(Disposable); NextCommand.Subscribe(() => { Image.Value = ImageHelper.GetNowLoadingImage(); _previewPhotoIndex = (_previewPhotoIndex + 1) % _photoList.Count; PreviewPhoto.Value = _photoList[_previewPhotoIndex]; }).AddTo(Disposable); OpenTwitterCommand.Subscribe(WindowHelper.OpenTwitterWithScreenName).AddTo(Disposable); OpenExplorerCommand.Subscribe(() => WindowHelper.OpenFileExplorer(PreviewPhoto.Value.FilePath)).AddTo(Disposable); RotateL90Command.Subscribe(() => ImageProcessing(PreviewPhoto.Value.FilePath, PreviewPhoto.Value.MetaData, searchResult, ImageHelper.RotateLeft90AndSave)).AddTo(Disposable); RotateR90Command.Subscribe(() => ImageProcessing(PreviewPhoto.Value.FilePath, PreviewPhoto.Value.MetaData, searchResult, ImageHelper.RotateRight90AndSave)).AddTo(Disposable); Rotate180Command.Subscribe(() => ImageProcessing(PreviewPhoto.Value.FilePath, PreviewPhoto.Value.MetaData, searchResult, ImageHelper.Rotate180AndSave)).AddTo(Disposable); FlipHorizontalCommand.Subscribe(() => ImageProcessing(PreviewPhoto.Value.FilePath, PreviewPhoto.Value.MetaData, searchResult, ImageHelper.FilpHorizontalAndSave)).AddTo(Disposable); ShareToTwitterCommand.Subscribe(() => WindowHelper.OpenShareDialog(PreviewPhoto.Value, photoPreviewWindow)).AddTo(Disposable); UserSelectCommand.Subscribe(u => searchResult.SearchedUserName.Value = u.UserName).AddTo(Disposable); WorldSelectCommand.Subscribe(w => searchResult.SearchedWorldName.Value = w).AddTo(Disposable); DateSelectCommand.Subscribe(d => searchResult.SearchedDate.Value = d).AddTo(Disposable); WindowCloseCommand.Subscribe(w => w.Close()).AddTo(Disposable); }