mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Fix warnings in ControllerExtensions
This commit is contained in:
parent
03b18b3d4f
commit
0e9d105b1d
2 changed files with 38 additions and 38 deletions
|
@ -24,6 +24,8 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.math.MathUtils
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.view.WindowInsetsCompat.Type.ime
|
||||
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePaddingRelative
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -47,6 +49,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
|
|||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.isTablet
|
||||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||
import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
|
||||
import eu.kanade.tachiyomi.util.system.toInt
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -116,19 +119,19 @@ fun Controller.liftAppbarWith(recycler: RecyclerView, padView: Boolean = false)
|
|||
}
|
||||
}
|
||||
recycler.updatePaddingRelative(
|
||||
top = activityBinding!!.toolbar.y.toInt() + appBarHeight
|
||||
top = activityBinding!!.toolbar.y.toInt() + appBarHeight,
|
||||
bottom = recycler.rootWindowInsetsCompat?.getInsets(systemBars())?.bottom ?: 0
|
||||
)
|
||||
recycler.applyBottomAnimatedInsets(setPadding = true)
|
||||
recycler.doOnApplyWindowInsets { view, insets, _ ->
|
||||
val headerHeight = insets.systemWindowInsetTop + appBarHeight
|
||||
recycler.applyBottomAnimatedInsets(setPadding = true) { view, insets ->
|
||||
val headerHeight = insets.getInsets(systemBars()).top + appBarHeight
|
||||
view.updatePaddingRelative(top = headerHeight)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
recycler.doOnApplyWindowInsetsCompat { view, insets, _ ->
|
||||
val headerHeight = insets.getInsets(systemBars()).top + appBarHeight
|
||||
view.updatePaddingRelative(
|
||||
bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
insets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemBars()).bottom
|
||||
} else {
|
||||
insets.systemWindowInsetBottom
|
||||
}
|
||||
top = headerHeight,
|
||||
bottom = insets.getInsets(ime() or systemBars()).bottom
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +199,6 @@ fun Controller.scrollViewWith(
|
|||
var statusBarHeight = -1
|
||||
val tabBarHeight = 48.dpToPx
|
||||
activityBinding?.appBar?.y = 0f
|
||||
val isSideNavWithTabs = activityBinding?.sideNav != null && includeTabView && recycler.context.isTablet()
|
||||
val attrsArray = intArrayOf(R.attr.actionBarSize)
|
||||
val array = recycler.context.obtainStyledAttributes(attrsArray)
|
||||
var appBarHeight = (
|
||||
|
@ -224,23 +226,25 @@ fun Controller.scrollViewWith(
|
|||
var fakeBottomNavView: View? = null
|
||||
if (!customPadding) {
|
||||
recycler.updatePaddingRelative(
|
||||
top = (activity?.window?.decorView?.rootWindowInsets?.systemWindowInsetTop ?: 0) +
|
||||
appBarHeight
|
||||
top = (
|
||||
activity?.window?.decorView?.rootWindowInsetsCompat?.getInsets(systemBars())?.top
|
||||
?: 0
|
||||
) + appBarHeight
|
||||
)
|
||||
}
|
||||
recycler.doOnApplyWindowInsets { view, insets, _ ->
|
||||
val headerHeight = insets.systemWindowInsetTop + appBarHeight
|
||||
recycler.doOnApplyWindowInsetsCompat { view, insets, _ ->
|
||||
val headerHeight = insets.getInsets(systemBars()).top + appBarHeight
|
||||
if (!customPadding) view.updatePaddingRelative(
|
||||
top = headerHeight,
|
||||
bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom
|
||||
bottom = if (padBottom) insets.getInsets(systemBars()).bottom else view.paddingBottom
|
||||
)
|
||||
swipeRefreshLayout?.setProgressViewOffset(
|
||||
true,
|
||||
headerHeight + (-60).dpToPx,
|
||||
headerHeight + 10.dpToPx
|
||||
)
|
||||
statusBarHeight = insets.systemWindowInsetTop
|
||||
afterInsets?.invoke(insets)
|
||||
statusBarHeight = insets.getInsets(systemBars()).top
|
||||
afterInsets?.invoke(insets.toWindowInsets()!!)
|
||||
}
|
||||
|
||||
var toolbarColorAnim: ValueAnimator? = null
|
||||
|
@ -516,15 +520,6 @@ fun Controller.setAppBarBG(value: Float, includeTabView: Boolean = false) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) {
|
||||
val activity = activity ?: return
|
||||
permissions.forEach { permission ->
|
||||
if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(permission), requestCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Controller.requestFilePermissionsSafe(
|
||||
requestCode: Int,
|
||||
preferences: PreferencesHelper,
|
||||
|
|
|
@ -36,6 +36,8 @@ import androidx.core.graphics.ColorUtils
|
|||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsAnimationCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsCompat.Type.ime
|
||||
import androidx.core.view.WindowInsetsCompat.Type.systemBars
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePaddingRelative
|
||||
|
@ -60,6 +62,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
|
|||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.isLTR
|
||||
import eu.kanade.tachiyomi.util.system.pxToDp
|
||||
import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlin.math.max
|
||||
import kotlin.math.pow
|
||||
|
@ -135,14 +138,15 @@ object RecyclerWindowInsetsListener : View.OnApplyWindowInsetsListener {
|
|||
}
|
||||
}
|
||||
|
||||
fun View.applyBottomAnimatedInsets(bottomMargin: Int = 0, setPadding: Boolean = false) {
|
||||
fun View.applyBottomAnimatedInsets(
|
||||
bottomMargin: Int = 0,
|
||||
setPadding: Boolean = false,
|
||||
onApplyInsets: ((View, WindowInsetsCompat) -> Unit)? = null
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return
|
||||
val setInsets: ((WindowInsets) -> Unit) = { insets ->
|
||||
val bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
insets.getInsets(WindowInsets.Type.systemBars() or WindowInsets.Type.ime()).bottom
|
||||
} else {
|
||||
insets.systemWindowInsetBottom
|
||||
}
|
||||
val setInsets: ((WindowInsetsCompat) -> Unit) = { insets ->
|
||||
val bottom = insets.getInsets(systemBars() or ime()).bottom
|
||||
|
||||
if (setPadding) {
|
||||
updatePaddingRelative(bottom = bottomMargin + bottom)
|
||||
} else {
|
||||
|
@ -152,7 +156,8 @@ fun View.applyBottomAnimatedInsets(bottomMargin: Int = 0, setPadding: Boolean =
|
|||
}
|
||||
}
|
||||
var handleInsets = true
|
||||
doOnApplyWindowInsets { _, insets, _ ->
|
||||
doOnApplyWindowInsetsCompat { view, insets, _ ->
|
||||
onApplyInsets?.invoke(view, insets)
|
||||
if (handleInsets) {
|
||||
setInsets(insets)
|
||||
}
|
||||
|
@ -171,20 +176,20 @@ fun View.applyBottomAnimatedInsets(bottomMargin: Int = 0, setPadding: Boolean =
|
|||
bounds: WindowInsetsAnimationCompat.BoundsCompat
|
||||
): WindowInsetsAnimationCompat.BoundsCompat {
|
||||
handleInsets = false
|
||||
rootWindowInsets?.let { insets -> setInsets(insets) }
|
||||
rootWindowInsetsCompat?.let { insets -> setInsets(insets) }
|
||||
return super.onStart(animation, bounds)
|
||||
}
|
||||
override fun onProgress(
|
||||
insets: WindowInsetsCompat,
|
||||
runningAnimations: List<WindowInsetsAnimationCompat>
|
||||
): WindowInsetsCompat {
|
||||
insets.toWindowInsets()?.let { setInsets(it) }
|
||||
setInsets(insets)
|
||||
return insets
|
||||
}
|
||||
|
||||
override fun onEnd(animation: WindowInsetsAnimationCompat) {
|
||||
handleInsets = true
|
||||
rootWindowInsets?.let { insets -> setInsets(insets) }
|
||||
rootWindowInsetsCompat?.let { insets -> setInsets(insets) }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue