From 211b815a20d0d0597682be8a5b3d440bb45ff70f Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 7 Nov 2024 13:38:54 -0700 Subject: [PATCH] ui: handle round mode again --- .../BackportBottomSheetBehavior.java | 4 +++ .../java/org/oxycblt/auxio/MainFragment.kt | 6 ++++ .../java/org/oxycblt/auxio/image/CoverView.kt | 19 +++++++----- .../playback/PlaybackBottomSheetBehavior.kt | 31 ++++++++++++------- .../queue/QueueBottomSheetBehavior.kt | 17 +++++----- .../auxio/ui/BaseBottomSheetBehavior.kt | 8 +++-- .../auxio/ui/BottomSheetContentBehavior.kt | 14 ++------- .../ViewBindingBottomSheetDialogFragment.kt | 5 +++ 8 files changed, 66 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java b/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java index 4b92cfc2e..1ca251dc0 100644 --- a/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java +++ b/app/src/main/java/com/google/android/material/bottomsheet/BackportBottomSheetBehavior.java @@ -1390,6 +1390,10 @@ public boolean isShouldRemoveExpandedCorners() { return shouldRemoveExpandedCorners; } + public void killCorners() { + materialShapeDrawable.setCornerSize(0f); + } + /** * Gets the current state of the bottom sheet. * diff --git a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt index 3eade4d09..d5c3f4840 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt @@ -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) diff --git a/app/src/main/java/org/oxycblt/auxio/image/CoverView.kt b/app/src/main/java/org/oxycblt/auxio/image/CoverView.kt index f8c4ee328..90fcf17d8 100644 --- a/app/src/main/java/org/oxycblt/auxio/image/CoverView.kt +++ b/app/src/main/java/org/oxycblt/auxio/image/CoverView.kt @@ -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 { diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt index 84c5df5e2..49cef16f3 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackBottomSheetBehavior.kt @@ -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(context: Context, attributeSet: AttributeSet?) : BaseBottomSheetBehavior(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(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 diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt index 02da14b5b..8e56dad16 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueBottomSheetBehavior.kt @@ -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(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 { diff --git a/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt index 2d64c17d4..8f4488a7d 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/BaseBottomSheetBehavior.kt @@ -46,6 +46,10 @@ abstract class BaseBottomSheetBehavior(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(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(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 diff --git a/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt b/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt index 50c266ee0..96d494a47 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt @@ -69,7 +69,7 @@ class BottomSheetContentBehavior(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(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(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 = diff --git a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingBottomSheetDialogFragment.kt b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingBottomSheetDialogFragment.kt index 7e2e07ba9..53e3af574 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingBottomSheetDialogFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/ViewBindingBottomSheetDialogFragment.kt @@ -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 : 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 : 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") }