From 5526eb435b8017448d6e4390e08049a51ac55a67 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Jun 2022 11:55:03 +0200 Subject: [PATCH] Wire activity/fragment back --- .../main/java/eu/faircode/email/ActivityBase.java | 3 +++ .../main/java/eu/faircode/email/FragmentBase.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 9cb8a8b115..5340be1a68 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -750,6 +750,9 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == android.R.id.home) { + // Delegate to fragment first + if (super.onOptionsItemSelected(item)) + return true; performBack(); return true; } diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index ee16f8521f..90ee0d8328 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -40,6 +40,7 @@ import android.os.Handler; import android.os.ResultReceiver; import android.text.TextUtils; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; @@ -315,6 +316,18 @@ public class FragmentBase extends Fragment { lbm.unregisterReceiver(receiver); } + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + FragmentActivity activity = getActivity(); + if (activity != null) { + activity.getOnBackPressedDispatcher().onBackPressed(); + return true; + } + } + return super.onOptionsItemSelected(item); + } + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { EntityLog.log(getContext(), "Result class=" + this.getClass().getSimpleName() +