Add debug setting to enable Picasso indicators

This commit is contained in:
Stypox 2021-03-27 14:59:24 +01:00
parent 314964c5f9
commit 52189fc5df
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
6 changed files with 34 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import android.os.Bundle;
import androidx.preference.Preference; import androidx.preference.Preference;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.PicassoHelper;
import leakcanary.LeakCanary; import leakcanary.LeakCanary;
@ -15,10 +16,13 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
final Preference showMemoryLeaksPreference final Preference showMemoryLeaksPreference
= findPreference(getString(R.string.show_memory_leaks_key)); = findPreference(getString(R.string.show_memory_leaks_key));
final Preference showImageIndicatorsPreference
= findPreference(getString(R.string.show_image_indicators_key));
final Preference crashTheAppPreference final Preference crashTheAppPreference
= findPreference(getString(R.string.crash_the_app_key)); = findPreference(getString(R.string.crash_the_app_key));
assert showMemoryLeaksPreference != null; assert showMemoryLeaksPreference != null;
assert showImageIndicatorsPreference != null;
assert crashTheAppPreference != null; assert crashTheAppPreference != null;
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
@ -26,6 +30,11 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
return true; return true;
}); });
showImageIndicatorsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
PicassoHelper.setIndicatorsEnabled((Boolean) newValue);
return true;
});
crashTheAppPreference.setOnPreferenceClickListener(preference -> { crashTheAppPreference.setOnPreferenceClickListener(preference -> {
throw new RuntimeException(); throw new RuntimeException();
}); });

View file

