1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Adds manual tablet mode setting

Co-authored-by: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com>
This commit is contained in:
Dakkaron 2021-04-11 13:29:11 +02:00 committed by Stypox
parent 56cd84c1fe
commit e01ef42d31
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 44 additions and 6 deletions

View File

@ -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) {

View File

@ -1220,5 +1220,22 @@
<item>@string/grid</item>
</string-array>
<string name="tablet_mode_key" translatable="false">tablet_mode</string>
<string name="tablet_mode_value" translatable="false">@string/tablet_mode_auto_key</string>
<string name="tablet_mode_auto_key" translatable="false">auto</string>
<string name="tablet_mode_on_key" translatable="false">on</string>
<string name="tablet_mode_off_key" translatable="false">off</string>
<string-array name="tablet_mode_values" translatable="false">
<item>@string/tablet_mode_auto_key</item>
<item>@string/tablet_mode_on_key</item>
<item>@string/tablet_mode_off_key</item>
</string-array>
<string-array name="tablet_mode_description" translatable="false">
<item>@string/auto</item>
<item>@string/on</item>
<item>@string/off</item>
</string-array>
<string name="recaptcha_cookies_key" translatable="false">recaptcha_cookies_key</string>
</resources>

View File

@ -742,5 +742,8 @@
<string name="metadata_privacy_unlisted">Unlisted</string>
<string name="metadata_privacy_private">Private</string>
<string name="metadata_privacy_internal">Internal</string>
<string name="open_website_license">Open Website</string>
</resources>
<string name="open_website_license">Open website</string>
<string name="tablet_mode_title">Tablet mode</string>
<string name="on">On</string>
<string name="off">Off</string>
</resources>

View File

@ -43,4 +43,12 @@
android:title="@string/caption_setting_title"
app:iconSpaceReserved="false" />
<ListPreference
android:defaultValue="@string/tablet_mode_auto_key"
android:entries="@array/tablet_mode_description"
android:entryValues="@array/tablet_mode_values"
android:key="@string/tablet_mode_key"
android:summary="%s"
android:title="@string/tablet_mode_title"
app:iconSpaceReserved="false" />
</PreferenceScreen>