Migrate to from OnBackPressed to OnBackPressedDispatcher

Closes: https://github.com/CatimaLoyalty/Android/issues/1498

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-10-01 18:51:06 +05:30
parent 2344b6367f
commit aea1ea0cbf
7 changed files with 52 additions and 43 deletions

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
@@ -133,6 +134,13 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
// this setText is here because content_main.xml is reused from main activity
noGroupCardsText.setText(getResources().getText(R.string.noGiftCardsGroup));
updateLoyaltyCardList();
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
leaveWithoutSaving();
}
});
}
private ArrayList<Integer> adapterStateToIntegerArray(HashMap<Integer, Boolean> adapterState) {
@@ -210,14 +218,9 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
}
}
@Override
public void onBackPressed() {
leaveWithoutSaving();
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
getOnBackPressedDispatcher().onBackPressed();
return true;
}