ui: handle round mode again

This commit is contained in:
Alexander Capehart 2024-11-07 13:38:54 -07:00
parent f25c98aa7e
commit 211b815a20
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
8 changed files with 66 additions and 38 deletions

View file

@ -1390,6 +1390,10 @@ public class BackportBottomSheetBehavior<V extends View> extends CoordinatorLayo
return shouldRemoveExpandedCorners;
}
public void killCorners() {
materialShapeDrawable.setCornerSize(0f);
}
/**
* Gets the current state of the bottom sheet.
*

View file

@ -40,6 +40,7 @@ import com.leinardi.android.speeddial.SpeedDialActionItem
import com.leinardi.android.speeddial.SpeedDialView
import dagger.hilt.android.AndroidEntryPoint
import java.lang.reflect.Method
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
import org.oxycblt.auxio.databinding.FragmentMainBinding
@ -58,6 +59,7 @@ import org.oxycblt.auxio.playback.PlaybackBottomSheetBehavior
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.playback.queue.QueueBottomSheetBehavior
import org.oxycblt.auxio.ui.DialogAwareNavigationListener
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collect
import org.oxycblt.auxio.util.collectImmediately
@ -95,6 +97,7 @@ class MainFragment :
private var normalCornerSize = 0f
private var maxScaleXDistance = 0f
private var sheetRising: Boolean? = null
@Inject lateinit var uiSettings: UISettings
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -109,8 +112,11 @@ class MainFragment :
val playbackSheetBehavior =
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior
playbackSheetBehavior.uiSettings = uiSettings
playbackSheetBehavior.makeBackgroundDrawable(requireContext())
val queueSheetBehavior =
binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior?
queueSheetBehavior?.uiSettings = uiSettings
elevationNormal = binding.context.getDimen(MR.dimen.m3_sys_elevation_level1)

View file

@ -108,14 +108,19 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
val shapeAppearanceRes = styledAttrs.getResourceId(R.styleable.CoverView_shapeAppearance, 0)
shapeAppearance =
if (shapeAppearanceRes != 0) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
if (uiSettings.roundMode) {
if (shapeAppearanceRes != 0) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder(
context,
com.google.android.material.R.style
.ShapeAppearance_Material3_Corner_Medium,
-1)
.build()
}
} else {
ShapeAppearanceModel.builder(
context,
com.google.android.material.R.style.ShapeAppearance_Material3_Corner_Medium,
-1)
.build()
ShapeAppearanceModel.builder().build()
}
iconSize =
styledAttrs.getDimensionPixelSize(R.styleable.CoverView_iconSize, -1).takeIf {

View file

@ -30,6 +30,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
@ -42,16 +43,24 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
*/
class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
BaseBottomSheetBehavior<V>(context, attributeSet) {
val sheetBackgroundDrawable =
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerLow)
shapeAppearanceModel =
ShapeAppearanceModel.builder(
context,
R.style.ShapeAppearance_Auxio_BottomSheet,
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build()
}
lateinit var sheetBackgroundDrawable: MaterialShapeDrawable
fun makeBackgroundDrawable(context: Context) {
sheetBackgroundDrawable =
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerLow)
shapeAppearanceModel =
if (uiSettings.roundMode) {
ShapeAppearanceModel.builder(
context,
R.style.ShapeAppearance_Auxio_BottomSheet,
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build()
} else {
ShapeAppearanceModel.Builder().build()
}
}
}
init {
isHideable = true
@ -68,7 +77,7 @@ class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: Attr
// Note: This is an extension to Auxio's vendored BottomSheetBehavior
override fun isHideableWhenDragging() = false
override fun createBackground(context: Context) =
override fun createBackground(context: Context, uiSettings: UISettings) =
LayerDrawable(
arrayOf(
// Add another colored background so that there is always an obscuring

View file

@ -28,6 +28,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
@ -65,16 +66,18 @@ class QueueBottomSheetBehavior<V : View>(context: Context, attributeSet: Attribu
return false
}
override fun createBackground(context: Context) =
override fun createBackground(context: Context, uiSettings: UISettings) =
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
// The queue sheet's background is a static elevated background.
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerHigh)
shapeAppearanceModel =
ShapeAppearanceModel.builder(
context,
R.style.ShapeAppearance_Auxio_BottomSheet,
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build()
if (uiSettings.roundMode) {
shapeAppearanceModel =
ShapeAppearanceModel.builder(
context,
R.style.ShapeAppearance_Auxio_BottomSheet,
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build()
}
}
override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {

View file

@ -46,6 +46,10 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
private var initalized = false
private val idealBottomGestureInsets = context.getDimenPixels(R.dimen.spacing_medium)
// I can't manually inject this, MainFragment must be the one to do it.
// TODO: Just use another library. Tired of Hilt.
lateinit var uiSettings: UISettings
init {
// Disable isFitToContents to make the bottom sheet expand to the top of the screen and
// not just how much the content takes up.
@ -58,7 +62,7 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
* @param context [Context] that can be used to draw the [Drawable].
* @return A background drawable.
*/
abstract fun createBackground(context: Context): Drawable
abstract fun createBackground(context: Context, uiSettings: UISettings): Drawable
/** Get the ideal bar height to use before the bar is properly measured. */
abstract fun getIdealBarHeight(context: Context): Int
@ -101,7 +105,7 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
// Set up compat elevation attributes. These are only shown below API 28.
translationZ = context.getDimen(MR.dimen.m3_sys_elevation_level1)
// Background differs depending on concrete implementation.
background = createBackground(context)
background = createBackground(context, uiSettings)
setOnApplyWindowInsetsListener(::applyWindowInsets)
}
initalized = true

View file

@ -69,7 +69,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
L.d("Consumed amount changed, re-applying insets")
lastConsumed = consumed
lastInsets?.let(child::dispatchApplyWindowInsets)
measureContent(parent, child, consumed)
measureContent(parent, child)
layoutContent(child)
return true
}
@ -85,15 +85,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
parentHeightMeasureSpec: Int,
heightUsed: Int
): Boolean {
val dep = dep ?: return false
val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior
val consumed = behavior.calculateConsumedByBar()
if (consumed == Int.MIN_VALUE) {
return false
}
measureContent(parent, child, consumed)
measureContent(parent, child)
return true
}
@ -123,7 +115,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
return true
}
private fun measureContent(parent: View, child: View, consumed: Int) {
private fun measureContent(parent: View, child: View) {
val contentWidthSpec =
View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)
val contentHeightSpec =

View file

@ -30,6 +30,7 @@ import com.google.android.material.bottomsheet.BackportBottomSheetBehavior
import com.google.android.material.bottomsheet.BackportBottomSheetDialog
import com.google.android.material.bottomsheet.BackportBottomSheetDialogFragment
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import javax.inject.Inject
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.unlikelyToBeNull
import timber.log.Timber as L
@ -43,6 +44,7 @@ import timber.log.Timber as L
abstract class ViewBindingBottomSheetDialogFragment<VB : ViewBinding> :
BackportBottomSheetDialogFragment() {
private var _binding: VB? = null
@Inject lateinit var uiSettings: UISettings
override fun onCreateDialog(savedInstanceState: Bundle?): BackportBottomSheetDialog =
TweakedBottomSheetDialog(requireContext(), theme)
@ -97,6 +99,9 @@ abstract class ViewBindingBottomSheetDialogFragment<VB : ViewBinding> :
final override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (!uiSettings.roundMode) {
(dialog as BackportBottomSheetDialog).behavior.killCorners()
}
onBindingCreated(requireBinding(), savedInstanceState)
L.d("Fragment created")
}