@ -100,9 +100,12 @@ public class App extends MultiDexApplication {
ServiceHelper.initServices(this); ServiceHelper.initServices(this);
// Initialize image loader // Initialize image loader
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
PicassoHelper.init(this); PicassoHelper.init(this);
PicassoHelper.setShouldLoadImages(PreferenceManager.getDefaultSharedPreferences(this) PicassoHelper.setShouldLoadImages(
.getBoolean(getString(R.string.download_thumbnail_key), true)); prefs.getBoolean(getString(R.string.download_thumbnail_key), true));
PicassoHelper.setIndicatorsEnabled(BuildConfig.DEBUG
&& prefs.getBoolean(getString(R.string.show_image_indicators_key), false));
configureRxJavaErrorHandler(); configureRxJavaErrorHandler();

View file

@ -71,6 +71,10 @@ public final class PicassoHelper {
picassoInstance.cancelTag(tag); picassoInstance.cancelTag(tag);
} }
public static void setIndicatorsEnabled(final boolean enabled) {
picassoInstance.setIndicatorsEnabled(enabled); // useful for debugging
}
public static void setShouldLoadImages(final boolean shouldLoadImages) { public static void setShouldLoadImages(final boolean shouldLoadImages) {
PicassoHelper.shouldLoadImages = shouldLoadImages; PicassoHelper.shouldLoadImages = shouldLoadImages;
} }

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources translatable="false"> <resources xmlns:tools="http://schemas.android.com/tools" translatable="false">
<!-- App versioning --> <!-- App versioning -->
<string name="last_used_version" translatable="false">last_used_version</string> <string name="last_used_version" translatable="false">last_used_version</string>
<string name="last_used_preferences_version" translatable="false">last_used_preferences_version</string> <string name="last_used_preferences_version" translatable="false">last_used_preferences_version</string>
@ -139,13 +139,13 @@
<string name="scale_to_square_image_in_notifications_key" translatable="false">scale_to_square_image_in_notifications</string> <string name="scale_to_square_image_in_notifications_key" translatable="false">scale_to_square_image_in_notifications</string>
<string name="notification_slot_0_key" translatable="false">notification_slot_0_key</string> <string name="notification_slot_0_key" translatable="false">notification_slot_0_key</string>
<string name="notification_slot_1_key" translatable="false">notification_slot_1_key</string> <string name="notification_slot_1_key" translatable="false" tools:ignore="Typos">notification_slot_1_key</string>
<string name="notification_slot_2_key" translatable="false">notification_slot_2_key</string> <string name="notification_slot_2_key" translatable="false">notification_slot_2_key</string>
<string name="notification_slot_3_key" translatable="false">notification_slot_3_key</string> <string name="notification_slot_3_key" translatable="false">notification_slot_3_key</string>
<string name="notification_slot_4_key" translatable="false">notification_slot_4_key</string> <string name="notification_slot_4_key" translatable="false">notification_slot_4_key</string>
<string name="notification_slot_compact_0_key" translatable="false">notification_slot_compact_0_key</string> <string name="notification_slot_compact_0_key" translatable="false">notification_slot_compact_0_key</string>
<string name="notification_slot_compact_1_key" translatable="false">notification_slot_compact_1_key</string> <string name="notification_slot_compact_1_key" translatable="false" tools:ignore="Typos">notification_slot_compact_1_key</string>
<string name="notification_slot_compact_2_key" translatable="false">notification_slot_compact_2_key</string> <string name="notification_slot_compact_2_key" translatable="false">notification_slot_compact_2_key</string>
<string name="notification_colorize_key" translatable="false">notification_colorize_key</string> <string name="notification_colorize_key" translatable="false">notification_colorize_key</string>
@ -189,6 +189,7 @@
<string name="show_original_time_ago_key" translatable="false">show_original_time_ago_key</string> <string name="show_original_time_ago_key" translatable="false">show_original_time_ago_key</string>
<string name="disable_media_tunneling_key" translatable="false">disable_media_tunneling_key</string> <string name="disable_media_tunneling_key" translatable="false">disable_media_tunneling_key</string>
<string name="crash_the_app_key" translatable="false">crash_the_app_key</string> <string name="crash_the_app_key" translatable="false">crash_the_app_key</string>
<string name="show_image_indicators_key" translatable="false">show_image_indicators_key</string>
<!-- THEMES --> <!-- THEMES -->
<string name="theme_key" translatable="false">theme</string> <string name="theme_key" translatable="false">theme</string>

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<string name="main_bg_subtitle">Tap the magnifying glass to get started.</string> <string name="main_bg_subtitle">Tap the magnifying glass to get started.</string>
<string name="view_count_text">%1$s views</string> <string name="view_count_text">%1$s views</string>
<string name="upload_date_text">Published on %1$s</string> <string name="upload_date_text">Published on %1$s</string>
@ -526,6 +528,8 @@
<string name="show_original_time_ago_summary">Original texts from services will be visible in stream items</string> <string name="show_original_time_ago_summary">Original texts from services will be visible in stream items</string>
<string name="disable_media_tunneling_title">Disable media tunneling</string> <string name="disable_media_tunneling_title">Disable media tunneling</string>
<string name="disable_media_tunneling_summary">Disable media tunneling if you experience a black screen or stuttering on video playback</string> <string name="disable_media_tunneling_summary">Disable media tunneling if you experience a black screen or stuttering on video playback</string>
<string name="show_image_indicators_title">Show image indicators</string>
<string name="show_image_indicators_summary">Show Picasso colored ribbons on top of images indicating their source: red for network, blue for disk and green for memory</string>
<string name="crash_the_app">Crash the app</string> <string name="crash_the_app">Crash the app</string>
<!-- Subscriptions import/export --> <!-- Subscriptions import/export -->
<string name="import_export_title">Import/export</string> <string name="import_export_title">Import/export</string>

View file

@ -42,6 +42,13 @@
app:singleLineTitle="false" app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/show_image_indicators_key"
android:summary="@string/show_image_indicators_summary"
android:title="@string/show_image_indicators_title"
app:iconSpaceReserved="false" />
<Preference <Preference
android:key="@string/crash_the_app_key" android:key="@string/crash_the_app_key"
android:title="@string/crash_the_app" android:title="@string/crash_the_app"