From ecc9bc2bf33b7631516f2115477356681241e667 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 20 Feb 2022 10:20:44 +0100 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/FragmentBase.java | 8 ++++++++ app/src/main/java/eu/faircode/email/FragmentCompose.java | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 9108d70924..3f24f3d0d5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -83,6 +83,14 @@ public class FragmentBase extends Fragment { static final String ACTION_STORE_ATTACHMENT = BuildConfig.APPLICATION_ID + ".STORE_ATTACHMENT"; static final String ACTION_STORE_ATTACHMENTS = BuildConfig.APPLICATION_ID + ".STORE_ATTACHMENTS"; + protected ActionBar getSupportActionBar() { + FragmentActivity activity = getActivity(); + if (activity instanceof ActivityBase) + return ((ActivityBase) activity).getSupportActionBar(); + else + return null; + } + protected void setTitle(int resid) { setTitle(getString(resid)); } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 0440becd0a..0943754298 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -108,6 +108,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SwitchCompat; @@ -1572,11 +1573,10 @@ public class FragmentCompose extends FragmentBase { menu.findItem(R.id.menu_zoom).setTitle(ssbZoom); PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom), false); - FragmentActivity activity = getActivity(); - Context tcontext = (activity instanceof ActivityBase - ? ((ActivityBase) activity).getSupportActionBar().getThemedContext() : context); + ActionBar actionBar = getSupportActionBar(); + Context actionBarContext = (actionBar == null ? context : actionBar.getThemedContext()); int colorEncrypt = Helper.resolveColor(context, R.attr.colorEncrypt); - int colorActionForeground = Helper.resolveColor((tcontext), android.R.attr.textColorPrimary); + int colorActionForeground = Helper.resolveColor(actionBarContext, android.R.attr.textColorPrimary); View v = menu.findItem(R.id.menu_encrypt).getActionView(); ImageButton ib = v.findViewById(R.id.button);