From ba546a27e4b8b6e2306a17ba2c10f33b0728842f Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 13 Jan 2021 23:03:28 +0800 Subject: New option: Disable Immersive Interface in Landscape Mode. --- .../infinityforreddit/activities/BaseActivity.java | 3 +++ .../settings/ImmersiveInterfacePreferenceFragment.java | 11 +++++++++-- .../infinityforreddit/utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/immersive_interface_preferences.xml | 5 +++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index e2f02bdd..12e565c4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -89,6 +89,9 @@ public abstract class BaseActivity extends AppCompatActivity { int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true); + if (immersiveInterface && config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + immersiveInterface = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE, false); + } switch (systemThemeType) { case 0: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java index 785721cb..73d5d305 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java @@ -7,8 +7,8 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; -import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat { @@ -19,8 +19,10 @@ public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentComp SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); + SwitchPreference disableImmersiveInterfaceInLandscapeModeSwitch = findPreference(SharedPreferencesUtils.DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE); - if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) { + if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null + && disableImmersiveInterfaceInLandscapeModeSwitch != null) { immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); @@ -41,6 +43,11 @@ public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentComp EventBus.getDefault().post(new RecreateActivityEvent()); return true; }); + + disableImmersiveInterfaceInLandscapeModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); } } } \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 45878da5..0d6c9ffe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -35,6 +35,7 @@ public class SharedPreferencesUtils { public static final String IMMERSIVE_INTERFACE_ENTRY_KEY = "immersive_interface_entry"; public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface"; public static final String IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY = "immersive_interface_ignore_nav_bar"; + public static final String DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE = "disable_immersive_interface_in_landscape_mode"; public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar"; public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e096984a..f5410e92 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -359,6 +359,7 @@ Does Not Apply to All Pages Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding + Disable Immersive Interface in Landscape Mode Customize Tabs in Main Page Only for Logged-in User Enable Bottom Navigation diff --git a/app/src/main/res/xml/immersive_interface_preferences.xml b/app/src/main/res/xml/immersive_interface_preferences.xml index 6cd31d84..5897108a 100644 --- a/app/src/main/res/xml/immersive_interface_preferences.xml +++ b/app/src/main/res/xml/immersive_interface_preferences.xml @@ -13,4 +13,9 @@ app:title="@string/settings_immersive_interface_ignore_nav_bar_title" app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" /> + + \ No newline at end of file -- cgit v1.2.3