private async void DeletionPrompt()
        {
            if (deleting)
            {
                return;
            }
            if (!squaresCentered)
            {
                deleting = true;
                setButtonsEnabled(false);
                MessageDialog messageDialog = new MessageDialog(
                    "Are you sure you want to delete this? There's an old adage that goes \"once you do this you can't undo it\"")
                {
                    DefaultCommandIndex = 0,
                    CancelCommandIndex  = 1,
                };
                messageDialog.Commands.Add(new UICommand("Yes. Leave me alone!", async(command) => {
                    await WorkoutManager.DeleteWorkout(presentedSquareIndex);
                    DeleteAWorkoutRestInPeace(presentedSquareIndex);
                    ClearPresentSquare(playSound: false);
                    deleting = false;
                }));
                messageDialog.Commands.Add(new UICommand("No! Please, Daddy don't delete it!", (command) => {
                    deleting = false;
                    setButtonsEnabled(true);
                    FocusManager.TryMoveFocus(FocusNavigationDirection.Previous);
                }));

                await messageDialog.ShowAsync();
            }
        }
Exemple #2
0
        private void GoBackAndNibbaRigSomeShit()
        {
            ((App)Application.Current).AWeirdPlaceForAWorkoutObjectThatIsViolatingCodingPrincipals = workout;
            if (workout.Name == null)
            {
                if (string.IsNullOrEmpty(processedNameBox))
                {
                    workout.Name = workoutDefaultName;
                }
                else
                {
                    workout.Name = processedNameBox;
                }
            }
            else
            {
                if (processedNameBox == string.Empty)
                {
                    workout.Name = workoutDefaultName;
                }
                else if (processedNameBox != null)
                {
                    workout.Name = processedNameBox;
                }
            }
            Frame.GoBack();
            var workoutToSave = workout;

            workout = null;
            loaded  = false;
                        #pragma warning disable CS4014
            WorkoutManager.SaveWorkout(workoutToSave);
                        #pragma warning restore CS4014
        }
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            if (WorkoutEditor.workout != null)
            {
                await WorkoutManager.SaveWorkout(WorkoutEditor.workout);
            }
            deferral.Complete();
        }
        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 GotoExport()
        {
            if (!squaresCentered && !exporting)
            {
                exporting = true;
                var exportWorkout = WorkoutManager.Workouts[presentedSquareIndex];
                setButtonsEnabled(false);
                var savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                savePicker.FileTypeChoices.Add("Keep with it Workout File", new List <string>()
                {
                    ".kwiw"
                });
                savePicker.SuggestedFileName = WorkoutManager.Workouts[presentedSquareIndex].Name;

                StorageFile file = await savePicker.PickSaveFileAsync();

                if (file != null)
                {
                    CachedFileManager.DeferUpdates(file);
                    var exportPassed = await WorkoutManager.ExportWorkout(file, exportWorkout, false);

                    var status = FileUpdateStatus.Incomplete;
                    if (exportPassed)
                    {
                        status = await CachedFileManager.CompleteUpdatesAsync(file);
                    }
                    if (status != FileUpdateStatus.Complete)
                    {
                        MessageDialog messageDialog = new MessageDialog("Workout couldn't be exported! SAD SAD SAD SAADDDDD SAD")
                        {
                            DefaultCommandIndex = 0,
                            CancelCommandIndex  = 0
                        };
                        messageDialog.Commands.Add(new UICommand("Okay :("));
                        await messageDialog.ShowAsync();
                    }
                }
                else
                {
                    ElementSoundPlayer.Play(ElementSoundKind.Hide);
                }

                setButtonsEnabled(true);
                exporting = false;
            }
        }
Exemple #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!loaded)
            {
                if (e.Parameter != null && e.Parameter is Workout)
                {
                    workout      = e.Parameter as Workout;
                    nameBox.Text = workout.Name;
                }
                else
                {
                    workout = new Workout();
                    WorkoutManager.Workouts.Add(workout);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    WorkoutManager.SaveWorkout(workout);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    ((App)Application.Current).WasThatComplicatedNavigationalMessFromANewWorkout = true;
                }

                workoutDefaultName   = $"Workout {WorkoutManager.Workouts.IndexOf(workout)+1}";
                listView.ItemsSource = workout.Segments;

                if (workout.Name == null)
                {
                    nameBox.Text = workoutDefaultName;
                    workout.Name = workoutDefaultName;
                }
                nameBox.PlaceholderText = workoutDefaultName;

                nameBox.SelectionStart  = nameBox.MaxLength - 1;
                nameBox.SelectionLength = 0;


                loaded = true;
            }
            else if (PendingDeletion != null)
            {
                workout.Segments.Remove(PendingDeletion);

                PendingDeletion = null;
            }
            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyPressEvent;

            var currentView = SystemNavigationManager.GetForCurrentView();
            currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            currentView.BackRequested += CurrentView_BackRequested;
        }
Exemple #7
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            Window.Current.CoreWindow.KeyDown -= CoreWindow_KeyPressEvent;

            timer.Stop();
            timer = null;

            var currentView = SystemNavigationManager.GetForCurrentView();

            currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            currentView.BackRequested -= CurrentView_BackRequested;

            if (completedWorkout)
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                WorkoutManager.SaveWorkout(currentWorkout);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
        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;
            }
        }
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                await WorkoutManager.LoadWorkouts();

                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;
                Window.Current.Content      = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }

                Window.Current.Activate();
            }
        }
Exemple #10
0
        private async void OpenImagePrompt()
        {
            if (openingOrProcessingImage || imageLoading)
            {
                return;
            }
            setPictureLabelText("Selecting image");
            openingOrProcessingImage = true;
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.FileTypeFilter.Add(".jpeg");
            fileOpenPicker.FileTypeFilter.Add(".gif");
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            ElementSoundPlayer.Play(ElementSoundKind.Show);
            var file = await fileOpenPicker.PickSingleFileAsync();

            if (file == null)
            {
                if (stillOnThePage)
                {
                    UpdatePicture();
                    openingOrProcessingImage = false;
                }
                return;
            }
            setPictureLabelText("Loading new image");
            SoftwareBitmap softwareBitmap;

            try {
                softwareBitmap = await WorkoutManager.GetBitMapFromFile(file);
            } catch {
                softwareBitmap = null;
            }

            if (softwareBitmap != null)
            {
                setPictureLabelText("Processing new image");
                segment.PropertyChanged += Segment_PropertyChanged;
                segment.SetImage(softwareBitmap);
                imageLoading = true;
            }
            else
            {
                ElementSoundPlayer.Play(ElementSoundKind.Show);
                MessageDialog messageDialog = new MessageDialog("Error opening new image. You know what sucks?")
                {
                    DefaultCommandIndex = 0,
                    CancelCommandIndex  = 0
                };
                messageDialog.Commands.Add(new UICommand("Well, this sucks?"));
                await messageDialog.ShowAsync();
            }
            ElementSoundPlayer.Play(ElementSoundKind.Hide);
            if (stillOnThePage)
            {
                openingOrProcessingImage = false;
                UpdatePicture();
            }
        }