diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-02-24 22:19:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 22:19:30 +0100 |
commit | 5f00294c29548e5b9867abe34229c69feb047180 (patch) | |
tree | 8d901fb8992be07cc340074db71ada21520a1c9b /app/src/main/java/de/danoeh/antennapod/dialog | |
parent | 06347a3df9d1e342d33762f1ef77f5335a86e083 (diff) | |
download | AntennaPod-5f00294c29548e5b9867abe34229c69feb047180.zip |
More human readable player error message (#6346)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/dialog')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/MediaPlayerErrorDialog.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/MediaPlayerErrorDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/MediaPlayerErrorDialog.java new file mode 100644 index 000000000..ab5dde92d --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/dialog/MediaPlayerErrorDialog.java @@ -0,0 +1,37 @@ +package de.danoeh.antennapod.dialog; + +import android.app.Activity; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; +import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.snackbar.Snackbar; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.event.PlayerErrorEvent; +import de.danoeh.antennapod.storage.preferences.UserPreferences; + +public class MediaPlayerErrorDialog { + public static void show(Activity activity, PlayerErrorEvent event) { + final MaterialAlertDialogBuilder errorDialog = new MaterialAlertDialogBuilder(activity); + errorDialog.setTitle(R.string.error_label); + + String genericMessage = activity.getString(R.string.playback_error_generic); + SpannableString errorMessage = new SpannableString(genericMessage + "\n\n" + event.getMessage()); + errorMessage.setSpan(new ForegroundColorSpan(0x88888888), + genericMessage.length(), errorMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + errorDialog.setMessage(errorMessage); + errorDialog.setPositiveButton(android.R.string.ok, (dialog, which) -> + ((MainActivity) activity).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED)); + if (!UserPreferences.useExoplayer()) { + errorDialog.setNeutralButton(R.string.media_player_switch_to_exoplayer, (dialog, which) -> { + UserPreferences.enableExoplayer(); + ((MainActivity) activity).showSnackbarAbovePlayer( + R.string.media_player_switched_to_exoplayer, Snackbar.LENGTH_LONG); + }); + } + errorDialog.create().show(); + } +} |