Skip to content

Commit

Permalink
replace deprecated onBackPressed() callback
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 8, 2023
1 parent de756d0 commit 65a7536
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions app/src/main/java/app/attestation/auditor/AttestationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;

import androidx.activity.OnBackPressedCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -303,6 +304,22 @@ public boolean onPreDraw() {
}
});

getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (stage == Stage.AuditeeResults || stage == Stage.Auditor ||
stage == Stage.Result) {
auditeeSerializedAttestation = null;
auditorChallenge = null;
stage = Stage.None;
binding.content.textview.setText("");
backgroundResource = 0;
recreate();
return;
}
}
});

RemoteVerifyJob.restore(this);
}

Expand Down Expand Up @@ -592,19 +609,4 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
if (stage == Stage.AuditeeResults || stage == Stage.Auditor ||
stage == Stage.Result) {
auditeeSerializedAttestation = null;
auditorChallenge = null;
stage = Stage.None;
binding.content.textview.setText("");
backgroundResource = 0;
recreate();
return;
}
super.onBackPressed();
}
}

0 comments on commit 65a7536

Please sign in to comment.