Skip to content

Commit

Permalink
Fix button state on init
Browse files Browse the repository at this point in the history
  • Loading branch information
kripper committed Dec 7, 2024
1 parent 22d9496 commit a091871
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/src/main/java/sq/rogue/rosettadrone/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -782,18 +782,8 @@ protected void onCreate(Bundle savedInstanceState) {
// SafeMode button
mBtnSafety = findViewById(R.id.btn_safety);
mBtnSafety.setOnClickListener(v -> {
Drawable connectedDrawable;
stat = !stat;
if (stat) {
connectedDrawable = getResources().getDrawable(R.drawable.ic_lock_outline_secondary_24dp, null);
mBtnSafety.setBackground(connectedDrawable);
findViewById(R.id.btn_takeoff).setVisibility(View.INVISIBLE);
} else {
connectedDrawable = getResources().getDrawable(R.drawable.ic_lock_open_black_24dp, null);
mBtnSafety.setBackground(connectedDrawable);
findViewById(R.id.btn_takeoff).setVisibility(View.VISIBLE);
}
mModel.setSafetyEnabled(stat);
setSafeMode(stat);
NotificationHandler.notifySnackbar(findViewById(R.id.snack),
(mModel.isSafetyEnabled()) ? R.string.safety_on : R.string.safety_off, LENGTH_LONG);
});
Expand All @@ -810,21 +800,29 @@ protected void onCreate(Bundle savedInstanceState) {
pluginManager.start();

if(RDApplication.isTestMode) {
setSafeMode(false);
mModel.mMotorsArmed = true;
onDroneConnected();

} else {
// Click on SafeMode button (enable SafeMode)
Handler mTimerHandler = new Handler(Looper.getMainLooper());
mTimerHandler.postDelayed(enableSafeMode, 3000);
setSafeMode(true);
}
}

private Runnable enableSafeMode = new Runnable() {
@Override
public void run() {
mBtnSafety.callOnClick();
private void setSafeMode(boolean enabled) {
Drawable connectedDrawable;
if (enabled) {
connectedDrawable = getResources().getDrawable(R.drawable.ic_lock_outline_secondary_24dp, null);
mBtnSafety.setBackground(connectedDrawable);
findViewById(R.id.btn_takeoff).setVisibility(View.INVISIBLE);
} else {
connectedDrawable = getResources().getDrawable(R.drawable.ic_lock_open_black_24dp, null);
mBtnSafety.setBackground(connectedDrawable);
findViewById(R.id.btn_takeoff).setVisibility(View.VISIBLE);
}
};

mModel.setSafetyEnabled(enabled);
}

@Override
protected void onNewIntent(@NonNull Intent intent) {
Expand Down

0 comments on commit a091871

Please sign in to comment.