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.
This commit is contained in:
Ivan Iskandar 2022-01-09 00:53:20 +07:00 committed by GitHub
parent e0d2a01bc8
commit b8f7653fb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 13 deletions

View File

@ -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

View File

@ -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 ->

View File

@ -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)
}

View File

@ -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)
}