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 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 leakcanary.LeakCanary;
@ -20,10 +23,16 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
= findPreference(getString(R.string.show_image_indicators_key));
final Preference crashTheAppPreference
= 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 showImageIndicatorsPreference != null;
assert crashTheAppPreference != null;
assert showErrorSnackbarPreference != null;
assert createErrorNotificationPreference != null;
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent());
@ -38,5 +47,17 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
crashTheAppPreference.setOnPreferenceClickListener(preference -> {
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;
});
}
}