Surface image loading error in Reader (mihonapp/mihon#1981)

(cherry picked from commit fefa8f84982b537ca930438f7976087844d5bb9c)
This commit is contained in:
AwkwardPeak7 2025-04-13 19:46:12 +05:00 committed by Cuong-Tran
parent c72a4ab265
commit 6e966746db
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
10 changed files with 50 additions and 32 deletions

View file

@ -22,6 +22,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Significantly improve browsing speed (near instantaneous) ([@AntsyLich](https://github.com/AntsyLich)) ([#1946](https://github.com/mihonapp/mihon/pull/1946))
- Deduplicate entries when browsing ([@AntsyLich](https://github.com/AntsyLich)) ([#1957](https://github.com/mihonapp/mihon/pull/1957))
- Update non-library manga data when browsing ([@AntsyLich](https://github.com/AntsyLich)) ([#1967](https://github.com/mihonapp/mihon/pull/1967))
- Surface image loading error in Reader ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#1981](https://github.com/mihonapp/mihon/pull/1981))
### Changed
- Display all similarly named duplicates in duplicate manga dialogue ([@NarwhalHorns](https://github.com/NarwhalHorns), [@AntsyLich](https://github.com/AntsyLich)) ([#1861](https://github.com/mihonapp/mihon/pull/1861))

View file

@ -391,7 +391,7 @@ class Downloader(
try {
page.imageUrl = download.source.getImageUrl(page)
} catch (e: Throwable) {
page.status = Page.State.Error
page.status = Page.State.Error(e)
}
}
@ -482,7 +482,7 @@ class Downloader(
if (e is CancellationException) throw e
// Mark this page as error and allow to download the remaining
page.progress = 0
page.status = Page.State.Error
page.status = Page.State.Error(e)
notifier.onError(e.message, download.chapter.name, download.manga.title, download.manga.id)
}
}

View file

@ -834,7 +834,7 @@ class ReaderActivity : BaseActivity() {
?.pages
?.forEachIndexed { _, page ->
var shouldQueuePage = false
if (page.status == Page.State.Error) {
if (page.status is Page.State.Error) {
shouldQueuePage = true
} /*else if (page.status == Page.State.LoadPage ||
page.status == Page.State.DownloadImage) {
@ -875,7 +875,7 @@ class ReaderActivity : BaseActivity() {
return
}
if (curPage.status == Page.State.Error) {
if (curPage.status is Page.State.Error) {
toast(SYMR.strings.eh_boost_page_errored)
} else if (curPage.status == Page.State.LoadPage || curPage.status == Page.State.DownloadImage) {
toast(SYMR.strings.eh_boost_page_downloading)

View file

@ -703,7 +703,7 @@ class ReaderViewModel @JvmOverloads constructor(
readerChapter.requestedPage = pageIndex
chapterPageIndex = pageIndex
if (!incognitoMode && page.status != Page.State.Error) {
if (!incognitoMode && page.status is Page.State.Error) {
readerChapter.chapter.last_page_read = pageIndex
if (readerChapter.pages?.lastIndex == pageIndex ||

View file

@ -119,7 +119,7 @@ internal class HttpPageLoader(
}
// Automatically retry failed pages when subscribed to this page
if (page.status == Page.State.Error) {
if (page.status is Page.State.Error) {
page.status = Page.State.Queue
}
@ -144,7 +144,7 @@ internal class HttpPageLoader(
* Retries a page. This method is only called from user interaction on the viewer.
*/
override fun retryPage(page: ReaderPage) {
if (page.status == Page.State.Error) {
if (page.status is Page.State.Error) {
page.status = Page.State.Queue
}
// EXH -->
@ -227,7 +227,7 @@ internal class HttpPageLoader(
page.stream = { chapterCache.getImageFile(imageUrl).inputStream() }
page.status = Page.State.Ready
} catch (e: Throwable) {
page.status = Page.State.Error
page.status = Page.State.Error(e)
if (e is CancellationException) {
throw e
}

View file

@ -69,7 +69,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
private var config: Config? = null
var onImageLoaded: (() -> Unit)? = null
var onImageLoadError: (() -> Unit)? = null
var onImageLoadError: ((Throwable?) -> Unit)? = null
var onScaleChanged: ((newScale: Float) -> Unit)? = null
var onViewClicked: (() -> Unit)? = null
@ -85,8 +85,8 @@ open class ReaderPageImageView @JvmOverloads constructor(
}
@CallSuper
open fun onImageLoadError() {
onImageLoadError?.invoke()
open fun onImageLoadError(error: Throwable?) {
onImageLoadError?.invoke(error)
}
@CallSuper
@ -114,7 +114,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
}
override fun onImageLoadError(e: Exception) {
onImageLoadError()
onImageLoadError(e)
}
},
)
@ -318,7 +318,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
}
override fun onImageLoadError(e: Exception) {
this@ReaderPageImageView.onImageLoadError()
this@ReaderPageImageView.onImageLoadError(e)
}
},
)
@ -346,8 +346,10 @@ open class ReaderPageImageView @JvmOverloads constructor(
setImage(ImageSource.bitmap(image.bitmap))
isVisible = true
},
onError = {
onImageLoadError()
)
.listener(
onError = { _, result ->
onImageLoadError(result.throwable)
},
)
.size(ViewSizeResolver(this@ReaderPageImageView))
@ -423,8 +425,10 @@ open class ReaderPageImageView @JvmOverloads constructor(
isVisible = true
this@ReaderPageImageView.onImageLoaded()
},
onError = {
this@ReaderPageImageView.onImageLoadError()
)
.listener(
onError = { _, result ->
onImageLoadError(result.throwable)
},
)
.crossfade(false)

View file

@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.view.LayoutInflater
import androidx.annotation.ColorInt
import androidx.core.view.isVisible
import eu.kanade.presentation.util.formattedMessage
import eu.kanade.tachiyomi.databinding.ReaderErrorBinding
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.InsertPage
@ -23,12 +24,14 @@ import kotlinx.coroutines.supervisorScope
import logcat.LogPriority
import okio.Buffer
import okio.BufferedSource
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.core.common.util.lang.withUIContext
import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.core.common.util.system.logcat
import tachiyomi.decoder.ImageDecoder
import tachiyomi.i18n.MR
import kotlin.math.max
/**
@ -131,7 +134,7 @@ class PagerPageHolder(
}
}
Page.State.Ready -> setImage()
Page.State.Error -> setError()
is Page.State.Error -> setError(state.error)
}
}
}
@ -223,7 +226,7 @@ class PagerPageHolder(
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e)
withUIContext {
setError()
setError(e)
}
}
}
@ -415,9 +418,9 @@ class PagerPageHolder(
/**
* Called when the page has an error.
*/
private fun setError() {
private fun setError(error: Throwable?) {
progressIndicator?.hide()
showErrorLayout()
showErrorLayout(error)
}
override fun onImageLoaded() {
@ -428,9 +431,9 @@ class PagerPageHolder(
/**
* Called when an image fails to decode.
*/
override fun onImageLoadError() {
super.onImageLoadError()
setError()
override fun onImageLoadError(error: Throwable?) {
super.onImageLoadError(error)
setError(error)
}
/**
@ -441,7 +444,7 @@ class PagerPageHolder(
viewer.activity.hideMenu()
}
private fun showErrorLayout(): ReaderErrorBinding {
private fun showErrorLayout(error: Throwable?): ReaderErrorBinding {
if (errorLayout == null) {
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), this, true)
errorLayout?.actionRetry?.viewer = viewer
@ -462,6 +465,9 @@ class PagerPageHolder(
}
}
errorLayout?.errorMessage?.text = with(context) { error?.formattedMessage }
?: context.stringResource(MR.strings.decode_image_error)
errorLayout?.root?.isVisible = true
return errorLayout!!
}

View file

@ -11,6 +11,7 @@ import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updateMargins
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import eu.kanade.presentation.util.formattedMessage
import eu.kanade.tachiyomi.databinding.ReaderErrorBinding
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
@ -26,11 +27,13 @@ import kotlinx.coroutines.supervisorScope
import logcat.LogPriority
import okio.Buffer
import okio.BufferedSource
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.core.common.util.lang.withUIContext
import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.core.common.util.system.logcat
import tachiyomi.i18n.MR
/**
* Holder of the webtoon reader for a single page of a chapter.
@ -85,7 +88,7 @@ class WebtoonPageHolder(
refreshLayoutParams()
frame.onImageLoaded = { onImageDecoded() }
frame.onImageLoadError = { setError() }
frame.onImageLoadError = { error -> setError(error) }
frame.onScaleChanged = { viewer.activity.hideMenu() }
}
@ -149,7 +152,7 @@ class WebtoonPageHolder(
}
}
Page.State.Ready -> setImage()
Page.State.Error -> setError()
is Page.State.Error -> setError(state.error)
}
}
}
@ -213,7 +216,7 @@ class WebtoonPageHolder(
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e)
withUIContext {
setError()
setError(e)
}
}
}
@ -247,9 +250,9 @@ class WebtoonPageHolder(
/**
* Called when the page has an error.
*/
private fun setError() {
private fun setError(error: Throwable?) {
progressContainer.isVisible = false
initErrorLayout()
initErrorLayout(error)
}
/**
@ -284,7 +287,7 @@ class WebtoonPageHolder(
/**
* Initializes a button to retry pages.
*/
private fun initErrorLayout(): ReaderErrorBinding {
private fun initErrorLayout(error: Throwable?): ReaderErrorBinding {
if (errorLayout == null) {
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), frame, true)
errorLayout?.root?.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, (parentHeight * 0.8).toInt())
@ -304,6 +307,9 @@ class WebtoonPageHolder(
}
}
errorLayout?.errorMessage?.text = with(context) { error?.formattedMessage }
?: context.stringResource(MR.strings.decode_image_error)
return errorLayout!!
}

View file

@ -7,6 +7,7 @@
android:gravity="center">
<TextView
android:id="@+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"

View file

@ -54,6 +54,6 @@ open class Page(
data object LoadPage : State
data object DownloadImage : State
data object Ready : State
data object Error : State
data class Error(val error: Throwable) : State
}
}