protected async override void OnFileActivated(FileActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; var thisIsANewFrame = rootFrame == null; if (thisIsANewFrame) { await WorkoutManager.LoadWorkouts(); rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; } if (WorkoutEditor.workout != null) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed WorkoutManager.SaveWorkout(WorkoutEditor.workout); WorkoutEditor.workout = null; #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } if (args.Files.Count == 1) { var success = await WorkoutManager.AddWorkout(args.Files[0] as StorageFile); if (success) { var workout = WorkoutManager.Workouts.Last(); rootFrame.Navigate(typeof(MainPage), workout); } else { rootFrame.Navigate(typeof(MainPage)); } } else { var successOnce = false; foreach (var file in args.Files) { var passed = await WorkoutManager.AddWorkout(file as StorageFile); if (passed) { successOnce = true; } } if (successOnce) { rootFrame.Navigate(typeof(MainPage), new UselessPotato()); } } Window.Current.Activate(); }
private async void GotoImport() { if (squaresCentered && !importing) { importing = true; ElementSoundPlayer.Play(ElementSoundKind.Invoke); var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; picker.FileTypeFilter.Add(".kwiw"); var file = await picker.PickSingleFileAsync(); if (file != null) { var fileResult = await WorkoutManager.AddWorkout(file); if (fileResult == false) { MessageDialog messageDialog = new MessageDialog("Workout couldn't be imported! SAD SAD SAD SAADDDDD SAD") { DefaultCommandIndex = 0, CancelCommandIndex = 0 }; messageDialog.Commands.Add(new UICommand("Okay :(")); await messageDialog.ShowAsync(); } else { var newWorkout = WorkoutManager.Workouts.Last(); AddedANewDamnWorkoutToTheMix(newWorkout); PostImportSelect(newWorkout, true); } } else { ElementSoundPlayer.Play(ElementSoundKind.Hide); } importing = false; } }