Localize parsers errors
This commit is contained in:
@@ -27,7 +27,10 @@ import java.net.SocketTimeoutException
|
|||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
private const val MSG_NO_SPACE_LEFT = "No space left on device"
|
private const val MSG_NO_SPACE_LEFT = "No space left on device"
|
||||||
private const val IMAGE_FORMAT_NO_SUPPORTED = "Image format not supported"
|
private const val IMAGE_FORMAT_NOT_SUPPORTED = "Image format not supported"
|
||||||
|
private const val MULTIPLE_GENRES_NOT_SUPPORTED = "Multiple genres are not supported by this source"
|
||||||
|
private const val MULTIPLE_STATES_NOT_SUPPORTED = "Multiple states are not supported by this source"
|
||||||
|
private const val SEARCH_NOT_SUPPORTED = "Search is not supported by this source"
|
||||||
|
|
||||||
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
||||||
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
||||||
@@ -56,8 +59,7 @@ fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
|||||||
is HttpException -> getHttpDisplayMessage(response.code, resources)
|
is HttpException -> getHttpDisplayMessage(response.code, resources)
|
||||||
is HttpStatusException -> getHttpDisplayMessage(statusCode, resources)
|
is HttpStatusException -> getHttpDisplayMessage(statusCode, resources)
|
||||||
|
|
||||||
is IOException -> getDisplayMessage(message, resources) ?: localizedMessage
|
else -> getDisplayMessage(message, resources) ?: localizedMessage
|
||||||
else -> localizedMessage
|
|
||||||
}.ifNullOrEmpty {
|
}.ifNullOrEmpty {
|
||||||
resources.getString(R.string.error_occurred)
|
resources.getString(R.string.error_occurred)
|
||||||
}
|
}
|
||||||
@@ -82,7 +84,10 @@ private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String
|
|||||||
private fun getDisplayMessage(msg: String?, resources: Resources): String? = when {
|
private fun getDisplayMessage(msg: String?, resources: Resources): String? = when {
|
||||||
msg.isNullOrEmpty() -> null
|
msg.isNullOrEmpty() -> null
|
||||||
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
|
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
|
||||||
msg.contains(IMAGE_FORMAT_NO_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
|
msg.contains(IMAGE_FORMAT_NOT_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
|
||||||
|
msg == MULTIPLE_GENRES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_genres_not_supported)
|
||||||
|
msg == MULTIPLE_STATES_NOT_SUPPORTED -> resources.getString(R.string.error_multiple_states_not_supported)
|
||||||
|
msg == SEARCH_NOT_SUPPORTED -> resources.getString(R.string.error_search_not_supported)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -530,4 +530,7 @@
|
|||||||
<string name="reader_optimize">Reduce memory consumption (beta)</string>
|
<string name="reader_optimize">Reduce memory consumption (beta)</string>
|
||||||
<string name="reader_optimize_summary">Reduce offscreen pages quality to use less memory</string>
|
<string name="reader_optimize_summary">Reduce offscreen pages quality to use less memory</string>
|
||||||
<string name="state">State</string>
|
<string name="state">State</string>
|
||||||
|
<string name="error_multiple_genres_not_supported">Filtering by multiple genres is not supported by this manga source</string>
|
||||||
|
<string name="error_multiple_states_not_supported">Filtering by multiple states is not supported by this manga source</string>
|
||||||
|
<string name="error_search_not_supported">Search is not supported by this manga source</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user