Skip to content

Commit efd05ee

Browse files
committed
Add debug prefs to show error snackbar/notification
1 parent 5aa2173 commit efd05ee

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsFragment.java

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import androidx.preference.Preference;
66

77
import org.schabi.newpipe.R;
8+
import org.schabi.newpipe.error.ErrorInfo;
9+
import org.schabi.newpipe.error.ErrorUtil;
10+
import org.schabi.newpipe.error.UserAction;
811
import org.schabi.newpipe.util.PicassoHelper;
912

1013
import leakcanary.LeakCanary;
@@ -20,10 +23,16 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
2023
= findPreference(getString(R.string.show_image_indicators_key));
2124
final Preference crashTheAppPreference
2225
= findPreference(getString(R.string.crash_the_app_key));
26+
final Preference showErrorSnackbarPreference
27+
= findPreference(getString(R.string.show_error_snackbar_key));
28+
final Preference createErrorNotificationPreference
29+
= findPreference(getString(R.string.create_error_notification_key));
2330

2431
assert showMemoryLeaksPreference != null;
2532
assert showImageIndicatorsPreference != null;
2633
assert crashTheAppPreference != null;
34+
assert showErrorSnackbarPreference != null;
35+
assert createErrorNotificationPreference != null;
2736

2837
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
2938
startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent());
@@ -38,5 +47,17 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
3847
crashTheAppPreference.setOnPreferenceClickListener(preference -> {
3948
throw new RuntimeException();
4049
});
50+
51+
showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> {
52+
ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this,
53+
"Dummy", new RuntimeException("Dummy"));
54+
return true;
55+
});
56+
57+
createErrorNotificationPreference.setOnPreferenceClickListener(preference -> {
58+
ErrorUtil.createNotification(requireContext(),
59+
new ErrorInfo(new RuntimeException("Dummy"), UserAction.UI_ERROR, "Dummy"));
60+
return true;
61+
});
4162
}
4263
}

app/src/main/res/values/settings_keys.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,11 @@
186186
<string name="allow_disposed_exceptions_key" translatable="false">allow_disposed_exceptions_key</string>
187187
<string name="show_original_time_ago_key" translatable="false">show_original_time_ago_key</string>
188188
<string name="disable_media_tunneling_key" translatable="false">disable_media_tunneling_key</string>
189-
<string name="crash_the_app_key" translatable="false">crash_the_app_key</string>
190189
<string name="show_image_indicators_key" translatable="false">show_image_indicators_key</string>
191190
<string name="show_crash_the_player_key" translatable="false">show_crash_the_player_key</string>
191+
<string name="crash_the_app_key" translatable="false">crash_the_app_key</string>
192+
<string name="show_error_snackbar_key" translatable="false">show_error_snackbar_key</string>
193+
<string name="create_error_notification_key" translatable="false">create_error_notification_key</string>
192194

193195
<!-- THEMES -->
194196
<string name="theme_key" translatable="false">theme</string>

app/src/main/res/values/strings.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,11 @@
477477
<string name="disable_media_tunneling_summary">Disable media tunneling if you experience a black screen or stuttering on video playback</string>
478478
<string name="show_image_indicators_title">Show image indicators</string>
479479
<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>
480-
<string name="crash_the_app">Crash the app</string>
481480
<string name="show_crash_the_player_title">Show \"crash the player\"</string>
482481
<string name="show_crash_the_player_summary">Shows a crash option when using the player</string>
482+
<string name="crash_the_app">Crash the app</string>
483+
<string name="show_error_snackbar">Show an error snackbar</string>
484+
<string name="create_error_notification">Create an error notification</string>
483485
<!-- Subscriptions import/export -->
484486
<string name="import_title">Import</string>
485487
<string name="import_from">Import from</string>

app/src/main/res/xml/debug_settings.xml

+17-7
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,28 @@
4949
android:title="@string/show_image_indicators_title"
5050
app:iconSpaceReserved="false" />
5151

52+
<SwitchPreferenceCompat
53+
android:defaultValue="false"
54+
android:key="@string/show_crash_the_player_key"
55+
android:summary="@string/show_crash_the_player_summary"
56+
android:title="@string/show_crash_the_player_title"
57+
app:iconSpaceReserved="false" />
58+
5259
<Preference
5360
android:key="@string/crash_the_app_key"
5461
android:title="@string/crash_the_app"
5562
app:singleLineTitle="false"
5663
app:iconSpaceReserved="false" />
5764

58-
<SwitchPreferenceCompat
59-
android:layout_width="wrap_content"
60-
android:layout_height="wrap_content"
61-
android:defaultValue="false"
62-
android:key="@string/show_crash_the_player_key"
63-
android:summary="@string/show_crash_the_player_summary"
64-
android:title="@string/show_crash_the_player_title"
65+
<Preference
66+
android:key="@string/show_error_snackbar_key"
67+
android:title="@string/show_error_snackbar"
68+
app:singleLineTitle="false"
69+
app:iconSpaceReserved="false" />
70+
71+
<Preference
72+
android:key="@string/create_error_notification_key"
73+
android:title="@string/create_error_notification"
74+
app:singleLineTitle="false"
6575
app:iconSpaceReserved="false" />
6676
</PreferenceScreen>

0 commit comments

Comments
 (0)