diff --git a/app/src/debug/res/xml/main_settings.xml b/app/src/debug/res/xml/main_settings.xml index dfb8ffa34..f9af921c0 100644 --- a/app/src/debug/res/xml/main_settings.xml +++ b/app/src/debug/res/xml/main_settings.xml @@ -47,6 +47,18 @@ android:title="@string/settings_category_updates_title" app:iconSpaceReserved="false" /> + + + + { - final Intent i = new Intent(Intent.ACTION_VIEW, - Uri.parse(getString(R.string.sponsor_block_homepage_url))); - startActivity(i); - return true; - }); - - final Preference sponsorBlockPrivacyPreference = - findPreference(getString(R.string.sponsor_block_privacy_key)); - sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> { - final Intent i = new Intent(Intent.ACTION_VIEW, - Uri.parse(getString(R.string.sponsor_block_privacy_policy_url))); - startActivity(i); - return true; - }); - - final Preference sponsorBlockApiUrlPreference = - findPreference(getString(R.string.sponsor_block_api_url_key)); - sponsorBlockApiUrlPreference - .setOnPreferenceChangeListener((preference, newValue) -> { - updateDependencies(preference, newValue); - return true; - }); - - final Preference sponsorBlockClearWhitelistPreference = - findPreference(getString(R.string.sponsor_block_clear_whitelist_key)); - sponsorBlockClearWhitelistPreference.setOnPreferenceClickListener((Preference p) -> { - getPreferenceManager() - .getSharedPreferences() - .edit() - .putStringSet( - getString(R.string.sponsor_block_whitelist_key), new HashSet<>()) - .apply(); - Toast.makeText(getContext(), R.string.sponsor_block_whitelist_cleared_toast, - Toast.LENGTH_SHORT).show(); - return true; - }); - } - - @Override - public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - final Preference sponsorBlockApiUrlPreference = - findPreference(getString(R.string.sponsor_block_api_url_key)); - final String sponsorBlockApiUrlPreferenceValue = - getPreferenceManager() - .getSharedPreferences() - .getString(getString(R.string.sponsor_block_api_url_key), null); - updateDependencies(sponsorBlockApiUrlPreference, sponsorBlockApiUrlPreferenceValue); } @Override @@ -381,26 +325,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment { } } - private void updateDependencies(final Preference preference, final Object newValue) { - // This is a workaround to force dependency updates for custom preferences. - - // sponsor_block_api_url_key - if (preference.getKey().equals(getString(R.string.sponsor_block_api_url_key))) { - findPreference(getString(R.string.sponsor_block_enable_key)) - .onDependencyChanged(preference, - newValue == null || newValue.equals("")); - findPreference(getString(R.string.sponsor_block_notifications_key)) - .onDependencyChanged(preference, - newValue == null || newValue.equals("")); - findPreference(getString(R.string.sponsor_block_categories_key)) - .onDependencyChanged(preference, - newValue == null || newValue.equals("")); - findPreference(getString(R.string.sponsor_block_clear_whitelist_key)) - .onDependencyChanged(preference, - newValue == null || newValue.equals("")); - } - } - /*////////////////////////////////////////////////////////////////////////// // Error //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/settings/ExtraSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ExtraSettingsFragment.java new file mode 100644 index 000000000..0eaac6f07 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/ExtraSettingsFragment.java @@ -0,0 +1,12 @@ +package org.schabi.newpipe.settings; + +import android.os.Bundle; + +import org.schabi.newpipe.R; + +public class ExtraSettingsFragment extends BasePreferenceFragment { + @Override + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.extra_settings); + } +} diff --git a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java index 08e0d9b09..cf5ae1fa6 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java @@ -1,12 +1,13 @@ package org.schabi.newpipe.settings; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.widget.Toast; import androidx.annotation.ColorRes; import androidx.annotation.Nullable; import androidx.annotation.StringRes; +import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; import org.schabi.newpipe.R; @@ -22,48 +23,52 @@ public class SponsorBlockCategoriesSettingsFragment extends BasePreferenceFragme public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResource(R.xml.sponsor_block_category_settings); - final Preference resetPreferenceView = + final Preference resetPreference = findPreference(getString(R.string.sponsor_block_category_reset_key)); - if (resetPreferenceView != null) { - resetPreferenceView.setOnPreferenceClickListener(preference -> { - final Context context = getContext(); + resetPreference.setOnPreferenceClickListener(p -> { + new AlertDialog.Builder(p.getContext()) + .setMessage(R.string.sponsor_block_confirm_reset_colors) + .setPositiveButton(R.string.yes, (dialog, which) -> { + final SharedPreferences.Editor editor = + getPreferenceManager() + .getSharedPreferences() + .edit(); - if (context != null) { - final SharedPreferences.Editor editor = - getPreferenceManager() - .getSharedPreferences() - .edit(); + setColorPreference(editor, + R.string.sponsor_block_category_sponsor_color_key, + R.color.sponsor_segment); - setColorPreference(editor, - R.string.sponsor_block_category_sponsor_color_key, - R.color.sponsor_segment); + setColorPreference(editor, + R.string.sponsor_block_category_intro_color_key, + R.color.intro_segment); - setColorPreference(editor, - R.string.sponsor_block_category_intro_color_key, - R.color.intro_segment); + setColorPreference(editor, + R.string.sponsor_block_category_outro_color_key, + R.color.outro_segment); - setColorPreference(editor, - R.string.sponsor_block_category_outro_color_key, - R.color.outro_segment); + setColorPreference(editor, + R.string.sponsor_block_category_interaction_color_key, + R.color.interaction_segment); - setColorPreference(editor, - R.string.sponsor_block_category_interaction_color_key, - R.color.interaction_segment); + setColorPreference(editor, + R.string.sponsor_block_category_self_promo_color_key, + R.color.self_promo_segment); - setColorPreference(editor, - R.string.sponsor_block_category_self_promo_color_key, - R.color.self_promo_segment); + setColorPreference(editor, + R.string.sponsor_block_category_non_music_color_key, + R.color.non_music_segment); - setColorPreference(editor, - R.string.sponsor_block_category_non_music_color_key, - R.color.non_music_segment); + editor.apply(); - editor.apply(); - } - - return true; - }); - } + Toast.makeText(p.getContext(), R.string.sponsor_block_reset_colors_toast, + Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(R.string.no, (dialog, which) -> { + dialog.dismiss(); + }) + .show(); + return true; + }); } private void setColorPreference(final SharedPreferences.Editor editor, diff --git a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockSettingsFragment.java new file mode 100644 index 000000000..f3b8fc0eb --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockSettingsFragment.java @@ -0,0 +1,106 @@ +package org.schabi.newpipe.settings; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.preference.Preference; + +import org.schabi.newpipe.R; + +import java.util.HashSet; + +public class SponsorBlockSettingsFragment extends BasePreferenceFragment { + + @Override + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResource(R.xml.sponsor_block_settings); + + final Preference sponsorBlockWebsitePreference = + findPreference(getString(R.string.sponsor_block_home_page_key)); + sponsorBlockWebsitePreference.setOnPreferenceClickListener((Preference p) -> { + final Intent i = new Intent(Intent.ACTION_VIEW, + Uri.parse(getString(R.string.sponsor_block_homepage_url))); + startActivity(i); + return true; + }); + + final Preference sponsorBlockPrivacyPreference = + findPreference(getString(R.string.sponsor_block_privacy_key)); + sponsorBlockPrivacyPreference.setOnPreferenceClickListener((Preference p) -> { + final Intent i = new Intent(Intent.ACTION_VIEW, + Uri.parse(getString(R.string.sponsor_block_privacy_policy_url))); + startActivity(i); + return true; + }); + + final Preference sponsorBlockApiUrlPreference = + findPreference(getString(R.string.sponsor_block_api_url_key)); + sponsorBlockApiUrlPreference + .setOnPreferenceChangeListener((preference, newValue) -> { + updateDependencies(preference, newValue); + return true; + }); + + final Preference sponsorBlockClearWhitelistPreference = + findPreference(getString(R.string.sponsor_block_clear_whitelist_key)); + sponsorBlockClearWhitelistPreference.setOnPreferenceClickListener((Preference p) -> { + new AlertDialog.Builder(p.getContext()) + .setMessage(R.string.sponsor_block_confirm_clear_whitelist) + .setPositiveButton(R.string.yes, (dialog, which) -> { + getPreferenceManager() + .getSharedPreferences() + .edit() + .putStringSet(getString( + R.string.sponsor_block_whitelist_key), new HashSet<>()) + .apply(); + Toast.makeText(p.getContext(), + R.string.sponsor_block_whitelist_cleared_toast, + Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(R.string.no, (dialog, which) -> { + dialog.dismiss(); + }) + .show(); + return true; + }); + } + + @Override + public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + final Preference sponsorBlockApiUrlPreference = + findPreference(getString(R.string.sponsor_block_api_url_key)); + final String sponsorBlockApiUrlPreferenceValue = + getPreferenceManager() + .getSharedPreferences() + .getString(getString(R.string.sponsor_block_api_url_key), null); + updateDependencies(sponsorBlockApiUrlPreference, sponsorBlockApiUrlPreferenceValue); + } + + private void updateDependencies(final Preference preference, final Object newValue) { + // This is a workaround to force dependency updates for custom preferences. + + // sponsor_block_api_url_key + if (preference.getKey().equals(getString(R.string.sponsor_block_api_url_key))) { + findPreference(getString(R.string.sponsor_block_enable_key)) + .onDependencyChanged(preference, + newValue == null || newValue.equals("")); + findPreference(getString(R.string.sponsor_block_notifications_key)) + .onDependencyChanged(preference, + newValue == null || newValue.equals("")); + findPreference(getString(R.string.sponsor_block_categories_key)) + .onDependencyChanged(preference, + newValue == null || newValue.equals("")); + findPreference(getString(R.string.sponsor_block_clear_whitelist_key)) + .onDependencyChanged(preference, + newValue == null || newValue.equals("")); + } + } +} 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 1afedcaef..6d9842ee9 100644 --- a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.util; import android.app.UiModeManager; import android.content.Context; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.BatteryManager; @@ -10,8 +11,10 @@ import android.view.KeyEvent; 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 { @@ -53,6 +56,13 @@ public final class DeviceUtils { } public static boolean isTablet(@NonNull final Context context) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + if (prefs.getBoolean(context + .getString(R.string.disable_tablet_ui_key), false)) { + return false; + } + return (context .getResources() .getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 97b6dc175..be8c9fa2a 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -266,28 +266,6 @@ downloads_storage_ask storage_use_saf - sponsor_block_home_page - sponsor_block_enable - sponsor_block_api_url - sponsor_block_notifications - sponsor_block_privacy - sponsor_block_categories - sponsor_block_category_reset - sponsor_block_category_sponsor - sponsor_block_category_sponsor_color - sponsor_block_category_intro - sponsor_block_category_intro_color - sponsor_block_category_outro - sponsor_block_category_outro_color - sponsor_block_category_interaction - sponsor_block_category_interaction_color - sponsor_block_category_self_promo - sponsor_block_category_self_promo_color - sponsor_block_category_music - sponsor_block_category_music_color - sponsor_block_whitelist - sponsor_block_clear_whitelist - file_rename_charset file_replacement_character @@ -361,6 +339,32 @@ update_app_key update_pref_screen_key + + sponsor_block_home_page + sponsor_block_enable + sponsor_block_api_url + sponsor_block_notifications + sponsor_block_privacy + sponsor_block_categories + sponsor_block_category_reset + sponsor_block_category_sponsor + sponsor_block_category_sponsor_color + sponsor_block_category_intro + sponsor_block_category_intro_color + sponsor_block_category_outro + sponsor_block_category_outro_color + sponsor_block_category_interaction + sponsor_block_category_interaction_color + sponsor_block_category_self_promo + sponsor_block_category_self_promo_color + sponsor_block_category_music + sponsor_block_category_music_color + sponsor_block_whitelist + sponsor_block_clear_whitelist + + + disable_tablet_ui + system diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c2b59642d..7f53dc8f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,6 +194,7 @@ Albums Artists Yes + No Later Disabled Filter @@ -705,6 +706,8 @@ Show thumbnail Show thumbnail on lock screen as background and inside notifications + SponsorBlock + Information View Website View the official SponsorBlock website. Skip Sponsors @@ -734,4 +737,12 @@ Whitelist cleared Uploader added to whitelist Uploader removed from whitelist + Are you sure you want to clear the whitelist? + Are you sure you want to reset the category colors? + Colors reset. + + Extras + Experimental Settings + Disable Tablet UI + Ignore tablet layouts. This is intended for workarounds related to specific scenarios. diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index fc6dfe138..c885366ec 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -125,58 +125,4 @@ app:iconSpaceReserved="false" /> - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/extra_settings.xml b/app/src/main/res/xml/extra_settings.xml new file mode 100644 index 000000000..67979432a --- /dev/null +++ b/app/src/main/res/xml/extra_settings.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/sponsor_block_category_settings.xml b/app/src/main/res/xml/sponsor_block_category_settings.xml index f40be43f6..e066a1a50 100644 --- a/app/src/main/res/xml/sponsor_block_category_settings.xml +++ b/app/src/main/res/xml/sponsor_block_category_settings.xml @@ -4,11 +4,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:title="@string/settings_category_sponsor_block_categories_title"> - - @@ -153,4 +148,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/sponsor_block_settings.xml b/app/src/main/res/xml/sponsor_block_settings.xml new file mode 100644 index 000000000..89cb20539 --- /dev/null +++ b/app/src/main/res/xml/sponsor_block_settings.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/release/res/xml/main_settings.xml b/app/src/release/res/xml/main_settings.xml index abb94f4ef..a79ab95bb 100644 --- a/app/src/release/res/xml/main_settings.xml +++ b/app/src/release/res/xml/main_settings.xml @@ -46,4 +46,16 @@ android:key="update_pref_screen_key" android:title="@string/settings_category_updates_title" app:iconSpaceReserved="false" /> + + + +