mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 08:21:49 +01:00
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:
parent
e0d2a01bc8
commit
b8f7653fb2
@ -53,9 +53,15 @@ open class ReaderPageImageView @JvmOverloads constructor(
|
|||||||
var onScaleChanged: ((newScale: Float) -> Unit)? = null
|
var onScaleChanged: ((newScale: Float) -> Unit)? = null
|
||||||
var onViewClicked: (() -> Unit)? = null
|
var onViewClicked: (() -> Unit)? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For automatic background. Will be set as background color when [onImageLoaded] is called.
|
||||||
|
*/
|
||||||
|
var pageBackground: Drawable? = null
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
open fun onImageLoaded() {
|
open fun onImageLoaded() {
|
||||||
onImageLoaded?.invoke()
|
onImageLoaded?.invoke()
|
||||||
|
background = pageBackground
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
|
@ -3,14 +3,14 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.MotionEvent
|
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
|
* 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.
|
* the pager, but this class disables that behavior to allow clickable buttons.
|
||||||
*/
|
*/
|
||||||
@SuppressLint("ViewConstructor")
|
@SuppressLint("ViewConstructor")
|
||||||
class PagerButton(context: Context, viewer: PagerViewer) : AppCompatButton(context) {
|
class PagerButton(context: Context, viewer: PagerViewer) : MaterialButton(context) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setOnTouchListener { _, event ->
|
setOnTouchListener { _, event ->
|
||||||
|
@ -6,10 +6,10 @@ import android.view.Gravity
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.setMargins
|
import androidx.core.view.setMargins
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import com.google.android.material.textview.MaterialTextView
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.InsertPage
|
import eu.kanade.tachiyomi.ui.reader.model.InsertPage
|
||||||
@ -202,7 +202,7 @@ class PagerPageHolder(
|
|||||||
* Called when the page is ready.
|
* Called when the page is ready.
|
||||||
*/
|
*/
|
||||||
private fun setImage() {
|
private fun setImage() {
|
||||||
progressIndicator.hide()
|
progressIndicator.setProgress(0)
|
||||||
retryButton?.isVisible = false
|
retryButton?.isVisible = false
|
||||||
decodeErrorLayout?.isVisible = false
|
decodeErrorLayout?.isVisible = false
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ class PagerPageHolder(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (!isAnimated) {
|
if (!isAnimated) {
|
||||||
this.background = background
|
pageBackground = background
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,6 +302,11 @@ class PagerPageHolder(
|
|||||||
initRetryButton().isVisible = true
|
initRetryButton().isVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onImageLoaded() {
|
||||||
|
super.onImageLoaded()
|
||||||
|
progressIndicator.hide()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an image fails to decode.
|
* Called when an image fails to decode.
|
||||||
*/
|
*/
|
||||||
@ -352,7 +357,7 @@ class PagerPageHolder(
|
|||||||
}
|
}
|
||||||
decodeErrorLayout = decodeLayout
|
decodeErrorLayout = decodeLayout
|
||||||
|
|
||||||
TextView(context).apply {
|
MaterialTextView(context).apply {
|
||||||
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
setMargins(margins)
|
setMargins(margins)
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
|||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.appcompat.widget.AppCompatButton
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.core.view.updateMargins
|
import androidx.core.view.updateMargins
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
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.R
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||||
@ -247,7 +247,7 @@ class WebtoonPageHolder(
|
|||||||
* Called when the page is ready.
|
* Called when the page is ready.
|
||||||
*/
|
*/
|
||||||
private fun setImage() {
|
private fun setImage() {
|
||||||
progressIndicator.hide()
|
progressIndicator.setProgress(0)
|
||||||
retryContainer?.isVisible = false
|
retryContainer?.isVisible = false
|
||||||
removeDecodeErrorLayout()
|
removeDecodeErrorLayout()
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ class WebtoonPageHolder(
|
|||||||
retryContainer = FrameLayout(context)
|
retryContainer = FrameLayout(context)
|
||||||
frame.addView(retryContainer, MATCH_PARENT, parentHeight)
|
frame.addView(retryContainer, MATCH_PARENT, parentHeight)
|
||||||
|
|
||||||
AppCompatButton(context).apply {
|
MaterialButton(context).apply {
|
||||||
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
gravity = Gravity.CENTER_HORIZONTAL
|
gravity = Gravity.CENTER_HORIZONTAL
|
||||||
setMargins(0, parentHeight / 4, 0, 0)
|
setMargins(0, parentHeight / 4, 0, 0)
|
||||||
@ -378,7 +378,7 @@ class WebtoonPageHolder(
|
|||||||
}
|
}
|
||||||
decodeErrorLayout = decodeLayout
|
decodeErrorLayout = decodeLayout
|
||||||
|
|
||||||
TextView(context).apply {
|
MaterialTextView(context).apply {
|
||||||
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
setMargins(0, margins, 0, margins)
|
setMargins(0, margins, 0, margins)
|
||||||
}
|
}
|
||||||
@ -388,7 +388,7 @@ class WebtoonPageHolder(
|
|||||||
decodeLayout.addView(this)
|
decodeLayout.addView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
AppCompatButton(context).apply {
|
MaterialButton(context).apply {
|
||||||
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
setMargins(0, margins, 0, margins)
|
setMargins(0, margins, 0, margins)
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ class WebtoonPageHolder(
|
|||||||
|
|
||||||
val imageUrl = page?.imageUrl
|
val imageUrl = page?.imageUrl
|
||||||
if (imageUrl.orEmpty().startsWith("http", true)) {
|
if (imageUrl.orEmpty().startsWith("http", true)) {
|
||||||
AppCompatButton(context).apply {
|
MaterialButton(context).apply {
|
||||||
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
setMargins(0, margins, 0, margins)
|
setMargins(0, margins, 0, margins)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user