fix nullobject reference (luca) and made it so the repetitioncount resets properly

This commit is contained in:
2024-06-10 11:46:52 +02:00
parent 2453b8581f
commit 63a3e6870e
2 changed files with 24 additions and 22 deletions

View File

@@ -35,6 +35,7 @@ import com.example.fitbot.util.processing.InputProcessor;
public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks {
public static int progress = 1;
// Private fields for the FitnessActivity class.
private InputProcessor motionProcessor;
private Exercise currentExercise;
@@ -42,7 +43,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// Progress circle for the exercises
private ProgressBar progressCircle;
private TextView progressText;
private int progress = 1;
private final int maxProgress = 10;
// Exercise status element data
@@ -78,7 +78,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
QiSDK.register(this, this);
setContentView(R.layout.activity_fitness);
videoView = findViewById(R.id.videoView);
ExerciseManager.TOTAL_REPETITIONS_PERFORMED = 0;
// Fill empty objects with exercise data
this.exerciseNameTextView = findViewById(R.id.textViewFitnessTitle);
this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription);
@@ -190,6 +190,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
if (progress >= 10) {
runOnUiThread(() -> NavigationManager.navigateToActivity(this, EndScreenActivity.class));
InputProcessor.exercisesRemaining = 1;
progress = 1;
}
}

View File

@@ -25,7 +25,7 @@ import java.util.List;
public class InputProcessor {
private List<Vector3f>[] selfRotationVectorPaths = null;
private List<Vector3f>[] selfRotationVectorPaths = new ArrayList[2];
// Relative path of the motion data
private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data
@@ -78,11 +78,10 @@ public class InputProcessor {
* Constructor for the motion processor.
*/
public InputProcessor(FitnessActivity parentActivity) {
this.parentActivity = parentActivity;
// Initialize each ArrayList in the array
this.selfRotationVectorPaths[0] = new ArrayList<>();
this.selfRotationVectorPaths[1] = new ArrayList<>();
this.parentActivity = parentActivity;
// Initialize each ArrayList in the array
}
/**
@@ -120,6 +119,7 @@ public class InputProcessor {
if (this.totalChecks == 0 || this.selfRotationVectorPaths == null
|| this.selfRotationVectorPaths.length == 0
|| this.selfRotationVectorPaths[0] == null
|| this.selfRotationVectorPaths[0].size() == 0
|| this.selfRotationVectorPaths[1].size() == 0)
continue;
@@ -134,8 +134,7 @@ public class InputProcessor {
this.checksPerformed++;
if (this.checksPerformed >= this.totalChecks)
{
if (this.checksPerformed >= this.totalChecks) {
this.checksPerformed = 0;
this.exercisesRemaining--;
acquireExercise();
@@ -244,9 +243,11 @@ public class InputProcessor {
* incoming connections.
*/
public void startListening() {
this.selfRotationVectorPaths = new ArrayList[]{new ArrayList(), new ArrayList()};
// Create socket server
this.server = WebServer.createServer();
//
FitnessActivity.progress = 1;
Log.i("MotionProcessor", "Listening for incoming connections.");
// Check if the socket
@@ -264,8 +265,7 @@ public class InputProcessor {
*/
private void acquireExercise() {
if ( this.exercisesRemaining <= 0)
{
if (this.exercisesRemaining <= 0) {
Log.i("InputProcessor", "Exercises finished");
this.parentActivity.runOnUiThread(() -> {
NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class);
@@ -454,4 +454,5 @@ public class InputProcessor {
}
return true; // Return true for faulty movement if only up or down movement is detected
}}
}
}