improvements to expanded rounded sheets

This commit is contained in:
Jays2Kings 2022-07-01 15:07:59 -04:00
parent 3007210b85
commit 640347f941
3 changed files with 35 additions and 12 deletions

View file

@ -118,7 +118,7 @@ class RecentsController(bundle: Bundle? = null) :
private var showingDownloads = false
var headerHeight = 0
private var ogRadius = 0f
private var deviceRadius = 0f
private var deviceRadius = 0f to 0f
private var query = ""
set(value) {
@ -198,9 +198,12 @@ class RecentsController(bundle: Bundle? = null) :
setBottomPadding()
}
deviceRadius = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
it.toWindowInsets()?.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT)?.radius?.toFloat() ?: ogRadius
val wInsets = it.toWindowInsets()
val lCorner = wInsets?.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT)
val rCorner = wInsets?.getRoundedCorner(RoundedCorner.POSITION_TOP_RIGHT)
(lCorner?.radius?.toFloat() ?: 0f) to (rCorner?.radius?.toFloat() ?: 0f)
} else {
ogRadius
ogRadius to ogRadius
}
},
onBottomNavUpdate = {

View file

@ -103,7 +103,7 @@ class BrowseController :
var snackbar: Snackbar? = null
private var ogRadius = 0f
private var deviceRadius = 0f
private var deviceRadius = 0f to 0f
override val mainRecycler: RecyclerView
get() = binding.sourceRecycler
@ -146,9 +146,12 @@ class BrowseController :
setBottomPadding()
}
deviceRadius = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
it.toWindowInsets()?.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT)?.radius?.toFloat() ?: ogRadius
val wInsets = it.toWindowInsets()
val lCorner = wInsets?.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT)
val rCorner = wInsets?.getRoundedCorner(RoundedCorner.POSITION_TOP_RIGHT)
(lCorner?.radius?.toFloat() ?: 0f) to (rCorner?.radius?.toFloat() ?: 0f)
} else {
ogRadius
ogRadius to ogRadius
}
},
onBottomNavUpdate = {

View file

@ -61,6 +61,7 @@ import androidx.recyclerview.widget.RecyclerView.SmoothScroller
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.math.MathUtils
import com.google.android.material.navigation.NavigationBarItemView
import com.google.android.material.navigation.NavigationBarMenuView
import com.google.android.material.navigation.NavigationBarView
@ -79,7 +80,6 @@ import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import eu.kanade.tachiyomi.widget.StaggeredGridLayoutManagerAccurateOffset
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
@ -514,15 +514,32 @@ fun TextView.setTextColorAlpha(alpha: Int) {
setTextColor(ColorUtils.setAlphaComponent(currentTextColor, alpha))
}
fun View.updateGradiantBGRadius(ogRadius: Float, deviceRadius: Float, progress: Float, vararg updateOtherViews: View) {
fun View.updateGradiantBGRadius(
ogRadius: Float,
deviceRadius: Pair<Float, Float>,
progress: Float,
vararg updateOtherViews: View,
) {
(background as? GradientDrawable)?.let { drawable ->
val lerp = min(ogRadius, deviceRadius) * (1 - progress) +
max(ogRadius, deviceRadius) * progress
val hasRail = resources.configuration.screenWidthDp >= 720
val lerpL = MathUtils.lerp(
ogRadius,
if (hasRail && resources.isLTR) 0f else deviceRadius.first,
max(0f, progress),
)
val lerpR = MathUtils.lerp(
ogRadius,
if (hasRail && !resources.isLTR) 0f else deviceRadius.second,
max(0f, progress),
)
drawable.shape = GradientDrawable.RECTANGLE
drawable.cornerRadii = floatArrayOf(lerp, lerp, lerp, lerp, 0f, 0f, 0f, 0f)
drawable.cornerRadii = floatArrayOf(lerpL, lerpL, lerpR, lerpR, 0f, 0f, 0f, 0f)
background = drawable
updateOtherViews.forEach {
it.background = drawable
(it.background as? GradientDrawable)?.let { tDrawable ->
tDrawable.shape = GradientDrawable.RECTANGLE
tDrawable.cornerRadii = floatArrayOf(lerpL, lerpL, lerpR, lerpR, 0f, 0f, 0f, 0f)
}
}
}
}