New option: Disable Immersive Interface in Landscape Mode.

This commit is contained in:
Alex Ning 2021-01-13 23:03:28 +08:00
parent ba75ae1f53
commit ba546a27e4
5 changed files with 19 additions and 2 deletions

View File

@ -89,6 +89,9 @@ public abstract class BaseActivity extends AppCompatActivity {
int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true); 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) { switch (systemThemeType) {
case 0: case 0:
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);

View File

@ -7,8 +7,8 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat { public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat {
@ -19,8 +19,10 @@ public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentComp
SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_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) -> { immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
if ((Boolean) newValue) { if ((Boolean) newValue) {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
@ -41,6 +43,11 @@ public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentComp
EventBus.getDefault().post(new RecreateActivityEvent()); EventBus.getDefault().post(new RecreateActivityEvent());
return true; return true;
}); });
disableImmersiveInterfaceInLandscapeModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent());
return true;
});
} }
} }
} }

View File

@ -35,6 +35,7 @@ public class SharedPreferencesUtils {
public static final String IMMERSIVE_INTERFACE_ENTRY_KEY = "immersive_interface_entry"; 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_KEY = "immersive_interface";
public static final String IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY = "immersive_interface_ignore_nav_bar"; 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 BOTTOM_APP_BAR_KEY = "bottom_app_bar";
public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right"; public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right";

View File

@ -359,6 +359,7 @@
<string name="settings_immersive_interface_summary">Does Not Apply to All Pages</string> <string name="settings_immersive_interface_summary">Does Not Apply to All Pages</string>
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string> <string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string> <string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
<string name="settings_disable_immersive_interface_in_landscape_mode">Disable Immersive Interface in Landscape Mode</string>
<string name="settings_customize_tabs_in_main_page_title">Customize Tabs in Main Page</string> <string name="settings_customize_tabs_in_main_page_title">Customize Tabs in Main Page</string>
<string name="only_for_logged_in_user">Only for Logged-in User</string> <string name="only_for_logged_in_user">Only for Logged-in User</string>
<string name="settings_enable_bottom_app_bar_title">Enable Bottom Navigation</string> <string name="settings_enable_bottom_app_bar_title">Enable Bottom Navigation</string>

View File

@ -13,4 +13,9 @@
app:title="@string/settings_immersive_interface_ignore_nav_bar_title" app:title="@string/settings_immersive_interface_ignore_nav_bar_title"
app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" /> app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" />
<SwitchPreference
app:defaultValue="false"
app:key="disable_immersive_interface_in_landscape_mode"
app:title="@string/settings_disable_immersive_interface_in_landscape_mode"/>
</PreferenceScreen> </PreferenceScreen>