diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 51e9652aa..21424cbcf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -235,7 +235,7 @@ class PagerPageHolder( */ private fun setError() { progressIndicator.hide() - showErrorLayout(withOpenInWebView = false) + showErrorLayout() } override fun onImageLoaded() { @@ -248,8 +248,7 @@ class PagerPageHolder( */ override fun onImageLoadError() { super.onImageLoadError() - progressIndicator.hide() - showErrorLayout(withOpenInWebView = true) + setError() } /** @@ -260,23 +259,27 @@ class PagerPageHolder( viewer.activity.hideMenu() } - private fun showErrorLayout(withOpenInWebView: Boolean): ReaderErrorBinding { + private fun showErrorLayout(): ReaderErrorBinding { if (errorLayout == null) { errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), this, true) errorLayout?.actionRetry?.viewer = viewer errorLayout?.actionRetry?.setOnClickListener { page.chapter.pageLoader?.retryPage(page) } - val imageUrl = page.imageUrl - if (imageUrl.orEmpty().startsWith("http", true)) { + } + + val imageUrl = page.imageUrl + errorLayout?.actionOpenInWebView?.isVisible = imageUrl != null + if (imageUrl != null) { + if (imageUrl.startsWith("http", true)) { errorLayout?.actionOpenInWebView?.viewer = viewer errorLayout?.actionOpenInWebView?.setOnClickListener { - val intent = WebViewActivity.newIntent(context, imageUrl!!) + val intent = WebViewActivity.newIntent(context, imageUrl) context.startActivity(intent) } } } - errorLayout?.actionOpenInWebView?.isVisible = withOpenInWebView + errorLayout?.root?.isVisible = true return errorLayout!! } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index 6503457c4..b0f2fae72 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -80,7 +80,7 @@ class WebtoonPageHolder( refreshLayoutParams() frame.onImageLoaded = { onImageDecoded() } - frame.onImageLoadError = { onImageDecodeError() } + frame.onImageLoadError = { setError() } frame.onScaleChanged = { viewer.activity.hideMenu() } } @@ -240,7 +240,7 @@ class WebtoonPageHolder( */ private fun setError() { progressContainer.isVisible = false - initErrorLayout(withOpenInWebView = false) + initErrorLayout() } /** @@ -251,14 +251,6 @@ class WebtoonPageHolder( removeErrorLayout() } - /** - * Called when the image fails to decode. - */ - private fun onImageDecodeError() { - progressContainer.isVisible = false - initErrorLayout(withOpenInWebView = true) - } - /** * Creates a new progress bar. */ @@ -278,22 +270,26 @@ class WebtoonPageHolder( /** * Initializes a button to retry pages. */ - private fun initErrorLayout(withOpenInWebView: Boolean): ReaderErrorBinding { + private fun initErrorLayout(): ReaderErrorBinding { if (errorLayout == null) { errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), frame, true) errorLayout?.root?.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, (parentHeight * 0.8).toInt()) errorLayout?.actionRetry?.setOnClickListener { page?.let { it.chapter.pageLoader?.retryPage(it) } } - val imageUrl = page?.imageUrl - if (imageUrl.orEmpty().startsWith("http", true)) { + } + + val imageUrl = page?.imageUrl + errorLayout?.actionOpenInWebView?.isVisible = imageUrl != null + if (imageUrl != null) { + if (imageUrl.startsWith("http", true)) { errorLayout?.actionOpenInWebView?.setOnClickListener { - val intent = WebViewActivity.newIntent(context, imageUrl!!) + val intent = WebViewActivity.newIntent(context, imageUrl) context.startActivity(intent) } } } - errorLayout?.actionOpenInWebView?.isVisible = withOpenInWebView + return errorLayout!! }