From 52189fc5df86b1309d4be99e9d90ce5f3878a15e Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 27 Mar 2021 14:59:24 +0100 Subject: [PATCH] Add debug setting to enable Picasso indicators --- .../schabi/newpipe/settings/DebugSettingsFragment.java | 9 +++++++++ app/src/main/java/org/schabi/newpipe/App.java | 7 +++++-- .../main/java/org/schabi/newpipe/util/PicassoHelper.java | 4 ++++ app/src/main/res/values/settings_keys.xml | 7 ++++--- app/src/main/res/values/strings.xml | 6 +++++- app/src/main/res/xml/debug_settings.xml | 7 +++++++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index d5d223ff2..55b2c7708 100644 --- a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -5,6 +5,7 @@ import android.os.Bundle; import androidx.preference.Preference; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.PicassoHelper; import leakcanary.LeakCanary; @@ -15,10 +16,13 @@ public class DebugSettingsFragment extends BasePreferenceFragment { final Preference showMemoryLeaksPreference = findPreference(getString(R.string.show_memory_leaks_key)); + final Preference showImageIndicatorsPreference + = findPreference(getString(R.string.show_image_indicators_key)); final Preference crashTheAppPreference = findPreference(getString(R.string.crash_the_app_key)); assert showMemoryLeaksPreference != null; + assert showImageIndicatorsPreference != null; assert crashTheAppPreference != null; showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { @@ -26,6 +30,11 @@ public class DebugSettingsFragment extends BasePreferenceFragment { return true; }); + showImageIndicatorsPreference.setOnPreferenceChangeListener((preference, newValue) -> { + PicassoHelper.setIndicatorsEnabled((Boolean) newValue); + return true; + }); + crashTheAppPreference.setOnPreferenceClickListener(preference -> { throw new RuntimeException(); }); diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index a7d9d7c26..c27dc7de2 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -100,9 +100,12 @@ public class App extends MultiDexApplication { ServiceHelper.initServices(this); // Initialize image loader + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); PicassoHelper.init(this); - PicassoHelper.setShouldLoadImages(PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(getString(R.string.download_thumbnail_key), true)); + PicassoHelper.setShouldLoadImages( + prefs.getBoolean(getString(R.string.download_thumbnail_key), true)); + PicassoHelper.setIndicatorsEnabled(BuildConfig.DEBUG + && prefs.getBoolean(getString(R.string.show_image_indicators_key), false)); configureRxJavaErrorHandler(); diff --git a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java index bcacb0c13..3a9ce090b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java @@ -71,6 +71,10 @@ public final class PicassoHelper { picassoInstance.cancelTag(tag); } + public static void setIndicatorsEnabled(final boolean enabled) { + picassoInstance.setIndicatorsEnabled(enabled); // useful for debugging + } + public static void setShouldLoadImages(final boolean shouldLoadImages) { PicassoHelper.shouldLoadImages = shouldLoadImages; } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index c57b24f16..e0e0a613a 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -1,5 +1,5 @@ - + last_used_version last_used_preferences_version @@ -139,13 +139,13 @@ scale_to_square_image_in_notifications notification_slot_0_key - notification_slot_1_key + notification_slot_1_key notification_slot_2_key notification_slot_3_key notification_slot_4_key notification_slot_compact_0_key - notification_slot_compact_1_key + notification_slot_compact_1_key notification_slot_compact_2_key notification_colorize_key @@ -189,6 +189,7 @@ show_original_time_ago_key disable_media_tunneling_key crash_the_app_key + show_image_indicators_key theme diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc381f42c..aecb6e6d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,7 @@ - + + Tap the magnifying glass to get started. %1$s views Published on %1$s @@ -526,6 +528,8 @@ Original texts from services will be visible in stream items Disable media tunneling Disable media tunneling if you experience a black screen or stuttering on video playback + Show image indicators + Show Picasso colored ribbons on top of images indicating their source: red for network, blue for disk and green for memory Crash the app Import/export diff --git a/app/src/main/res/xml/debug_settings.xml b/app/src/main/res/xml/debug_settings.xml index 931f16e0a..22abebcae 100644 --- a/app/src/main/res/xml/debug_settings.xml +++ b/app/src/main/res/xml/debug_settings.xml @@ -42,6 +42,13 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + +