This commit is contained in:
Koitharu
2022-07-09 08:51:52 +03:00
parent b519b53419
commit f5dd1c39ce
7 changed files with 22 additions and 35 deletions

View File

@@ -38,6 +38,7 @@ import androidx.annotation.StyleableRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.content.withStyledAttributes
import androidx.core.view.GravityCompat
import androidx.core.view.isVisible
@@ -45,10 +46,6 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.utils.ext.*
import org.koitharu.kotatsu.utils.ext.getCompatDrawable
import org.koitharu.kotatsu.utils.ext.isLayoutReversed
import org.koitharu.kotatsu.utils.ext.setCompatTint
import org.koitharu.kotatsu.utils.ext.wrap
import kotlin.math.roundToInt
private const val BUBBLE_ANIM_DURATION = 100L
@@ -77,6 +74,7 @@ class FastScroller : LinearLayout {
@ColorInt
private var bubbleColor = 0
@ColorInt
private var handleColor = 0
@@ -385,11 +383,11 @@ class FastScroller : LinearLayout {
*/
fun setTrackColor(@ColorInt color: Int) {
if (trackImage == null) {
context.getCompatDrawable(R.drawable.fastscroll_track)?.let { trackImage = it.wrap().mutate() }
trackImage = ContextCompat.getDrawable(context, R.drawable.fastscroll_track)
}
trackImage?.let {
it.setCompatTint(color)
it.setTint(color)
trackView.setImageDrawable(it)
}
}
@@ -403,11 +401,11 @@ class FastScroller : LinearLayout {
handleColor = color
if (handleImage == null) {
context.getCompatDrawable(R.drawable.fastscroll_handle)?.let { handleImage = it.wrap().mutate() }
handleImage = ContextCompat.getDrawable(context, R.drawable.fastscroll_handle)
}
handleImage?.let {
it.setCompatTint(handleColor)
it.setTint(handleColor)
handleView.setImageDrawable(it)
}
}
@@ -433,11 +431,11 @@ class FastScroller : LinearLayout {
bubbleColor = color
if (bubbleImage == null) {
context.getCompatDrawable(bubbleSize.drawableId)?.let { bubbleImage = it.wrap().mutate() }
bubbleImage = ContextCompat.getDrawable(context, bubbleSize.drawableId)
}
bubbleImage?.let {
it.setCompatTint(bubbleColor)
it.setTint(bubbleColor)
bubbleView.background = it
}
}
@@ -566,7 +564,7 @@ class FastScroller : LinearLayout {
private fun setHandleSelected(selected: Boolean) {
handleView.isSelected = selected
handleImage?.setCompatTint(if (selected) bubbleColor else handleColor)
handleImage?.setTint(if (selected) bubbleColor else handleColor)
}
private fun TypedArray.getSize(@StyleableRes index: Int, defValue: Int) = getInt(index, defValue).let { ordinal ->

View File

@@ -1,8 +1,8 @@
package org.koitharu.kotatsu.core.ui
import android.app.ActivityManager
import android.content.Context
import android.text.Html
import androidx.core.content.getSystemService
import coil.ComponentRegistry
import coil.ImageLoader
import coil.disk.DiskCache
@@ -13,7 +13,6 @@ import org.koin.dsl.module
import org.koitharu.kotatsu.core.parser.FaviconMapper
import org.koitharu.kotatsu.local.data.CacheDir
import org.koitharu.kotatsu.local.data.CbzFetcher
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
import org.koitharu.kotatsu.utils.image.CoilImageGetter
val uiModule
@@ -31,6 +30,7 @@ val uiModule
.directory(rootDir.resolve(CacheDir.THUMBS.dir))
.build()
}
val activityManager = androidContext().getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
ImageLoader.Builder(androidContext())
.okHttpClient(httpClientFactory)
.interceptorDispatcher(Dispatchers.Default)
@@ -38,8 +38,7 @@ val uiModule
.decoderDispatcher(Dispatchers.Default)
.transformationDispatcher(Dispatchers.Default)
.diskCache(diskCacheFactory)
.crossfade((300 * androidContext().animatorDurationScale).toInt())
.allowRgb565(androidContext().getSystemService<ActivityManager>()!!.isLowRamDevice)
.allowRgb565(activityManager.isLowRamDevice)
.components(
ComponentRegistry.Builder()
.add(CbzFetcher.Factory())

View File

@@ -229,7 +229,6 @@ class DetailsFragment :
return
}
imageViewCover.newImageRequest(scrobbling.coverUrl)
.crossfade((300 * context?.animatorDurationScale!!).toInt())
.placeholder(R.drawable.ic_placeholder)
.fallback(R.drawable.ic_placeholder)
.error(R.drawable.ic_placeholder)
@@ -358,7 +357,7 @@ class DetailsFragment :
val request = ImageRequest.Builder(context ?: return)
.target(binding.imageViewCover)
.data(imageUrl)
.crossfade((300 * context?.animatorDurationScale!!).toInt())
.crossfade(context)
.referer(manga.publicUrl)
.lifecycle(viewLifecycleOwner)
lastResult?.drawable?.let {

View File

@@ -27,7 +27,7 @@ import org.koitharu.kotatsu.image.ui.ImageActivity
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingInfo
import org.koitharu.kotatsu.scrobbling.domain.model.ScrobblingStatus
import org.koitharu.kotatsu.scrobbling.ui.selector.ScrobblingSelectorBottomSheet
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
import org.koitharu.kotatsu.utils.ext.crossfade
import org.koitharu.kotatsu.utils.ext.enqueueWith
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
@@ -111,7 +111,7 @@ class ScrobblingInfoBottomSheet :
ImageRequest.Builder(context ?: return)
.target(binding.imageViewCover)
.data(scrobbling.coverUrl)
.crossfade((300 * context?.animatorDurationScale!!).toInt())
.crossfade(context)
.lifecycle(viewLifecycleOwner)
.placeholder(R.drawable.ic_placeholder)
.fallback(R.drawable.ic_placeholder)

View File

@@ -13,12 +13,8 @@ import android.provider.Settings
import android.view.ViewGroup
import android.view.ViewPropertyAnimator
import android.view.Window
import android.view.animation.Animation
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.DrawableRes
import androidx.constraintlayout.motion.widget.MotionScene
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.descendants
import androidx.lifecycle.Lifecycle
@@ -124,8 +120,6 @@ fun Window.setNavigationBarTransparentCompat(context: Context, elevation: Float
val Context.animatorDurationScale: Float
get() = Settings.Global.getFloat(this.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f)
internal fun Context.getCompatDrawable(@DrawableRes drawableId: Int) = ContextCompat.getDrawable(this, drawableId)
fun ViewPropertyAnimator.applySystemAnimatorScale(context: Context): ViewPropertyAnimator = apply {
this.duration = (this.duration * context.animatorDurationScale).toLong()
}

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.utils.ext
import android.content.Context
import android.widget.ImageView
import androidx.core.graphics.drawable.toBitmap
import coil.ImageLoader
@@ -13,7 +14,7 @@ import org.koitharu.kotatsu.utils.progress.ImageRequestIndicatorListener
fun ImageView.newImageRequest(url: String?) = ImageRequest.Builder(context)
.data(url)
.crossfade((300 * context.animatorDurationScale).toInt())
.crossfade(context)
.target(this)
fun ImageRequest.Builder.enqueueWith(loader: ImageLoader) = loader.enqueue(build())
@@ -38,4 +39,9 @@ fun ImageRequest.Builder.referer(referer: String): ImageRequest.Builder {
fun ImageRequest.Builder.indicator(indicator: BaseProgressIndicator<*>): ImageRequest.Builder {
return listener(ImageRequestIndicatorListener(indicator))
}
fun ImageRequest.Builder.crossfade(context: Context?): ImageRequest.Builder {
val scale = context?.animatorDurationScale ?: 1f
return crossfade((300 * scale).toInt())
}

View File

@@ -1,9 +0,0 @@
package org.koitharu.kotatsu.utils.ext
import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import androidx.core.graphics.drawable.DrawableCompat
internal fun Drawable.setCompatTint(@ColorInt color: Int) = DrawableCompat.setTint(this, color)
internal fun Drawable.wrap(): Drawable = DrawableCompat.wrap(this)