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; return shouldRemoveExpandedCorners;
} }
public void killCorners() {
materialShapeDrawable.setCornerSize(0f);
}
/** /**
* Gets the current state of the bottom sheet. * 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 com.leinardi.android.speeddial.SpeedDialView
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import java.lang.reflect.Method import java.lang.reflect.Method
import javax.inject.Inject
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import org.oxycblt.auxio.databinding.FragmentMainBinding 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.PlaybackViewModel
import org.oxycblt.auxio.playback.queue.QueueBottomSheetBehavior import org.oxycblt.auxio.playback.queue.QueueBottomSheetBehavior
import org.oxycblt.auxio.ui.DialogAwareNavigationListener import org.oxycblt.auxio.ui.DialogAwareNavigationListener
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.ui.ViewBindingFragment import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collect import org.oxycblt.auxio.util.collect
import org.oxycblt.auxio.util.collectImmediately import org.oxycblt.auxio.util.collectImmediately
@ -95,6 +97,7 @@ class MainFragment :
private var normalCornerSize = 0f private var normalCornerSize = 0f
private var maxScaleXDistance = 0f private var maxScaleXDistance = 0f
private var sheetRising: Boolean? = null private var sheetRising: Boolean? = null
@Inject lateinit var uiSettings: UISettings
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -109,8 +112,11 @@ class MainFragment :
val playbackSheetBehavior = val playbackSheetBehavior =
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior
playbackSheetBehavior.uiSettings = uiSettings
playbackSheetBehavior.makeBackgroundDrawable(requireContext())
val queueSheetBehavior = val queueSheetBehavior =
binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior? binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior?
queueSheetBehavior?.uiSettings = uiSettings
elevationNormal = binding.context.getDimen(MR.dimen.m3_sys_elevation_level1) elevationNormal = binding.context.getDimen(MR.dimen.m3_sys_elevation_level1)

View file

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

View file

@ -30,6 +30,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel import com.google.android.material.shape.ShapeAppearanceModel
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.getAttrColorCompat import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getDimenPixels import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
@ -42,15 +43,23 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
*/ */
class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) : class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
BaseBottomSheetBehavior<V>(context, attributeSet) { BaseBottomSheetBehavior<V>(context, attributeSet) {
val sheetBackgroundDrawable = lateinit var sheetBackgroundDrawable: MaterialShapeDrawable
fun makeBackgroundDrawable(context: Context) {
sheetBackgroundDrawable =
MaterialShapeDrawable.createWithElevationOverlay(context).apply { MaterialShapeDrawable.createWithElevationOverlay(context).apply {
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerLow) fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerLow)
shapeAppearanceModel = shapeAppearanceModel =
if (uiSettings.roundMode) {
ShapeAppearanceModel.builder( ShapeAppearanceModel.builder(
context, context,
R.style.ShapeAppearance_Auxio_BottomSheet, R.style.ShapeAppearance_Auxio_BottomSheet,
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top) MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build() .build()
} else {
ShapeAppearanceModel.Builder().build()
}
}
} }
init { init {
@ -68,7 +77,7 @@ class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: Attr
// Note: This is an extension to Auxio's vendored BottomSheetBehavior // Note: This is an extension to Auxio's vendored BottomSheetBehavior
override fun isHideableWhenDragging() = false override fun isHideableWhenDragging() = false
override fun createBackground(context: Context) = override fun createBackground(context: Context, uiSettings: UISettings) =
LayerDrawable( LayerDrawable(
arrayOf( arrayOf(
// Add another colored background so that there is always an obscuring // 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 com.google.android.material.shape.ShapeAppearanceModel
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.getAttrColorCompat import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getDimenPixels import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
@ -65,10 +66,11 @@ class QueueBottomSheetBehavior<V : View>(context: Context, attributeSet: Attribu
return false return false
} }
override fun createBackground(context: Context) = override fun createBackground(context: Context, uiSettings: UISettings) =
MaterialShapeDrawable.createWithElevationOverlay(context).apply { MaterialShapeDrawable.createWithElevationOverlay(context).apply {
// The queue sheet's background is a static elevated background. // The queue sheet's background is a static elevated background.
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerHigh) fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerHigh)
if (uiSettings.roundMode) {
shapeAppearanceModel = shapeAppearanceModel =
ShapeAppearanceModel.builder( ShapeAppearanceModel.builder(
context, context,
@ -76,6 +78,7 @@ class QueueBottomSheetBehavior<V : View>(context: Context, attributeSet: Attribu
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top) MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
.build() .build()
} }
}
override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets { override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {
super.applyWindowInsets(child, insets) super.applyWindowInsets(child, insets)

View file

@ -46,6 +46,10 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
private var initalized = false private var initalized = false
private val idealBottomGestureInsets = context.getDimenPixels(R.dimen.spacing_medium) 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 { init {
// Disable isFitToContents to make the bottom sheet expand to the top of the screen and // Disable isFitToContents to make the bottom sheet expand to the top of the screen and
// not just how much the content takes up. // 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]. * @param context [Context] that can be used to draw the [Drawable].
* @return A background 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. */ /** Get the ideal bar height to use before the bar is properly measured. */
abstract fun getIdealBarHeight(context: Context): Int 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. // Set up compat elevation attributes. These are only shown below API 28.
translationZ = context.getDimen(MR.dimen.m3_sys_elevation_level1) translationZ = context.getDimen(MR.dimen.m3_sys_elevation_level1)
// Background differs depending on concrete implementation. // Background differs depending on concrete implementation.
background = createBackground(context) background = createBackground(context, uiSettings)
setOnApplyWindowInsetsListener(::applyWindowInsets) setOnApplyWindowInsetsListener(::applyWindowInsets)
} }
initalized = true initalized = true

View file

@ -69,7 +69,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
L.d("Consumed amount changed, re-applying insets") L.d("Consumed amount changed, re-applying insets")
lastConsumed = consumed lastConsumed = consumed
lastInsets?.let(child::dispatchApplyWindowInsets) lastInsets?.let(child::dispatchApplyWindowInsets)
measureContent(parent, child, consumed) measureContent(parent, child)
layoutContent(child) layoutContent(child)
return true return true
} }
@ -85,15 +85,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
parentHeightMeasureSpec: Int, parentHeightMeasureSpec: Int,
heightUsed: Int heightUsed: Int
): Boolean { ): Boolean {
val dep = dep ?: return false measureContent(parent, child)
val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior
val consumed = behavior.calculateConsumedByBar()
if (consumed == Int.MIN_VALUE) {
return false
}
measureContent(parent, child, consumed)
return true return true
} }
@ -123,7 +115,7 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
return true return true
} }
private fun measureContent(parent: View, child: View, consumed: Int) { private fun measureContent(parent: View, child: View) {
val contentWidthSpec = val contentWidthSpec =
View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY) View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)
val contentHeightSpec = 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.BackportBottomSheetDialog
import com.google.android.material.bottomsheet.BackportBottomSheetDialogFragment import com.google.android.material.bottomsheet.BackportBottomSheetDialogFragment
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import javax.inject.Inject
import org.oxycblt.auxio.util.getDimenPixels import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.unlikelyToBeNull import org.oxycblt.auxio.util.unlikelyToBeNull
import timber.log.Timber as L import timber.log.Timber as L
@ -43,6 +44,7 @@ import timber.log.Timber as L
abstract class ViewBindingBottomSheetDialogFragment<VB : ViewBinding> : abstract class ViewBindingBottomSheetDialogFragment<VB : ViewBinding> :
BackportBottomSheetDialogFragment() { BackportBottomSheetDialogFragment() {
private var _binding: VB? = null private var _binding: VB? = null
@Inject lateinit var uiSettings: UISettings
override fun onCreateDialog(savedInstanceState: Bundle?): BackportBottomSheetDialog = override fun onCreateDialog(savedInstanceState: Bundle?): BackportBottomSheetDialog =
TweakedBottomSheetDialog(requireContext(), theme) TweakedBottomSheetDialog(requireContext(), theme)
@ -97,6 +99,9 @@ abstract class ViewBindingBottomSheetDialogFragment<VB : ViewBinding> :
final override fun onViewCreated(view: View, savedInstanceState: Bundle?) { final override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
if (!uiSettings.roundMode) {
(dialog as BackportBottomSheetDialog).behavior.killCorners()
}
onBindingCreated(requireBinding(), savedInstanceState) onBindingCreated(requireBinding(), savedInstanceState)
L.d("Fragment created") L.d("Fragment created")
} }