From b8f7653fb2eec259172e8b4631cdac5f662cafda Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 9 Jan 2022 00:53:20 +0700 Subject: [PATCH] Use material components on reader error views (#6447) * Use material components on reader error views * Adjust image loading behavior Don't set automatic background color right away and keep show progress indicator until the page image is fully loaded. --- .../ui/reader/viewer/ReaderPageImageView.kt | 6 ++++++ .../ui/reader/viewer/pager/PagerButton.kt | 4 ++-- .../ui/reader/viewer/pager/PagerPageHolder.kt | 13 +++++++++---- .../ui/reader/viewer/webtoon/WebtoonPageHolder.kt | 14 +++++++------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt index 975505f45..cc3d9dc21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt @@ -53,9 +53,15 @@ open class ReaderPageImageView @JvmOverloads constructor( var onScaleChanged: ((newScale: Float) -> Unit)? = null var onViewClicked: (() -> Unit)? = null + /** + * For automatic background. Will be set as background color when [onImageLoaded] is called. + */ + var pageBackground: Drawable? = null + @CallSuper open fun onImageLoaded() { onImageLoaded?.invoke() + background = pageBackground } @CallSuper diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerButton.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerButton.kt index 57cef1c8a..0089ad5dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerButton.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerButton.kt @@ -3,14 +3,14 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import android.annotation.SuppressLint import android.content.Context import android.view.MotionEvent -import androidx.appcompat.widget.AppCompatButton +import com.google.android.material.button.MaterialButton /** * A button class to be used by child views of the pager viewer. All tap gestures are handled by * the pager, but this class disables that behavior to allow clickable buttons. */ @SuppressLint("ViewConstructor") -class PagerButton(context: Context, viewer: PagerViewer) : AppCompatButton(context) { +class PagerButton(context: Context, viewer: PagerViewer) : MaterialButton(context) { init { setOnTouchListener { _, event -> 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 80d4ac06d..c2b4b7e32 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 @@ -6,10 +6,10 @@ import android.view.Gravity import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.LinearLayout -import android.widget.TextView import androidx.core.view.isVisible import androidx.core.view.setMargins import androidx.core.view.updateLayoutParams +import com.google.android.material.textview.MaterialTextView import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.reader.model.InsertPage @@ -202,7 +202,7 @@ class PagerPageHolder( * Called when the page is ready. */ private fun setImage() { - progressIndicator.hide() + progressIndicator.setProgress(0) retryButton?.isVisible = false decodeErrorLayout?.isVisible = false @@ -244,7 +244,7 @@ class PagerPageHolder( ) ) if (!isAnimated) { - this.background = background + pageBackground = background } } } @@ -302,6 +302,11 @@ class PagerPageHolder( initRetryButton().isVisible = true } + override fun onImageLoaded() { + super.onImageLoaded() + progressIndicator.hide() + } + /** * Called when an image fails to decode. */ @@ -352,7 +357,7 @@ class PagerPageHolder( } decodeErrorLayout = decodeLayout - TextView(context).apply { + MaterialTextView(context).apply { layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(margins) } 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 6f4e670be..0674e7e63 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 @@ -7,12 +7,12 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import android.widget.LinearLayout -import android.widget.TextView -import androidx.appcompat.widget.AppCompatButton import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import androidx.core.view.updateMargins import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView +import com.google.android.material.button.MaterialButton +import com.google.android.material.textview.MaterialTextView import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.reader.model.ReaderPage @@ -247,7 +247,7 @@ class WebtoonPageHolder( * Called when the page is ready. */ private fun setImage() { - progressIndicator.hide() + progressIndicator.setProgress(0) retryContainer?.isVisible = false removeDecodeErrorLayout() @@ -346,7 +346,7 @@ class WebtoonPageHolder( retryContainer = FrameLayout(context) frame.addView(retryContainer, MATCH_PARENT, parentHeight) - AppCompatButton(context).apply { + MaterialButton(context).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { gravity = Gravity.CENTER_HORIZONTAL setMargins(0, parentHeight / 4, 0, 0) @@ -378,7 +378,7 @@ class WebtoonPageHolder( } decodeErrorLayout = decodeLayout - TextView(context).apply { + MaterialTextView(context).apply { layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(0, margins, 0, margins) } @@ -388,7 +388,7 @@ class WebtoonPageHolder( decodeLayout.addView(this) } - AppCompatButton(context).apply { + MaterialButton(context).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(0, margins, 0, margins) } @@ -402,7 +402,7 @@ class WebtoonPageHolder( val imageUrl = page?.imageUrl if (imageUrl.orEmpty().startsWith("http", true)) { - AppCompatButton(context).apply { + MaterialButton(context).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(0, margins, 0, margins) }