Skip to content

Commit

Permalink
ui: handle round mode again
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Nov 7, 2024
1 parent f25c98a commit 211b815
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,10 @@ public boolean isShouldRemoveExpandedCorners() {
return shouldRemoveExpandedCorners;
}

public void killCorners() {
materialShapeDrawable.setCornerSize(0f);
}

/**
* Gets the current state of the bottom sheet.
*
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/org/oxycblt/auxio/image/CoverView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 211b815

Please sign in to comment.