Skip to content

Commit

Permalink
fix for race condition in passwor reset
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 5, 2023
1 parent 84697f9 commit fe626e5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/co/tinode/tindroid/PasswordResetFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
}).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
Log.w(TAG, "Failed to connect", err);
parent.runOnUiThread(() -> {
if (parent.isFinishing() || parent.isDestroyed() || !isVisible()) {
return;
}

parent.findViewById(R.id.requestCode).setEnabled(false);
parent.findViewById(R.id.haveCode).setEnabled(false);
Toast.makeText(parent, R.string.unable_to_use_service, Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -185,6 +185,10 @@ private void clickRequest(View button) {
@Override
public PromisedReply<ServerMessage> onSuccess(ServerMessage msg) {
parent.runOnUiThread(() -> {
if (parent.isFinishing() || parent.isDestroyed() || !isVisible()) {
return;
}

readyToEnterCode();
Toast.makeText(parent, R.string.confirmation_code_sent, Toast.LENGTH_SHORT).show();
});
Expand All @@ -195,6 +199,10 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage msg) {
new PromisedReply.FailureListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onFailure(Exception err) {
if (parent.isFinishing() || parent.isDestroyed() || !isVisible()) {
return null;
}

// Something went wrong.
parent.reportError(err, (Button) button, 0, R.string.invalid_or_unknown_credential);
return null;
Expand Down Expand Up @@ -230,9 +238,10 @@ private void clickConfirm(View button) {
.thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
if (parent.isFinishing() || parent.isDestroyed()) {
if (parent.isFinishing() || parent.isDestroyed() || !isVisible()) {
return null;
}

parent.runOnUiThread(() -> {
Toast.makeText(parent, R.string.password_changed, Toast.LENGTH_LONG).show();
parent.getSupportFragmentManager().popBackStack();
Expand All @@ -243,6 +252,10 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
.thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public <E extends Exception> PromisedReply<ServerMessage> onFailure(E err) {
if (parent.isFinishing() || parent.isDestroyed() || !isVisible()) {
return null;
}

parent.reportError(err, (Button) button, 0, R.string.action_failed);
return null;
}
Expand Down

0 comments on commit fe626e5

Please sign in to comment.