From 092a265e6ddb9183e364f4c85a9a329f8bad5148 Mon Sep 17 00:00:00 2001 From: Zakhar Timoshenko Date: Sat, 6 Aug 2022 20:18:32 +0300 Subject: [PATCH] Some update error message --- .../kotatsu/list/ui/model/ListModelConversionExt.kt | 13 +++++++++---- .../org/koitharu/kotatsu/utils/ext/ThrowableExt.kt | 10 ++++++---- app/src/main/res/drawable/ic_auth_key_large.xml | 11 +++++++++++ app/src/main/res/drawable/ic_bot_large.xml | 11 +++++++++++ app/src/main/res/drawable/ic_plug_large.xml | 11 +++++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/drawable/ic_auth_key_large.xml create mode 100644 app/src/main/res/drawable/ic_bot_large.xml create mode 100644 app/src/main/res/drawable/ic_plug_large.xml diff --git a/app/src/main/java/org/koitharu/kotatsu/list/ui/model/ListModelConversionExt.kt b/app/src/main/java/org/koitharu/kotatsu/list/ui/model/ListModelConversionExt.kt index b2f082a7e..73e57d848 100644 --- a/app/src/main/java/org/koitharu/kotatsu/list/ui/model/ListModelConversionExt.kt +++ b/app/src/main/java/org/koitharu/kotatsu/list/ui/model/ListModelConversionExt.kt @@ -1,5 +1,7 @@ package org.koitharu.kotatsu.list.ui.model +import java.net.SocketTimeoutException +import java.net.UnknownHostException import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver @@ -79,16 +81,19 @@ fun Throwable.toErrorState(canRetry: Boolean = true) = ErrorState( exception = this, icon = getErrorIcon(this), canRetry = canRetry, - buttonText = ExceptionResolver.getResolveStringId(this).ifZero { R.string.try_again } + buttonText = ExceptionResolver.getResolveStringId(this).ifZero { R.string.try_again }, ) fun Throwable.toErrorFooter() = ErrorFooter( exception = this, - icon = R.drawable.ic_alert_outline + icon = R.drawable.ic_alert_outline, ) private fun getErrorIcon(error: Throwable) = when (error) { - is AuthRequiredException, - is CloudFlareProtectedException -> R.drawable.ic_denied_large + is AuthRequiredException -> R.drawable.ic_auth_key_large + is CloudFlareProtectedException -> R.drawable.ic_bot_large + is UnknownHostException, + is SocketTimeoutException, + -> R.drawable.ic_plug_large else -> R.drawable.ic_error_large } diff --git a/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt b/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt index 9d4315d41..5e5efa840 100644 --- a/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt +++ b/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt @@ -2,6 +2,8 @@ package org.koitharu.kotatsu.utils.ext import android.content.ActivityNotFoundException import android.content.res.Resources +import java.net.SocketTimeoutException +import java.net.UnknownHostException import okio.FileNotFoundException import org.acra.ktx.sendWithAcra import org.koitharu.kotatsu.R @@ -10,20 +12,20 @@ import org.koitharu.kotatsu.parsers.exception.AuthRequiredException import org.koitharu.kotatsu.parsers.exception.ContentUnavailableException import org.koitharu.kotatsu.parsers.exception.NotFoundException import org.koitharu.kotatsu.parsers.exception.ParseException -import java.net.SocketTimeoutException fun Throwable.getDisplayMessage(resources: Resources): String = when (this) { is AuthRequiredException -> resources.getString(R.string.auth_required) is CloudFlareProtectedException -> resources.getString(R.string.captcha_required) is ActivityNotFoundException, - is UnsupportedOperationException -> resources.getString(R.string.operation_not_supported) + is UnsupportedOperationException, -> resources.getString(R.string.operation_not_supported) is UnsupportedFileException -> resources.getString(R.string.text_file_not_supported) is FileNotFoundException -> resources.getString(R.string.file_not_found) is EmptyHistoryException -> resources.getString(R.string.history_is_empty) is SyncApiException, - is ContentUnavailableException -> message + is ContentUnavailableException, -> message is ParseException -> shortMessage - is SocketTimeoutException -> resources.getString(R.string.network_error) + is UnknownHostException, + is SocketTimeoutException, -> resources.getString(R.string.network_error) is WrongPasswordException -> resources.getString(R.string.wrong_password) is NotFoundException -> resources.getString(R.string.not_found_404) else -> localizedMessage diff --git a/app/src/main/res/drawable/ic_auth_key_large.xml b/app/src/main/res/drawable/ic_auth_key_large.xml new file mode 100644 index 000000000..e1f925ee8 --- /dev/null +++ b/app/src/main/res/drawable/ic_auth_key_large.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_bot_large.xml b/app/src/main/res/drawable/ic_bot_large.xml new file mode 100644 index 000000000..f96226251 --- /dev/null +++ b/app/src/main/res/drawable/ic_bot_large.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_plug_large.xml b/app/src/main/res/drawable/ic_plug_large.xml new file mode 100644 index 000000000..8930996e4 --- /dev/null +++ b/app/src/main/res/drawable/ic_plug_large.xml @@ -0,0 +1,11 @@ + + +