Show user friendly error messages

See https://github.com/FossifyOrg/Gallery/issues/309
This commit is contained in:
Naveen Singh 2024-09-27 23:15:25 +05:30
parent 43eff348e6
commit 1edcd5d161
No known key found for this signature in database
GPG key ID: AF5D43C216778C0B
4 changed files with 31 additions and 3 deletions

View file

@ -311,7 +311,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onPlayerErrorChanged(error: PlaybackException?) { override fun onPlayerErrorChanged(error: PlaybackException?) {
binding.errorMessageHolder.errorMessage.apply { binding.errorMessageHolder.errorMessage.apply {
if (error != null) { if (error != null) {
text = error.localizedMessage ?: getString(R.string.failed_to_load_media) text = error.getFriendlyMessage(context)
setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor()) setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor())
fadeIn() fadeIn()
} else { } else {

View file

@ -1,6 +1,10 @@
package org.fossify.gallery.extensions package org.fossify.gallery.extensions
import android.content.Context
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackException.*
import androidx.media3.common.Player import androidx.media3.common.Player
import org.fossify.gallery.R
fun Player.mute() { fun Player.mute() {
volume = 0f volume = 0f
@ -9,3 +13,22 @@ fun Player.mute() {
fun Player.unmute() { fun Player.unmute() {
volume = 1f volume = 1f
} }
fun PlaybackException.getFriendlyMessage(context: Context): String? {
val resource = when (errorCode) {
ERROR_CODE_PARSING_CONTAINER_MALFORMED,
ERROR_CODE_PARSING_MANIFEST_MALFORMED -> R.string.file_is_malformed_or_corrupted
ERROR_CODE_DECODER_INIT_FAILED,
ERROR_CODE_DECODING_FAILED,
ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES -> R.string.media_exceeds_device_capabilities
ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
ERROR_CODE_DECODING_FORMAT_UNSUPPORTED,
ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED -> R.string.unsupported_format
else -> return localizedMessage ?: context.getString(R.string.failed_to_load_media)
}
return context.getString(resource)
}

View file

@ -452,7 +452,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
if (error != null) { if (error != null) {
binding.videoPreview.beGone() binding.videoPreview.beGone()
binding.videoPlayOutline.beGone() binding.videoPlayOutline.beGone()
text = error.localizedMessage ?: getString(R.string.failed_to_load_media) text = error.getFriendlyMessage(context)
setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor()) setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor())
fadeIn() fadeIn()
} else { } else {

View file

@ -34,7 +34,6 @@
<string name="reorder_by_dragging_pro">Reorder folders by dragging (Pro)</string> <string name="reorder_by_dragging_pro">Reorder folders by dragging (Pro)</string>
<string name="restore_to_path">Restoring to \'%s\'</string> <string name="restore_to_path">Restoring to \'%s\'</string>
<string name="full_storage_permission_required">Fossify Gallery needs full access to display all your photos and videos. Go to Settings > Permissions > Photos and videos > Allow all.</string> <string name="full_storage_permission_required">Fossify Gallery needs full access to display all your photos and videos. Go to Settings > Permissions > Photos and videos > Allow all.</string>
<string name="failed_to_load_media">Failed to load media.</string>
<!-- Filter --> <!-- Filter -->
<string name="filter_media">Filter media</string> <string name="filter_media">Filter media</string>
@ -242,6 +241,12 @@
<string name="toggle_favorite">Toggle favorite</string> <string name="toggle_favorite">Toggle favorite</string>
<string name="toggle_file_visibility">Toggle file visibility</string> <string name="toggle_file_visibility">Toggle file visibility</string>
<!-- Errors -->
<string name="failed_to_load_media">Failed to load media.</string>
<string name="file_is_malformed_or_corrupted">File is malformed or corrupted.</string>
<string name="media_exceeds_device_capabilities">Media exceeds device capabilities.</string>
<string name="unsupported_format">Unsupported format.</string>
<!-- FAQ --> <!-- FAQ -->
<string name="faq_1_title">How can I make Fossify Gallery the default device gallery?</string> <string name="faq_1_title">How can I make Fossify Gallery the default device gallery?</string>
<string name="faq_1_text">First you have to find the currently default gallery in the Apps section of your device settings, look for a button that says something like \"Open by default\", click on it, then select \"Clear defaults\". <string name="faq_1_text">First you have to find the currently default gallery in the Apps section of your device settings, look for a button that says something like \"Open by default\", click on it, then select \"Clear defaults\".