style: enable drop shadows before api 28

Re-enable drop shadows on the playback bar and queue items on API 27
and lower. This is mostly to make Auxio line up with the M3 styles as
a whole.
This commit is contained in:
OxygenCobalt 2022-02-19 11:06:10 -07:00
parent f5478018c5
commit 2a74ff906c
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 28 additions and 3 deletions

View file

@ -2,6 +2,9 @@
## dev [v2.2.2 or 2.3.0] ## dev [v2.2.2 or 2.3.0]
#### Dev/Meta
- Enabled elevation drop shadows below Android P for consistency
## v2.2.1 ## v2.2.1
#### What's Improved #### What's Improved
- Updated chinese translations [courtesy of cccClyde] - Updated chinese translations [courtesy of cccClyde]

View file

@ -23,9 +23,11 @@ import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.detail.DetailViewModel import org.oxycblt.auxio.detail.DetailViewModel
import org.oxycblt.auxio.music.Song import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.util.disableDropShadowCompat
import org.oxycblt.auxio.util.getAttrColorSafe import org.oxycblt.auxio.util.getAttrColorSafe
import org.oxycblt.auxio.util.getDimenSizeSafe import org.oxycblt.auxio.util.getDimenSafe
import org.oxycblt.auxio.util.getDrawableSafe import org.oxycblt.auxio.util.getDrawableSafe
import org.oxycblt.auxio.util.pxOfDp
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
import org.oxycblt.auxio.util.stateList import org.oxycblt.auxio.util.stateList
import org.oxycblt.auxio.util.systemBarInsetsCompat import org.oxycblt.auxio.util.systemBarInsetsCompat
@ -98,6 +100,8 @@ class PlaybackLayout @JvmOverloads constructor(
private var initMotionY = 0f private var initMotionY = 0f
private val tRect = Rect() private val tRect = Rect()
private val elevationNormal = context.getDimenSafe(R.dimen.elevation_normal)
/** See [isDragging] */ /** See [isDragging] */
private val dragStateField = ViewDragHelper::class.java.getDeclaredField("mDragState").apply { private val dragStateField = ViewDragHelper::class.java.getDeclaredField("mDragState").apply {
isAccessible = true isAccessible = true
@ -117,7 +121,7 @@ class PlaybackLayout @JvmOverloads constructor(
playbackContainerBg = MaterialShapeDrawable.createWithElevationOverlay(context).apply { playbackContainerBg = MaterialShapeDrawable.createWithElevationOverlay(context).apply {
fillColor = context.getAttrColorSafe(R.attr.colorSurface).stateList fillColor = context.getAttrColorSafe(R.attr.colorSurface).stateList
elevation = context.getDimenSizeSafe(R.dimen.elevation_normal).toFloat() elevation = context.pxOfDp(elevationNormal).toFloat()
} }
// The way we fade out the elevation overlay is not by actually reducing the elevation // The way we fade out the elevation overlay is not by actually reducing the elevation
@ -127,6 +131,8 @@ class PlaybackLayout @JvmOverloads constructor(
background = (context.getDrawableSafe(R.drawable.ui_panel_bg) as LayerDrawable).apply { background = (context.getDrawableSafe(R.drawable.ui_panel_bg) as LayerDrawable).apply {
setDrawableByLayerId(R.id.panel_overlay, playbackContainerBg) setDrawableByLayerId(R.id.panel_overlay, playbackContainerBg)
} }
disableDropShadowCompat()
} }
playbackBarView = PlaybackBarView(context).apply { playbackBarView = PlaybackBarView(context).apply {
@ -535,6 +541,7 @@ class PlaybackLayout @JvmOverloads constructor(
// Slowly reduce the elevation of the container as we slide up, eventually resulting in a // Slowly reduce the elevation of the container as we slide up, eventually resulting in a
// neutral color instead of an elevated one when fully expanded. // neutral color instead of an elevated one when fully expanded.
playbackContainerBg.alpha = (outRatio * 255).toInt() playbackContainerBg.alpha = (outRatio * 255).toInt()
playbackContainerView.translationZ = elevationNormal * outRatio
// Fade out our bar view as we slide up // Fade out our bar view as we slide up
playbackBarView.apply { playbackBarView.apply {

View file

@ -37,6 +37,7 @@ import org.oxycblt.auxio.ui.ActionHeaderViewHolder
import org.oxycblt.auxio.ui.BaseViewHolder import org.oxycblt.auxio.ui.BaseViewHolder
import org.oxycblt.auxio.ui.DiffCallback import org.oxycblt.auxio.ui.DiffCallback
import org.oxycblt.auxio.ui.HeaderViewHolder import org.oxycblt.auxio.ui.HeaderViewHolder
import org.oxycblt.auxio.util.disableDropShadowCompat
import org.oxycblt.auxio.util.inflater import org.oxycblt.auxio.util.inflater
import org.oxycblt.auxio.util.logE import org.oxycblt.auxio.util.logE
import org.oxycblt.auxio.util.stateList import org.oxycblt.auxio.util.stateList
@ -132,6 +133,8 @@ class QueueAdapter(
).apply { ).apply {
fillColor = (binding.body.background as ColorDrawable).color.stateList fillColor = (binding.body.background as ColorDrawable).color.stateList
} }
binding.root.disableDropShadowCompat()
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")

View file

@ -86,7 +86,6 @@ class QueueDragCallback(private val playbackModel: PlaybackViewModel) : ItemTouc
// themselves when being dragged. Too bad google's implementation of this doesn't even // themselves when being dragged. Too bad google's implementation of this doesn't even
// work! To emulate it on my own, I check if this child is in a drag state and then animate // work! To emulate it on my own, I check if this child is in a drag state and then animate
// an elevation change. // an elevation change.
val holder = viewHolder as QueueAdapter.QueueSongViewHolder val holder = viewHolder as QueueAdapter.QueueSongViewHolder
if (shouldLift && isCurrentlyActive && actionState == ItemTouchHelper.ACTION_STATE_DRAG) { if (shouldLift && isCurrentlyActive && actionState == ItemTouchHelper.ACTION_STATE_DRAG) {

View file

@ -22,6 +22,7 @@ import android.content.res.ColorStateList
import android.graphics.Insets import android.graphics.Insets
import android.graphics.Rect import android.graphics.Rect
import android.os.Build import android.os.Build
import android.view.View
import android.view.WindowInsets import android.view.WindowInsets
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
@ -62,6 +63,18 @@ fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
*/ */
fun RecyclerView.canScroll(): Boolean = computeVerticalScrollRange() > height fun RecyclerView.canScroll(): Boolean = computeVerticalScrollRange() > height
/**
* Disables drop shadows on a view programmatically in a version-compatible manner.
* This only works on Android 9 and above. Below that version, shadows will remain visible.
*/
fun View.disableDropShadowCompat() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val transparent = context.getColorSafe(android.R.color.transparent)
outlineAmbientShadowColor = transparent
outlineSpotShadowColor = transparent
}
}
/** /**
* Resolve system bar insets in a version-aware manner. This can be used to apply padding to * Resolve system bar insets in a version-aware manner. This can be used to apply padding to
* a view that properly follows all the frustrating changes that were made between 8-11. * a view that properly follows all the frustrating changes that were made between 8-11.