ui: improve bottom sheet backgrounds
Try to improve the efficiency/management of bottom sheet bakcgrounds somewhat.
This commit is contained in:
parent
0474940ee3
commit
7b3490d5d3
4 changed files with 51 additions and 23 deletions
|
@ -18,13 +18,17 @@
|
||||||
package org.oxycblt.auxio.playback
|
package org.oxycblt.auxio.playback
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
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.R
|
||||||
import org.oxycblt.auxio.settings.Settings
|
import org.oxycblt.auxio.settings.Settings
|
||||||
import org.oxycblt.auxio.ui.AuxioSheetBehavior
|
import org.oxycblt.auxio.ui.AuxioSheetBehavior
|
||||||
|
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||||
import org.oxycblt.auxio.util.getDimen
|
import org.oxycblt.auxio.util.getDimen
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +38,21 @@ import org.oxycblt.auxio.util.getDimen
|
||||||
*/
|
*/
|
||||||
class PlaybackSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
class PlaybackSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
||||||
AuxioSheetBehavior<V>(context, attributeSet) {
|
AuxioSheetBehavior<V>(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 {
|
init {
|
||||||
isHideable = true
|
isHideable = true
|
||||||
if (Settings(context).roundMode) {
|
if (Settings(context).roundMode) {
|
||||||
|
@ -48,4 +67,12 @@ class PlaybackSheetBehavior<V : View>(context: Context, attributeSet: AttributeS
|
||||||
|
|
||||||
// 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) =
|
||||||
|
LayerDrawable(
|
||||||
|
arrayOf(
|
||||||
|
MaterialShapeDrawable(sheetBackgroundDrawable.shapeAppearanceModel).apply {
|
||||||
|
fillColor = sheetBackgroundDrawable.fillColor
|
||||||
|
},
|
||||||
|
sheetBackgroundDrawable))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
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.R
|
||||||
import org.oxycblt.auxio.ui.AuxioSheetBehavior
|
import org.oxycblt.auxio.ui.AuxioSheetBehavior
|
||||||
import org.oxycblt.auxio.util.*
|
import org.oxycblt.auxio.util.*
|
||||||
|
@ -37,7 +39,6 @@ class QueueSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?
|
||||||
|
|
||||||
init {
|
init {
|
||||||
isHideable = false
|
isHideable = false
|
||||||
sheetBackgroundDrawable.setCornerSize(context.getDimen(R.dimen.size_corners_medium))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) =
|
override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) =
|
||||||
|
@ -52,6 +53,19 @@ class QueueSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?
|
||||||
return false // No change, just grabbed the height
|
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 {
|
override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {
|
||||||
super.applyWindowInsets(child, insets)
|
super.applyWindowInsets(child, insets)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
package org.oxycblt.auxio.ui
|
package org.oxycblt.auxio.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -26,7 +26,6 @@ import android.view.ViewGroup
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import com.google.android.material.bottomsheet.NeoBottomSheetBehavior
|
import com.google.android.material.bottomsheet.NeoBottomSheetBehavior
|
||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.util.*
|
import org.oxycblt.auxio.util.*
|
||||||
|
|
||||||
|
@ -38,11 +37,6 @@ import org.oxycblt.auxio.util.*
|
||||||
abstract class AuxioSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
abstract class AuxioSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
||||||
NeoBottomSheetBehavior<V>(context, attributeSet) {
|
NeoBottomSheetBehavior<V>(context, attributeSet) {
|
||||||
private var setup = false
|
private var setup = false
|
||||||
val sheetBackgroundDrawable =
|
|
||||||
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
|
|
||||||
fillColor = context.getAttrColorCompat(R.attr.colorSurface)
|
|
||||||
elevation = context.getDimen(R.dimen.elevation_normal)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// We need to disable isFitToContents for us to have our bottom sheet expand to the
|
// We need to disable isFitToContents for us to have our bottom sheet expand to the
|
||||||
|
@ -50,6 +44,9 @@ abstract class AuxioSheetBehavior<V : View>(context: Context, attributeSet: Attr
|
||||||
isFitToContents = false
|
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. */
|
/** Called when the child the bottom sheet applies to receives window insets. */
|
||||||
open fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {
|
open fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {
|
||||||
// All sheet behaviors derive their peek height from the size of the "bar" (i.e the
|
// All sheet behaviors derive their peek height from the size of the "bar" (i.e the
|
||||||
|
@ -70,14 +67,7 @@ abstract class AuxioSheetBehavior<V : View>(context: Context, attributeSet: Attr
|
||||||
|
|
||||||
if (!setup) {
|
if (!setup) {
|
||||||
child.apply {
|
child.apply {
|
||||||
// Sometimes the sheet background will fade out, so guard it with another
|
background = createBackground(context)
|
||||||
// colorSurface drawable to prevent content overlap.
|
|
||||||
val guardDrawable =
|
|
||||||
MaterialShapeDrawable(sheetBackgroundDrawable.shapeAppearanceModel).apply {
|
|
||||||
fillColor = context.getAttrColorCompat(R.attr.colorSurface)
|
|
||||||
}
|
|
||||||
|
|
||||||
background = LayerDrawable(arrayOf(guardDrawable, sheetBackgroundDrawable))
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
// Shadows aren't disabled by default, do that.
|
// Shadows aren't disabled by default, do that.
|
||||||
|
|
|
@ -30,8 +30,7 @@ import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
|
||||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A behavior that automatically re-layouts and re-insets content to align with the parent layout's
|
* A behavior that automatically re-insets content to align with the parent layout's bottom sheet.
|
||||||
* bottom sheet.
|
|
||||||
* @author OxygenCobalt
|
* @author OxygenCobalt
|
||||||
*/
|
*/
|
||||||
class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: AttributeSet?) :
|
||||||
|
@ -61,12 +60,10 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consumed != lastConsumed) {
|
lastConsumed = consumed
|
||||||
lastConsumed = consumed
|
lastInsets?.let(child::dispatchApplyWindowInsets)
|
||||||
lastInsets?.let(child::dispatchApplyWindowInsets)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Re-insetting views does not lead to the child view changing size or position.
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue