Skip to content

Commit

Permalink
Merge pull request #7859 from thunderbird/onBackPressed_1
Browse files Browse the repository at this point in the history
Remove `onBackPressed()` usage [1/x]
  • Loading branch information
cketti committed May 27, 2024
2 parents b91b356 + 6a14c95 commit e1ac98f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ public void onResume() {


@Override
public void onBackPressed() {
public void onStop() {
// TODO: Instead of saving the changes when the activity is stopped, save the changes (in a background thread)
// immediately after modifying the list of identities.
saveIdentities();
super.onBackPressed();
super.onStop();
}

private void saveIdentities() {
if (mIdentitiesChanged) {
mAccount.setIdentities(identities);
Preferences.getPreferences().saveAccount(mAccount);
}
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
finish();
return true;
}

Expand All @@ -133,9 +133,11 @@ private void saveSettings() {
}

@Override
public void onBackPressed() {
public void onStop() {
// TODO: Instead of saving the changes when the activity is stopped, add buttons to explicitly save or discard
// changes.
saveSettings();
super.onBackPressed();
super.onStop();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class ManageFoldersActivity : K9Activity() {
}

override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp() || super.onSupportNavigateUp() || navigateUpBySimulatedBackButtonPress()
return navController.navigateUp() || super.onSupportNavigateUp() || finishActivity()
}

private fun navigateUpBySimulatedBackButtonPress(): Boolean {
onBackPressed()
private fun finishActivity(): Boolean {
finish()
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class SettingsActivity : K9Activity() {
}

override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp() || super.onSupportNavigateUp() || navigateUpBySimulatedBackButtonPress()
return navController.navigateUp() || super.onSupportNavigateUp() || finishActivity()
}

private fun navigateUpBySimulatedBackButtonPress(): Boolean {
onBackPressed()
private fun finishActivity(): Boolean {
finish()
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AccountSettingsActivity : K9Activity(), OnPreferenceStartScreenCallback {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,13 @@ class GeneralSettingsActivity : K9Activity(), OnPreferenceStartScreenCallback, S

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}

return super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
if (!searchPreferenceActionView.cancelSearch()) {
super.onBackPressed()
}
}

override fun onPreferenceStartScreen(
caller: PreferenceFragmentCompat,
preferenceScreen: PreferenceScreen,
Expand Down

0 comments on commit e1ac98f

Please sign in to comment.