diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSheetBehavior.kt index f6aa8b653..d614fb12e 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSheetBehavior.kt @@ -18,13 +18,17 @@ package org.oxycblt.auxio.playback import android.content.Context +import android.graphics.drawable.LayerDrawable import android.util.AttributeSet import android.view.MotionEvent import android.view.View import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.google.android.material.shape.MaterialShapeDrawable +import com.google.android.material.shape.ShapeAppearanceModel import org.oxycblt.auxio.R import org.oxycblt.auxio.settings.Settings import org.oxycblt.auxio.ui.AuxioSheetBehavior +import org.oxycblt.auxio.util.getAttrColorCompat import org.oxycblt.auxio.util.getDimen /** @@ -34,6 +38,21 @@ import org.oxycblt.auxio.util.getDimen */ class PlaybackSheetBehavior(context: Context, attributeSet: AttributeSet?) : AuxioSheetBehavior(context, attributeSet) { + val sheetBackgroundDrawable = + MaterialShapeDrawable.createWithElevationOverlay(context).apply { + fillColor = context.getAttrColorCompat(R.attr.colorSurface) + elevation = context.getDimen(R.dimen.elevation_normal) + + if (Settings(context).roundMode) { + val cornersMedium = context.getDimen(R.dimen.size_corners_medium) + shapeAppearanceModel = + ShapeAppearanceModel.Builder() + .setTopLeftCornerSize(cornersMedium) + .setTopRightCornerSize(cornersMedium) + .build() + } + } + init { isHideable = true if (Settings(context).roundMode) { @@ -48,4 +67,12 @@ class PlaybackSheetBehavior(context: Context, attributeSet: AttributeS // Note: This is an extension to Auxio's vendored BottomSheetBehavior override fun isHideableWhenDragging() = false + + override fun createBackground(context: Context) = + LayerDrawable( + arrayOf( + MaterialShapeDrawable(sheetBackgroundDrawable.shapeAppearanceModel).apply { + fillColor = sheetBackgroundDrawable.fillColor + }, + sheetBackgroundDrawable)) } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueSheetBehavior.kt index 0ec75162a..ff67e1d0c 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueSheetBehavior.kt @@ -22,6 +22,8 @@ import android.util.AttributeSet import android.view.View import android.view.WindowInsets import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.google.android.material.shape.MaterialShapeDrawable +import com.google.android.material.shape.ShapeAppearanceModel import org.oxycblt.auxio.R import org.oxycblt.auxio.ui.AuxioSheetBehavior import org.oxycblt.auxio.util.* @@ -37,7 +39,6 @@ class QueueSheetBehavior(context: Context, attributeSet: AttributeSet? init { isHideable = false - sheetBackgroundDrawable.setCornerSize(context.getDimen(R.dimen.size_corners_medium)) } override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) = @@ -52,6 +53,19 @@ class QueueSheetBehavior(context: Context, attributeSet: AttributeSet? return false // No change, just grabbed the height } + override fun createBackground(context: Context) = + MaterialShapeDrawable.createWithElevationOverlay(context).apply { + fillColor = context.getAttrColorCompat(R.attr.colorSurface) + elevation = context.getDimen(R.dimen.elevation_normal) + + val cornersMedium = context.getDimen(R.dimen.size_corners_medium) + shapeAppearanceModel = + ShapeAppearanceModel.Builder() + .setTopLeftCornerSize(cornersMedium) + .setTopRightCornerSize(cornersMedium) + .build() + } + override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets { super.applyWindowInsets(child, insets) diff --git a/app/src/main/java/org/oxycblt/auxio/ui/AuxioSheetBehavior.kt b/app/src/main/java/org/oxycblt/auxio/ui/AuxioSheetBehavior.kt index fcc0dd0ab..581aa5e9b 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/AuxioSheetBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/AuxioSheetBehavior.kt @@ -18,7 +18,7 @@ package org.oxycblt.auxio.ui import android.content.Context -import android.graphics.drawable.LayerDrawable +import android.graphics.drawable.Drawable import android.os.Build import android.util.AttributeSet import android.view.View @@ -26,7 +26,6 @@ import android.view.ViewGroup import android.view.WindowInsets import androidx.coordinatorlayout.widget.CoordinatorLayout import com.google.android.material.bottomsheet.NeoBottomSheetBehavior -import com.google.android.material.shape.MaterialShapeDrawable import org.oxycblt.auxio.R import org.oxycblt.auxio.util.* @@ -38,11 +37,6 @@ import org.oxycblt.auxio.util.* abstract class AuxioSheetBehavior(context: Context, attributeSet: AttributeSet?) : NeoBottomSheetBehavior(context, attributeSet) { private var setup = false - val sheetBackgroundDrawable = - MaterialShapeDrawable.createWithElevationOverlay(context).apply { - fillColor = context.getAttrColorCompat(R.attr.colorSurface) - elevation = context.getDimen(R.dimen.elevation_normal) - } init { // We need to disable isFitToContents for us to have our bottom sheet expand to the @@ -50,6 +44,9 @@ abstract class AuxioSheetBehavior(context: Context, attributeSet: Attr isFitToContents = false } + /** Called when the sheet background is being created */ + abstract fun createBackground(context: Context): Drawable + /** Called when the child the bottom sheet applies to receives window insets. */ open fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets { // All sheet behaviors derive their peek height from the size of the "bar" (i.e the @@ -70,14 +67,7 @@ abstract class AuxioSheetBehavior(context: Context, attributeSet: Attr if (!setup) { child.apply { - // Sometimes the sheet background will fade out, so guard it with another - // colorSurface drawable to prevent content overlap. - val guardDrawable = - MaterialShapeDrawable(sheetBackgroundDrawable.shapeAppearanceModel).apply { - fillColor = context.getAttrColorCompat(R.attr.colorSurface) - } - - background = LayerDrawable(arrayOf(guardDrawable, sheetBackgroundDrawable)) + background = createBackground(context) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // Shadows aren't disabled by default, do that. 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 922cf1307..19a8319cd 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt @@ -30,8 +30,7 @@ import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.systemBarInsetsCompat /** - * A behavior that automatically re-layouts and re-insets content to align with the parent layout's - * bottom sheet. + * A behavior that automatically re-insets content to align with the parent layout's bottom sheet. * @author OxygenCobalt */ class BottomSheetContentBehavior(context: Context, attributeSet: AttributeSet?) : @@ -61,12 +60,10 @@ class BottomSheetContentBehavior(context: Context, attributeSet: Attri return false } - if (consumed != lastConsumed) { - lastConsumed = consumed - lastInsets?.let(child::dispatchApplyWindowInsets) - return true - } + lastConsumed = consumed + lastInsets?.let(child::dispatchApplyWindowInsets) + // Re-insetting views does not lead to the child view changing size or position. return false }