From c0d002c46b9ff5e23eed07cb023baa3ce3e10544 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Mon, 3 Jun 2024 14:47:31 +0200 Subject: [PATCH] Luca's attempt at fixing app --- .../fitbot/ui/activities/FitnessActivity.java | 2 +- .../ui/components/ExerciseStatusElement.java | 66 ++++++++++--------- .../util/processing/InputProcessor.java | 4 ++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java index 1d74427..7d970db 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java @@ -162,7 +162,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall Pepper.provideContext(null, this.getClass()); // Remove the context (unavailable) // Go to the main screen - NavigationManager.navigateToActivity(this, MainActivity.class); +// NavigationManager.navigateToActivity(this, MainActivity.class); } @Override diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java index c8b112b..e8b2351 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/ExerciseStatusElement.java @@ -86,40 +86,9 @@ public class ExerciseStatusElement extends View implements IInputHandler { Pepper.say(STARTING_PHRASES[(int) Math.floor(Math.random() * STARTING_PHRASES.length)]); // Handler that is called every time the motion processor receives new data. - this.motionProcessor.setInputHandler((rotationVector, deviceId) -> { - Log.i("MotionProcessor", "Rotation vector received: " + rotationVector); - Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(deviceId, this.motionProcessor.secondsPassed())); - // Check whether the current exercise has been completed. - // This is determined by the duration of the exercise, and the amount of time that has passed. - // The duration of the exercise originates from the database, and is stored in seconds. - // Whenever 'useExercise' is called, the timer resets and this method will be called again. - if (this.motionProcessor.hasFinished()) { - // If for some reason the parent activity is not defined, - // move back to the main screen. - if (this.parentActivity == null) { - // Move to main screen - NavigationManager.navigateToActivity(getContext(), MainActivity.class); - return; - } - // Move on to the next exercise, or finish. - if (this.exerciseCount > 0) { - this.exerciseCount--; - this.parentActivity.fetchExerciseAsync((newExercise) -> { - this.motionProcessor.useExercise(newExercise); - // Whenever the database retrieval failed, we return to the main screen. - }, (failed) -> { - // Move to main screen - NavigationManager.navigateToActivity(parentActivity, MainActivity.class); - }); - } else { - // Finish the exercise. - NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class); - } - } - }); } /** @@ -130,6 +99,7 @@ public class ExerciseStatusElement extends View implements IInputHandler { public void setExercise(Exercise exercise) { this.motionProcessor.useExercise(exercise); this.exercise = exercise; + Log.i("MotionProcessor", "Updating exercise in ExerciseStatusElement"); } @Override @@ -157,6 +127,40 @@ public class ExerciseStatusElement extends View implements IInputHandler { @Override public void accept(Vector3f rotationVector, int sensorId) { + Log.i("MotionProcessor", "Rotation vector received: " + rotationVector); + Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(sensorId, this.motionProcessor.secondsPassed())); + + // Check whether the current exercise has been completed. + // This is determined by the duration of the exercise, and the amount of time that has passed. + // The duration of the exercise originates from the database, and is stored in seconds. + // Whenever 'useExercise' is called, the timer resets and this method will be called again. + if (this.motionProcessor.hasFinished() && !this.motionProcessor.isRecording()) { + // If for some reason the parent activity is not defined, + // move back to the main screen. + if (this.parentActivity == null) { + // Move to main screen + Log.i("MotionProcessor", "Parent activity was null."); + NavigationManager.navigateToActivity(getContext(), MainActivity.class); + return; + } + // Move on to the next exercise, or finish. + if (this.exerciseCount > 0) { + this.exerciseCount--; + this.parentActivity.fetchExerciseAsync((newExercise) -> { + this.motionProcessor.useExercise(newExercise); + + // Whenever the database retrieval failed, we return to the main screen. + }, (failed) -> { + // Move to main screen + Log.i("MotionProcessor", "Failed to fetch exercise from database"); + NavigationManager.navigateToActivity(parentActivity, MainActivity.class); + }); + } else { + // Finish the exercise. + Log.i("MotionProcessor", "Exercise has finished"); + NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class); + } + } } } diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java index 66c6d94..52c8524 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java @@ -335,4 +335,8 @@ public class InputProcessor { public float secondsPassed() { return (float) secondsPassed; } + + public boolean isRecording() { + return this.recordingMovement; + } }