Use getOnBackPressedDispatcher().addCallback in EditCommentActivity.

This commit is contained in:
Docile-Alligator 2025-07-04 18:27:04 -04:00
parent 341104e37a
commit caa90cf117

View File

@ -13,6 +13,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
@ -219,6 +220,22 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
Utils.showKeyboard(this, new Handler(), binding.commentEditTextEditCommentActivity);
Giphy.INSTANCE.configure(this, APIUtils.GIPHY_GIF_API_KEY);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (isSubmitting) {
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_edit_comment_detail);
} else {
if (binding.commentEditTextEditCommentActivity.getText().toString().equals(mCommentContent)) {
setEnabled(false);
triggerBackPress();
} else {
promptAlertDialog(R.string.discard, R.string.discard_detail);
}
}
}
});
}
@Override
@ -271,7 +288,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
editComment();
return true;
} else if (item.getItemId() == android.R.id.home) {
onBackPressed();
triggerBackPress();
return true;
}
return false;
@ -385,19 +402,6 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
outState.putParcelable(GIPHY_GIF_STATE, giphyGif);
}
@Override
public void onBackPressed() {
if (isSubmitting) {
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_edit_comment_detail);
} else {
if (binding.commentEditTextEditCommentActivity.getText().toString().equals(mCommentContent)) {
finish();
} else {
promptAlertDialog(R.string.discard, R.string.discard_detail);
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();