Skip to content

Commit

Permalink
Merge pull request TeamNewPipe#6059 from Dakkaron/manual-tablet-mode-…
Browse files Browse the repository at this point in the history
…setting

Adds manual tablet mode setting
  • Loading branch information
Stypox authored Jun 15, 2021
2 parents 92910eb + e01ef42 commit d6e0bd8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
18 changes: 14 additions & 4 deletions app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
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 {

Expand Down Expand Up @@ -65,10 +67,18 @@ public static boolean isTv(final Context context) {
}

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) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
8 changes: 8 additions & 0 deletions app/src/main/res/xml/appearance_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit d6e0bd8

Please sign in to comment.