Proper handling network unavailable error for images
This commit is contained in:
@@ -172,8 +172,9 @@ fun Throwable.getCauseUrl(): String? = when (this) {
|
||||
}
|
||||
|
||||
private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String? = when (statusCode) {
|
||||
404 -> resources.getString(R.string.not_found_404)
|
||||
403 -> resources.getString(R.string.access_denied_403)
|
||||
HttpURLConnection.HTTP_NOT_FOUND -> resources.getString(R.string.not_found_404)
|
||||
HttpURLConnection.HTTP_FORBIDDEN -> resources.getString(R.string.access_denied_403)
|
||||
HttpURLConnection.HTTP_GATEWAY_TIMEOUT -> resources.getString(R.string.network_unavailable)
|
||||
in 500..599 -> resources.getString(R.string.server_error, statusCode)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.koitharu.kotatsu.image.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.ViewTreeObserver.OnPreDrawListener
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
@@ -33,6 +36,7 @@ import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||
import org.koitharu.kotatsu.core.util.ext.bookmarkExtra
|
||||
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||
import org.koitharu.kotatsu.core.util.ext.isNetworkError
|
||||
import org.koitharu.kotatsu.core.util.ext.mangaExtra
|
||||
import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra
|
||||
import org.koitharu.kotatsu.favourites.domain.model.Cover
|
||||
@@ -185,8 +189,17 @@ class CoverImageView @JvmOverloads constructor(
|
||||
|
||||
override fun onError(request: ImageRequest, result: ErrorResult) {
|
||||
super.onError(request, result)
|
||||
foreground = result.throwable.getShortMessage()?.let { text ->
|
||||
TextDrawable.create(context, text, materialR.attr.textAppearanceTitleSmall)
|
||||
foreground = if (result.throwable.isNetworkError()) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_offline)?.let {
|
||||
LayerDrawable(arrayOf(it)).apply {
|
||||
setLayerGravity(0, Gravity.CENTER)
|
||||
setTint(ContextCompat.getColor(context, R.color.dim_lite))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.throwable.getShortMessage()?.let { text ->
|
||||
TextDrawable.create(context, text, materialR.attr.textAppearanceTitleSmall)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
app/src/main/res/drawable/ic_offline.xml
Normal file
11
app/src/main/res/drawable/ic_offline.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M2.28,3L1,4.27L2.47,5.74C2.04,6 1.61,6.29 1.2,6.6L3,9C3.53,8.6 4.08,8.25 4.66,7.93L6.89,10.16C6.15,10.5 5.44,10.91 4.8,11.4L6.6,13.8C7.38,13.22 8.26,12.77 9.2,12.47L11.75,15C10.5,15.07 9.34,15.5 8.4,16.2L12,21L14.46,17.73L17.74,21L19,19.72M12,3C9.85,3 7.8,3.38 5.9,4.07L8.29,6.47C9.5,6.16 10.72,6 12,6C15.38,6 18.5,7.11 21,9L22.8,6.6C19.79,4.34 16.06,3 12,3M12,9C11.62,9 11.25,9 10.88,9.05L14.07,12.25C15.29,12.53 16.43,13.07 17.4,13.8L19.2,11.4C17.2,9.89 14.7,9 12,9Z" />
|
||||
</vector>
|
||||
@@ -11,6 +11,7 @@
|
||||
<color name="common_yellow">#FFF176</color>
|
||||
<color name="common_red">#E57373</color>
|
||||
<color name="dim2">#C8000000</color>
|
||||
<color name="dim_lite">#66FFFFFF</color>
|
||||
<color name="nsfw_18">#BF360C</color>
|
||||
<color name="nsfw_16">#FF6F00</color>
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<color name="grey">#424242</color>
|
||||
<color name="dim">#99000000</color>
|
||||
<color name="dim2">#C8FFFFFF</color>
|
||||
<color name="dim_lite">#66000000</color>
|
||||
<color name="warning">#E65100</color>
|
||||
<color name="launcher_background">#FFFFFF</color>
|
||||
<color name="common_green">#388E3C</color>
|
||||
|
||||
Reference in New Issue
Block a user