Fixes for api<23

This commit is contained in:
Koitharu
2022-03-28 18:48:36 +03:00
parent 5d2c046d53
commit 0c1ec2b0fc
26 changed files with 331 additions and 244 deletions

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.base.ui.widgets
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
@@ -14,10 +15,12 @@ import androidx.annotation.AttrRes
import androidx.appcompat.widget.AppCompatCheckedTextView
import androidx.core.content.res.use
import androidx.core.content.withStyledAttributes
import com.google.android.material.ripple.RippleUtils
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import org.koitharu.kotatsu.R
@SuppressLint("RestrictedApi")
class ListItemTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
@@ -33,9 +36,12 @@ class ListItemTextView @JvmOverloads constructor(
init {
context.withStyledAttributes(attrs, R.styleable.ListItemTextView, defStyleAttr) {
val itemRippleColor = getColorStateList(R.styleable.ListItemTextView_rippleColor)
?: getRippleColorFallback(context)
val shape = createShapeDrawable(this)
background = RippleDrawable(
getColorStateList(R.styleable.ListItemTextView_rippleColor) ?: getRippleColorFallback(context),
createShapeDrawable(this),
RippleUtils.sanitizeRippleDrawableColor(itemRippleColor),
shape,
ShapeDrawable(RectShape()),
)
checkedDrawableStart = getDrawable(R.styleable.ListItemTextView_checkedDrawableStart)

View File

@@ -286,7 +286,7 @@ class ReaderActivity : BaseFullscreenActivity<ActivityReaderBinding>(),
private fun onPageSaved(uri: Uri?) {
if (uri != null) {
Snackbar.make(binding.container, R.string.page_saved, Snackbar.LENGTH_INDEFINITE)
Snackbar.make(binding.container, R.string.page_saved, Snackbar.LENGTH_LONG)
.setAnchorView(binding.appbarBottom)
.setAction(R.string.share) {
ShareHelper(this).shareImage(uri)

View File

@@ -6,6 +6,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
import org.koitharu.kotatsu.reader.domain.PageLoader
abstract class BasePageHolder<B : ViewBinding>(
@@ -16,6 +17,7 @@ abstract class BasePageHolder<B : ViewBinding>(
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
protected val delegate = PageHolderDelegate(loader, settings, this, exceptionResolver)
protected val bindingInfo = LayoutPageInfoBinding.bind(binding.root)
val context: Context
get() = itemView.context

View File

@@ -15,8 +15,7 @@ import org.koitharu.kotatsu.databinding.ItemPageBinding
import org.koitharu.kotatsu.reader.domain.PageLoader
import org.koitharu.kotatsu.reader.ui.pager.BasePageHolder
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
import org.koitharu.kotatsu.utils.ext.ifZero
import org.koitharu.kotatsu.utils.ext.*
open class PageHolder(
binding: ItemPageBinding,
@@ -29,7 +28,7 @@ open class PageHolder(
init {
binding.ssiv.setOnImageEventListener(delegate)
@Suppress("LeakingThis")
binding.buttonRetry.setOnClickListener(this)
bindingInfo.buttonRetry.setOnClickListener(this)
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
}
@@ -45,17 +44,17 @@ open class PageHolder(
}
override fun onLoadingStarted() {
binding.layoutError.isVisible = false
binding.progressBar.isVisible = true
bindingInfo.layoutError.isVisible = false
bindingInfo.progressBar.showCompat()
binding.ssiv.recycle()
}
override fun onProgressChanged(progress: Int) {
if (progress in 0..100) {
binding.progressBar.isIndeterminate = false
binding.progressBar.setProgressCompat(progress, true)
bindingInfo.progressBar.isIndeterminate = false
bindingInfo.progressBar.setProgressCompat(progress, true)
} else {
binding.progressBar.isIndeterminate = true
bindingInfo.progressBar.isIndeterminate = true
}
}
@@ -100,7 +99,7 @@ open class PageHolder(
}
override fun onImageShown() {
binding.progressBar.isVisible = false
bindingInfo.progressBar.hideCompat()
}
override fun onClick(v: View) {
@@ -110,11 +109,11 @@ open class PageHolder(
}
override fun onError(e: Throwable) {
binding.textViewError.text = e.getDisplayMessage(context.resources)
binding.buttonRetry.setText(
bindingInfo.textViewError.text = e.getDisplayMessage(context.resources)
bindingInfo.buttonRetry.setText(
ExceptionResolver.getResolveStringId(e).ifZero { R.string.try_again }
)
binding.layoutError.isVisible = true
binding.progressBar.isVisible = false
bindingInfo.layoutError.isVisible = true
bindingInfo.progressBar.hideCompat()
}
}

View File

@@ -13,8 +13,7 @@ import org.koitharu.kotatsu.databinding.ItemPageWebtoonBinding
import org.koitharu.kotatsu.reader.domain.PageLoader
import org.koitharu.kotatsu.reader.ui.pager.BasePageHolder
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
import org.koitharu.kotatsu.utils.ext.ifZero
import org.koitharu.kotatsu.utils.ext.*
class WebtoonHolder(
@@ -29,7 +28,7 @@ class WebtoonHolder(
init {
binding.ssiv.setOnImageEventListener(delegate)
binding.buttonRetry.setOnClickListener(this)
bindingInfo.buttonRetry.setOnClickListener(this)
}
override fun onBind(data: ReaderPage) {
@@ -42,17 +41,17 @@ class WebtoonHolder(
}
override fun onLoadingStarted() {
binding.layoutError.isVisible = false
binding.progressBar.isVisible = true
bindingInfo.layoutError.isVisible = false
bindingInfo.progressBar.showCompat()
binding.ssiv.recycle()
}
override fun onProgressChanged(progress: Int) {
if (progress in 0..100) {
binding.progressBar.isIndeterminate = false
binding.progressBar.setProgressCompat(progress, true)
bindingInfo.progressBar.isIndeterminate = false
bindingInfo.progressBar.setProgressCompat(progress, true)
} else {
binding.progressBar.isIndeterminate = true
bindingInfo.progressBar.isIndeterminate = true
}
}
@@ -77,7 +76,7 @@ class WebtoonHolder(
}
override fun onImageShown() {
binding.progressBar.isVisible = false
bindingInfo.progressBar.hideCompat()
}
override fun onClick(v: View) {
@@ -87,12 +86,12 @@ class WebtoonHolder(
}
override fun onError(e: Throwable) {
binding.textViewError.text = e.getDisplayMessage(context.resources)
binding.buttonRetry.setText(
bindingInfo.textViewError.text = e.getDisplayMessage(context.resources)
bindingInfo.buttonRetry.setText(
ExceptionResolver.getResolveStringId(e).ifZero { R.string.try_again }
)
binding.layoutError.isVisible = true
binding.progressBar.isVisible = false
bindingInfo.layoutError.isVisible = true
bindingInfo.progressBar.hideCompat()
}
fun getScrollY() = binding.ssiv.getScroll()

View File

@@ -42,7 +42,7 @@ class SettingsActivity :
override fun onTitleChanged(title: CharSequence?, color: Int) {
super.onTitleChanged(title, color)
binding.collapsingToolbarLayout.title = title
binding.collapsingToolbarLayout?.title = title
}
override fun onStart() {

View File

@@ -0,0 +1,25 @@
package org.koitharu.kotatsu.utils.ext
import android.os.Build
import android.widget.ProgressBar
import androidx.core.view.isVisible
import androidx.core.widget.ContentLoadingProgressBar
import com.google.android.material.progressindicator.BaseProgressIndicator
fun ProgressBar.setProgressCompat(progress: Int, animate: Boolean) = when {
this is BaseProgressIndicator<*> -> setProgressCompat(progress, animate)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> setProgress(progress, animate)
else -> setProgress(progress)
}
fun ProgressBar.showCompat() = when (this) {
is BaseProgressIndicator<*> -> show()
is ContentLoadingProgressBar -> show()
else -> isVisible = true
}
fun ProgressBar.hideCompat() = when (this) {
is BaseProgressIndicator<*> -> hide()
is ContentLoadingProgressBar -> hide()
else -> isVisible = false
}