From 1083865e773beab41b0e8c3b361edbade8f24567 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 17 May 2024 12:33:50 +0200 Subject: [PATCH] Switched to app bar --- .../java/eu/faircode/email/ActivityAMP.java | 4 +- .../eu/faircode/email/ActivityAnswer.java | 4 +- .../java/eu/faircode/email/ActivityBase.java | 26 +++++++ .../java/eu/faircode/email/ActivityClear.java | 3 +- .../java/eu/faircode/email/ActivityCode.java | 4 +- .../eu/faircode/email/ActivityCompose.java | 2 - .../java/eu/faircode/email/ActivityDMARC.java | 6 +- .../java/eu/faircode/email/ActivityDSN.java | 6 +- .../java/eu/faircode/email/ActivityEML.java | 6 +- .../java/eu/faircode/email/ActivityError.java | 3 +- .../java/eu/faircode/email/ActivitySetup.java | 3 - .../eu/faircode/email/ActivitySignature.java | 6 +- .../java/eu/faircode/email/ActivityView.java | 2 - .../eu/faircode/email/ActivityWidget.java | 3 +- .../eu/faircode/email/ActivityWidgetSync.java | 3 +- .../faircode/email/ActivityWidgetUnified.java | 3 +- .../java/eu/faircode/email/FragmentBase.java | 9 ++- .../eu/faircode/email/FragmentCompose.java | 4 +- .../eu/faircode/email/FragmentOptions.java | 2 +- .../java/eu/faircode/email/ToolbarEx.java | 60 ++++++++++++++++ .../res/layout/spinner_item1_dropdown.xml | 1 + app/src/main/res/layout/toolbar_holder.xml | 71 +++++++++++++++++++ app/src/main/res/values/styles.xml | 7 +- 23 files changed, 201 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/ToolbarEx.java create mode 100644 app/src/main/res/layout/toolbar_holder.xml diff --git a/app/src/main/java/eu/faircode/email/ActivityAMP.java b/app/src/main/java/eu/faircode/email/ActivityAMP.java index 79a4540374..0fcdc2473d 100644 --- a/app/src/main/java/eu/faircode/email/ActivityAMP.java +++ b/app/src/main/java/eu/faircode/email/ActivityAMP.java @@ -69,11 +69,11 @@ public class ActivityAMP extends ActivityBase { if (savedInstanceState != null) force_light = savedInstanceState.getBoolean("fair:force_light"); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - View view = LayoutInflater.from(this).inflate(R.layout.activity_amp, null); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + wvAmp = findViewById(R.id.wvAmp); pbWait = findViewById(R.id.pbWait); grpReady = findViewById(R.id.grpReady); diff --git a/app/src/main/java/eu/faircode/email/ActivityAnswer.java b/app/src/main/java/eu/faircode/email/ActivityAnswer.java index 9ae0df73dd..3ed1e59332 100644 --- a/app/src/main/java/eu/faircode/email/ActivityAnswer.java +++ b/app/src/main/java/eu/faircode/email/ActivityAnswer.java @@ -54,11 +54,11 @@ public class ActivityAnswer extends ActivityBase { final CharSequence query = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT); final boolean readonly = intent.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false); - getSupportActionBar().setSubtitle(query == null ? null : query.toString()); - View view = LayoutInflater.from(this).inflate(R.layout.activity_answer, null); setContentView(view); + getSupportActionBar().setSubtitle(query == null ? null : query.toString()); + ListView lvAnswer = view.findViewById(R.id.lvAnswer); Group grpReady = view.findViewById(R.id.grpReady); ContentLoadingProgressBar pbWait = view.findViewById(R.id.pbWait); diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 2c17bf7109..fed6f8afa9 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -40,6 +40,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.text.TextUtils; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MotionEvent; import android.view.View; @@ -52,6 +53,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.graphics.ColorUtils; import androidx.documentfile.provider.DocumentFile; import androidx.fragment.app.Fragment; @@ -92,6 +95,29 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc return originalContext; } + @Override + public void setContentView(View view) { + LayoutInflater inflater = LayoutInflater.from(this); + + ConstraintLayout container = (ConstraintLayout) inflater.inflate(R.layout.toolbar_holder, null); + View placeholder = container.findViewById(R.id.placeholder); + container.removeView(placeholder); + container.addView(view, placeholder.getLayoutParams()); + + Toolbar toolbar = container.findViewById(R.id.toolbar); + toolbar.setPopupTheme(getThemeId()); + + setSupportActionBar(toolbar); + + super.setContentView(container); + } + + @Override + public void setContentView(int layoutResID) { + View view = LayoutInflater.from(this).inflate(layoutResID, null); + setContentView(view); + } + @Override protected void onCreate(Bundle savedInstanceState) { EntityLog.log(this, "Activity create " + this.getClass().getName() + diff --git a/app/src/main/java/eu/faircode/email/ActivityClear.java b/app/src/main/java/eu/faircode/email/ActivityClear.java index 3f44d9ac5f..35899100d7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityClear.java +++ b/app/src/main/java/eu/faircode/email/ActivityClear.java @@ -35,9 +35,10 @@ public class ActivityClear extends ActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_clear); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setSubtitle(getString(R.string.title_advanced_clear_all)); - setContentView(R.layout.activity_clear); btnClearAll = findViewById(R.id.btnClearAll); btnCancel = findViewById(R.id.btnCancel); diff --git a/app/src/main/java/eu/faircode/email/ActivityCode.java b/app/src/main/java/eu/faircode/email/ActivityCode.java index cfc8984323..1f0e304be4 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCode.java +++ b/app/src/main/java/eu/faircode/email/ActivityCode.java @@ -90,8 +90,6 @@ public class ActivityCode extends ActivityBase { searching = savedInstanceState.getString("fair:searching"); } - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { @@ -102,6 +100,8 @@ public class ActivityCode extends ActivityBase { View view = LayoutInflater.from(this).inflate(R.layout.activity_code, null); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + wvCode = findViewById(R.id.wvCode); pbWait = findViewById(R.id.pbWait); grpReady = findViewById(R.id.grpReady); diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index ede3be9b1f..16858dd53c 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -56,8 +56,6 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB setContentView(R.layout.activity_compose); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setCustomView(R.layout.action_bar); - getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportFragmentManager().addOnBackStackChangedListener(this); diff --git a/app/src/main/java/eu/faircode/email/ActivityDMARC.java b/app/src/main/java/eu/faircode/email/ActivityDMARC.java index 9364854144..709dabf1cf 100644 --- a/app/src/main/java/eu/faircode/email/ActivityDMARC.java +++ b/app/src/main/java/eu/faircode/email/ActivityDMARC.java @@ -64,12 +64,12 @@ public class ActivityDMARC extends ActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle(R.string.title_advanced_dmarc_viewer); - View view = LayoutInflater.from(this).inflate(R.layout.activity_dmarc, null); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setSubtitle(R.string.title_advanced_dmarc_viewer); + tvDmarc = findViewById(R.id.tvDmarc); pbWait = findViewById(R.id.pbWait); grpReady = findViewById(R.id.grpReady); diff --git a/app/src/main/java/eu/faircode/email/ActivityDSN.java b/app/src/main/java/eu/faircode/email/ActivityDSN.java index 1100d2531a..b5d4568fa5 100644 --- a/app/src/main/java/eu/faircode/email/ActivityDSN.java +++ b/app/src/main/java/eu/faircode/email/ActivityDSN.java @@ -46,12 +46,12 @@ public class ActivityDSN extends ActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle("DSN"); - View view = LayoutInflater.from(this).inflate(R.layout.activity_dsn, null); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setSubtitle("DSN"); + tvHeaders = findViewById(R.id.tvHeaders); pbWait = findViewById(R.id.pbWait); grpReady = findViewById(R.id.grpReady); diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index ba862ae26e..1e52fa15cd 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -109,12 +109,12 @@ public class ActivityEML extends ActivityBase { junk = savedInstanceState.getBoolean("fair:junk"); } - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle("EML"); - View view = LayoutInflater.from(this).inflate(R.layout.activity_eml, null); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setSubtitle("EML"); + tvFrom = findViewById(R.id.tvFrom); tvTo = findViewById(R.id.tvTo); tvReplyTo = findViewById(R.id.tvReplyTo); diff --git a/app/src/main/java/eu/faircode/email/ActivityError.java b/app/src/main/java/eu/faircode/email/ActivityError.java index 474df0fbc9..5662865be7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityError.java +++ b/app/src/main/java/eu/faircode/email/ActivityError.java @@ -51,9 +51,10 @@ public class ActivityError extends ActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_error); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setSubtitle(getString(R.string.title_setup_error)); - setContentView(R.layout.activity_error); tvTitle = findViewById(R.id.tvTitle); tvMessage = findViewById(R.id.tvMessage); diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 65b418cd85..41ce42019e 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -120,10 +120,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac view = LayoutInflater.from(this).inflate(R.layout.activity_setup, null); setContentView(view); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setCustomView(R.layout.action_bar); - getSupportActionBar().setDisplayShowCustomEnabled(true); drawerLayout = findViewById(R.id.drawer_layout); drawerLayout.setScrimColor(Helper.resolveColor(this, R.attr.colorDrawerScrim)); diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index 0feadbd6d3..4978359f82 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -88,13 +88,13 @@ public class ActivitySignature extends ActivityBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean monospaced = prefs.getBoolean("monospaced", false); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle(getString(R.string.title_edit_signature)); - LayoutInflater inflater = LayoutInflater.from(this); view = (ViewGroup) inflater.inflate(R.layout.activity_signature, null, false); setContentView(view); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setSubtitle(getString(R.string.title_edit_signature)); + tvHtmlRemark = findViewById(R.id.tvHtmlRemark); etText = findViewById(R.id.etText); ibFull = findViewById(R.id.ibFull); diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 61f565f602..798f30a122 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -269,8 +269,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB setContentView(view); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setCustomView(R.layout.action_bar); - getSupportActionBar().setDisplayShowCustomEnabled(true); content_separator = findViewById(R.id.content_separator); content_pane = findViewById(R.id.content_pane); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidget.java b/app/src/main/java/eu/faircode/email/ActivityWidget.java index 311cd397c2..0632847b0c 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidget.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidget.java @@ -109,9 +109,10 @@ public class ActivityWidget extends ActivityBase { daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S); + setContentView(R.layout.activity_widget); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setSubtitle(R.string.title_widget_title_count); - setContentView(R.layout.activity_widget); spAccount = findViewById(R.id.spAccount); spFolder = findViewById(R.id.spFolder); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java index 503131863b..921b03617e 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java @@ -66,9 +66,10 @@ public class ActivityWidgetSync extends ActivityBase { daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S); + setContentView(R.layout.activity_widget_sync); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setSubtitle(R.string.title_widget_title_sync); - setContentView(R.layout.activity_widget_sync); cbDayNight = findViewById(R.id.cbDayNight); cbSemiTransparent = findViewById(R.id.cbSemiTransparent); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index 0a05a83928..cc557180f2 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -127,9 +127,10 @@ public class ActivityWidgetUnified extends ActivityBase { daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S); + setContentView(R.layout.activity_widget_unified); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setSubtitle(R.string.title_widget_title_list); - setContentView(R.layout.activity_widget_unified); spAccount = findViewById(R.id.spAccount); spFolder = findViewById(R.id.spFolder); diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 7ddcd76904..6be34719b5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -56,6 +56,7 @@ import androidx.annotation.RequiresApi; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.documentfile.provider.DocumentFile; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -465,15 +466,16 @@ public class FragmentBase extends Fragment { AppCompatActivity activity = (AppCompatActivity) getActivity(); if (activity != null && !isPane()) { ActionBar actionbar = activity.getSupportActionBar(); - if (actionbar != null) - if ((actionbar.getDisplayOptions() & DISPLAY_SHOW_CUSTOM) == 0) { + if (actionbar != null) { + Toolbar toolbar = activity.findViewById(R.id.toolbar); + if ((actionbar.getDisplayOptions() & DISPLAY_SHOW_CUSTOM) == 0 && toolbar == null) { actionbar.setTitle(title == null ? getString(R.string.app_name) : title); actionbar.setSubtitle(subtitle); } else { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); boolean list_count = prefs.getBoolean("list_count", false); - View custom = actionbar.getCustomView(); + View custom = (toolbar == null ? actionbar.getCustomView() : toolbar); TextView tvCount = custom.findViewById(R.id.count); TextView tvTitle = custom.findViewById(R.id.title); TextView tvSubtitle = custom.findViewById(R.id.subtitle); @@ -487,6 +489,7 @@ public class FragmentBase extends Fragment { if (tvSubtitle != null) tvSubtitle.setText(subtitle); } + } } } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index f7aec43749..fe0030629d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1873,7 +1873,9 @@ public class FragmentCompose extends FragmentBase { final Context context = getContext(); PopupMenuLifecycle.insertIcons(context, menu, false); - LayoutInflater infl = LayoutInflater.from(context); + ActionBar actionBar = getSupportActionBar(); + Context actionBarContext = (actionBar == null ? context : actionBar.getThemedContext()); + LayoutInflater infl = LayoutInflater.from(actionBarContext); ImageButton ibOpenAi = (ImageButton) infl.inflate(R.layout.action_button, null); ibOpenAi.setId(View.generateViewId()); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 580314fed1..cc1d7791fd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -424,7 +424,7 @@ public class FragmentOptions extends FragmentBase { } searchView.setSuggestionsAdapter(new SimpleCursorAdapter( - searchView.getContext(), + pager.getContext(), R.layout.spinner_item1_dropdown, cursor, new String[]{"title"}, diff --git a/app/src/main/java/eu/faircode/email/ToolbarEx.java b/app/src/main/java/eu/faircode/email/ToolbarEx.java new file mode 100644 index 0000000000..70d6c3ee82 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/ToolbarEx.java @@ -0,0 +1,60 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2024 by Marcel Bokhorst (M66B) +*/ + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; + +public class ToolbarEx extends Toolbar { + public ToolbarEx(@NonNull Context context) { + super(context); + } + + public ToolbarEx(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public ToolbarEx(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public void setTitle(CharSequence title) { + super.setTitle(null); + TextView tv = findViewById(R.id.title); + tv.setText(title); + tv.setVisibility(title == null ? GONE : VISIBLE); + findViewById(R.id.count).setVisibility(GONE); + } + + @Override + public void setSubtitle(CharSequence subtitle) { + super.setSubtitle(null); + TextView tv = findViewById(R.id.subtitle); + tv.setText(subtitle); + tv.setVisibility(subtitle == null ? GONE : VISIBLE); + findViewById(R.id.count).setVisibility(GONE); + } +} diff --git a/app/src/main/res/layout/spinner_item1_dropdown.xml b/app/src/main/res/layout/spinner_item1_dropdown.xml index 8ddd8ebb65..4d560ea9dd 100644 --- a/app/src/main/res/layout/spinner_item1_dropdown.xml +++ b/app/src/main/res/layout/spinner_item1_dropdown.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?android:colorBackground" android:padding="12dp"> + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 84459fafe6..520d88f752 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -26,7 +26,7 @@ - - + +