From e01ef42d31efd29b43d5d9f557aa5264898f83c1 Mon Sep 17 00:00:00 2001 From: Dakkaron Date: Sun, 11 Apr 2021 13:29:11 +0200 Subject: [PATCH] Adds manual tablet mode setting Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> --- .../org/schabi/newpipe/util/DeviceUtils.java | 18 ++++++++++++++---- app/src/main/res/values/settings_keys.xml | 17 +++++++++++++++++ app/src/main/res/values/strings.xml | 7 +++++-- app/src/main/res/xml/appearance_settings.xml | 8 ++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java index 91578f27e..6d3e2936e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -12,8 +12,10 @@ import android.view.KeyEvent; import androidx.annotation.Dimension; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.App; +import org.schabi.newpipe.R; public final class DeviceUtils { @@ -65,10 +67,18 @@ public final class DeviceUtils { } public static boolean isTablet(@NonNull final Context context) { - return (context - .getResources() - .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) - >= Configuration.SCREENLAYOUT_SIZE_LARGE; + final String tabletModeSetting = PreferenceManager.getDefaultSharedPreferences(context) + .getString(context.getString(R.string.tablet_mode_key), ""); + + if (tabletModeSetting.equals(context.getString(R.string.tablet_mode_on_key))) { + return true; + } else if (tabletModeSetting.equals(context.getString(R.string.tablet_mode_off_key))) { + return false; + } + + // else automatically determine whether we are in a tablet or not + return (context.getResources().getConfiguration().screenLayout + & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } public static boolean isConfirmKey(final int keyCode) { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index c23e81fbe..399e4c832 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -1220,5 +1220,22 @@ @string/grid + tablet_mode + @string/tablet_mode_auto_key + + auto + on + off + + @string/tablet_mode_auto_key + @string/tablet_mode_on_key + @string/tablet_mode_off_key + + + @string/auto + @string/on + @string/off + + recaptcha_cookies_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 756e12eaf..e02acb696 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -742,5 +742,8 @@ Unlisted Private Internal - Open Website - \ No newline at end of file + Open website + Tablet mode + On + Off + diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index e5afef805..e1c80829d 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -43,4 +43,12 @@ android:title="@string/caption_setting_title" app:iconSpaceReserved="false" /> +