Add debug prefs to show error snackbar/notification

This commit is contained in:
Stypox 2021-12-02 14:56:45 +01:00
parent c8e2ab4c83
commit c000c1d455
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 44 additions and 9 deletions

View File

@ -5,6 +5,9 @@ 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.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.util.PicassoHelper; import org.schabi.newpipe.util.PicassoHelper;
import leakcanary.LeakCanary; import leakcanary.LeakCanary;
@ -20,10 +23,16 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
= findPreference(getString(R.string.show_image_indicators_key)); = 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));
final Preference showErrorSnackbarPreference
= findPreference(getString(R.string.show_error_snackbar_key));
final Preference createErrorNotificationPreference
= findPreference(getString(R.string.create_error_notification_key));
assert showMemoryLeaksPreference != null; assert showMemoryLeaksPreference != null;
assert showImageIndicatorsPreference != null; assert showImageIndicatorsPreference != null;
assert crashTheAppPreference != null; assert crashTheAppPreference != null;
assert showErrorSnackbarPreference != null;
assert createErrorNotificationPreference != null;
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent()); startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent());
@ -38,5 +47,17 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
crashTheAppPreference.setOnPreferenceClickListener(preference -> { crashTheAppPreference.setOnPreferenceClickListener(preference -> {
throw new RuntimeException(); throw new RuntimeException();
}); });
showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this,
"Dummy", new RuntimeException("Dummy"));
return true;
});
createErrorNotificationPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.createNotification(requireContext(),
new ErrorInfo(new RuntimeException("Dummy"), UserAction.UI_ERROR, "Dummy"));
return true;
});
} }
} }

View File

@ -186,9 +186,11 @@
<string name="allow_disposed_exceptions_key" translatable="false">allow_disposed_exceptions_key</string> <string name="allow_disposed_exceptions_key" translatable="false">allow_disposed_exceptions_key</string>
<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="show_image_indicators_key" translatable="false">show_image_indicators_key</string> <string name="show_image_indicators_key" translatable="false">show_image_indicators_key</string>
<string name="show_crash_the_player_key" translatable="false">show_crash_the_player_key</string> <string name="show_crash_the_player_key" translatable="false">show_crash_the_player_key</string>
<string name="crash_the_app_key" translatable="false">crash_the_app_key</string>
<string name="show_error_snackbar_key" translatable="false">show_error_snackbar_key</string>
<string name="create_error_notification_key" translatable="false">create_error_notification_key</string>
<!-- THEMES --> <!-- THEMES -->
<string name="theme_key" translatable="false">theme</string> <string name="theme_key" translatable="false">theme</string>

View File

@ -477,9 +477,11 @@
<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_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="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="show_crash_the_player_title">Show \"crash the player\"</string> <string name="show_crash_the_player_title">Show \"crash the player\"</string>
<string name="show_crash_the_player_summary">Shows a crash option when using the player</string> <string name="show_crash_the_player_summary">Shows a crash option when using the player</string>
<string name="crash_the_app">Crash the app</string>
<string name="show_error_snackbar">Show an error snackbar</string>
<string name="create_error_notification">Create an error notification</string>
<!-- Subscriptions import/export --> <!-- Subscriptions import/export -->
<string name="import_title">Import</string> <string name="import_title">Import</string>
<string name="import_from">Import from</string> <string name="import_from">Import from</string>

View File

@ -49,18 +49,28 @@
android:title="@string/show_image_indicators_title" android:title="@string/show_image_indicators_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/show_crash_the_player_key"
android:summary="@string/show_crash_the_player_summary"
android:title="@string/show_crash_the_player_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"
app:singleLineTitle="false" app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <Preference
android:layout_width="wrap_content" android:key="@string/show_error_snackbar_key"
android:layout_height="wrap_content" android:title="@string/show_error_snackbar"
android:defaultValue="false" app:singleLineTitle="false"
android:key="@string/show_crash_the_player_key" app:iconSpaceReserved="false" />
android:summary="@string/show_crash_the_player_summary"
android:title="@string/show_crash_the_player_title" <Preference
android:key="@string/create_error_notification_key"
android:title="@string/create_error_notification"
app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
</PreferenceScreen> </PreferenceScreen>