From 0dcbe6430dbe16bfd0edb5658f7f535c003ee18b Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 10 Aug 2021 08:19:03 +0200 Subject: [PATCH] Added option for fixed nav menu in portrait mode --- .../java/eu/faircode/email/ActivityView.java | 24 ++++++++++++------- .../eu/faircode/email/DrawerLayoutEx.java | 6 +++-- .../eu/faircode/email/FragmentOptions.java | 2 +- .../email/FragmentOptionsDisplay.java | 14 ++++++++++- .../res/layout/fragment_options_display.xml | 13 +++++++++- app/src/main/res/values/strings.xml | 1 + 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 174668561c..6bda85daf4 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -177,9 +177,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB Configuration config = getResources().getConfiguration(); final boolean normal = config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL); final boolean portrait2 = prefs.getBoolean("portrait2", false); + final boolean portrait3 = prefs.getBoolean("portrait3", false); final boolean landscape = prefs.getBoolean("landscape", true); final boolean landscape3 = prefs.getBoolean("landscape3", true); - Log.i("Orientation=" + config.orientation + " normal=" + normal + + Log.i("Orientation=" + config.orientation + + " normal=" + normal + + " portrait=" + portrait2 + "/" + portrait3 + " landscape=" + landscape + "/" + landscape3); int viewId; @@ -230,8 +233,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB Log.i("Drawer opened"); owner.start(); - if (normal && landscape3 && - config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + if (normal && + ((portrait3 && config.orientation == Configuration.ORIENTATION_PORTRAIT) || + (landscape3 && config.orientation == Configuration.ORIENTATION_LANDSCAPE))) { drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_OPEN); childContent.setPaddingRelative(childDrawer.getLayoutParams().width, 0, 0, 0); } @@ -246,8 +250,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB else owner.stop(); - if (normal && landscape3 && - config.orientation == Configuration.ORIENTATION_LANDSCAPE) + if (normal && + ((portrait3 && config.orientation == Configuration.ORIENTATION_PORTRAIT) || + (landscape3 && config.orientation == Configuration.ORIENTATION_LANDSCAPE))) childContent.setPaddingRelative( Math.round(slideOffset * childDrawer.getLayoutParams().width), 0, 0, 0); } @@ -258,7 +263,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB int drawerWidth; DisplayMetrics dm = getResources().getDisplayMetrics(); - if (viewId != R.layout.activity_view_landscape_split || !landscape3) { + if (viewId == R.layout.activity_view_landscape_split && landscape3) + drawerWidth = Helper.dp2pixels(this, 300); + else if (viewId != R.layout.activity_view_landscape_split && portrait3) + drawerWidth = Math.min(Helper.dp2pixels(this, 300), dm.widthPixels / 2); + else { int actionBarHeight; TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) @@ -269,8 +278,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB int screenWidth = Math.min(dm.widthPixels, dm.heightPixels); int dp320 = Helper.dp2pixels(this, 320); drawerWidth = Math.min(screenWidth - actionBarHeight, dp320); - } else - drawerWidth = Helper.dp2pixels(this, 300); + } ViewGroup.LayoutParams lparam = drawerContainer.getLayoutParams(); lparam.width = drawerWidth; diff --git a/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java b/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java index eb1e0899b8..44c32d408f 100644 --- a/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java +++ b/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java @@ -51,10 +51,12 @@ public class DrawerLayoutEx extends DrawerLayout { void setup(Configuration config, View drawerContainer, ActionBarDrawerToggle drawerToggle) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean normal = config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL); + boolean portrait3 = prefs.getBoolean("portrait3", false); boolean landscape3 = prefs.getBoolean("landscape3", true); - if (normal && landscape3 && - config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + if (normal && + ((portrait3 && config.orientation == Configuration.ORIENTATION_PORTRAIT) || + (landscape3 && config.orientation == Configuration.ORIENTATION_LANDSCAPE))) { setScrimColor(Color.TRANSPARENT); openDrawer(drawerContainer, false); drawerToggle.onDrawerOpened(drawerContainer); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 8063b1099a..423ada91dd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -108,7 +108,7 @@ public class FragmentOptions extends FragmentBase { "subscriptions", "check_authentication", "check_reply_domain", "check_mx", "check_blocklist", "send_pending", - "portrait2", "landscape", "landscape3", "nav_count", "startup", + "portrait2", "portrait3", "landscape", "landscape3", "nav_count", "startup", "cards", "beige", "tabular_card_bg", "shadow_unread", "indentation", "date", "date_bold", "threading", "threading_unread", "highlight_unread", "highlight_color", "color_stripe", diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index 449b7ab555..abac80993f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -68,6 +68,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private SwitchCompat swDateBold; private SwitchCompat swNavBarColorize; private SwitchCompat swPortrait2; + private SwitchCompat swPortrait3; private SwitchCompat swLandscape; private SwitchCompat swLandscape3; private SwitchCompat swNavMessageCount; @@ -154,7 +155,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private final static String[] RESET_OPTIONS = new String[]{ "theme", "startup", "cards", "beige", "tabular_card_bg", "shadow_unread", - "date", "date_bold", "navbar_colorize", "portrait2", "landscape", "landscape3", "nav_count", + "date", "date_bold", "navbar_colorize", + "portrait2", "portrait3", "landscape", "landscape3", "nav_count", "threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_color", "highlight_unread", "highlight_color", "color_stripe", "avatars", "bimi", "gravatars", "favicons", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", @@ -190,6 +192,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swDateBold = view.findViewById(R.id.swDateBold); swNavBarColorize = view.findViewById(R.id.swNavBarColorize); swPortrait2 = view.findViewById(R.id.swPortrait2); + swPortrait3 = view.findViewById(R.id.swPortrait3); swLandscape = view.findViewById(R.id.swLandscape); swLandscape3 = view.findViewById(R.id.swLandscape3); swNavMessageCount = view.findViewById(R.id.swNavMessageCount); @@ -359,6 +362,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); + swPortrait3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("portrait3", checked).apply(); + } + }); + swLandscape.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1023,6 +1033,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swDateBold.setEnabled(swDate.isChecked()); swNavBarColorize.setChecked(prefs.getBoolean("navbar_colorize", false)); swPortrait2.setChecked(prefs.getBoolean("portrait2", false)); + swPortrait3.setChecked(prefs.getBoolean("portrait3", false)); + swPortrait3.setEnabled(normal); swLandscape.setChecked(prefs.getBoolean("landscape", true)); swLandscape.setEnabled(normal); swLandscape3.setChecked(prefs.getBoolean("landscape3", true)); diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml index e2edfbc918..8569d253c6 100644 --- a/app/src/main/res/layout/fragment_options_display.xml +++ b/app/src/main/res/layout/fragment_options_display.xml @@ -254,6 +254,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swPortrait2" /> + + Debug Use two rows in portrait mode + Show navigation menu in portrait mode by default Use two columns in landscape mode Show navigation menu in landscape mode by default Show number of locally stored messages in the navigation menu