ui: clean out self-rolled dimens
Lots of cruft has built up with my dimensions, partially collapse them into a more consistent set of re-usable dimens (within reason) and try to delegate to MDC as much as possible.
This commit is contained in:
@@ -101,7 +101,7 @@ class MainFragment :
|
||||
val queueSheetBehavior =
|
||||
binding.queueSheet.coordinatorLayoutBehavior as QueueBottomSheetBehavior?
|
||||
|
||||
elevationNormal = binding.context.getDimen(R.dimen.elevation_normal)
|
||||
elevationNormal = binding.context.getDimen(MR.dimen.m3_sys_elevation_level1)
|
||||
|
||||
// Currently all back press callbacks are handled in MainFragment, as it's not guaranteed
|
||||
// that instantiating these callbacks in their respective fragments would result in the
|
||||
@@ -146,12 +146,11 @@ class MainFragment :
|
||||
// Emulate the elevated bottom sheet style.
|
||||
background =
|
||||
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
|
||||
val cornerSize =
|
||||
context.resources.getDimension(R.dimen.size_corners_mid_large)
|
||||
shapeAppearanceModel =
|
||||
ShapeAppearanceModel.builder()
|
||||
.setTopLeftCornerSize(cornerSize)
|
||||
.setTopRightCornerSize(cornerSize)
|
||||
ShapeAppearanceModel.builder(
|
||||
context,
|
||||
MR.style.ShapeAppearance_Material3_Corner_ExtraLarge,
|
||||
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
|
||||
.build()
|
||||
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerHigh)
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ class FastScrollPopupView
|
||||
constructor(context: Context, attrs: AttributeSet? = null, defStyleRes: Int = 0) :
|
||||
MaterialTextView(context, attrs, defStyleRes) {
|
||||
init {
|
||||
minimumWidth = context.getDimenPixels(R.dimen.fast_scroll_popup_min_width)
|
||||
minimumHeight = context.getDimenPixels(R.dimen.fast_scroll_popup_min_height)
|
||||
minimumWidth = context.getDimenPixels(R.dimen.size_touchable_mid_huge)
|
||||
minimumHeight = context.getDimenPixels(R.dimen.size_touchable_large)
|
||||
|
||||
TextViewCompat.setTextAppearance(this, R.style.TextAppearance_Auxio_HeadlineLarge)
|
||||
setTextColor(context.getAttrColorCompat(MR.attr.colorOnSecondary))
|
||||
@@ -60,7 +60,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleRes: Int = 0)
|
||||
includeFontPadding = false
|
||||
|
||||
alpha = 0f
|
||||
elevation = context.getDimenPixels(R.dimen.elevation_normal).toFloat()
|
||||
elevation = context.getDimenPixels(MR.dimen.m3_sys_elevation_level2).toFloat()
|
||||
background = FastScrollPopupDrawable(context)
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleRes: Int = 0)
|
||||
private val path = Path()
|
||||
private val matrix = Matrix()
|
||||
|
||||
private val paddingStart = context.getDimenPixels(R.dimen.fast_scroll_popup_padding_start)
|
||||
private val paddingEnd = context.getDimenPixels(R.dimen.fast_scroll_popup_padding_end)
|
||||
private val paddingStart = context.getDimenPixels(R.dimen.spacing_medium)
|
||||
private val paddingEnd = context.getDimenPixels(R.dimen.spacing_mid_huge)
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
canvas.drawPath(path, paint)
|
||||
|
||||
@@ -151,8 +151,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
private var showingPopup = false
|
||||
|
||||
// Touch
|
||||
private val minTouchTargetSize =
|
||||
context.getDimenPixels(R.dimen.fast_scroll_thumb_touch_target_size)
|
||||
private val minTouchTargetSize = context.getDimenPixels(R.dimen.size_touchable_small)
|
||||
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
private var downX = 0f
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.R as MR
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
@@ -96,7 +97,7 @@ abstract class MaterialDragCallback : ItemTouchHelper.Callback() {
|
||||
logD("Lifting ViewHolder")
|
||||
|
||||
val bg = holder.background
|
||||
val elevation = recyclerView.context.getDimen(R.dimen.elevation_normal)
|
||||
val elevation = recyclerView.context.getDimen(MR.dimen.m3_sys_elevation_level4)
|
||||
holder.root
|
||||
.animate()
|
||||
.translationZ(elevation)
|
||||
@@ -138,7 +139,7 @@ abstract class MaterialDragCallback : ItemTouchHelper.Callback() {
|
||||
logD("Lifting ViewHolder")
|
||||
|
||||
val bg = holder.background
|
||||
val elevation = recyclerView.context.getDimen(R.dimen.elevation_normal)
|
||||
val elevation = recyclerView.context.getDimen(MR.dimen.m3_sys_elevation_level4)
|
||||
holder.root
|
||||
.animate()
|
||||
.translationZ(0f)
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.view.WindowInsets
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.google.android.material.R as MR
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import org.oxycblt.auxio.R
|
||||
import com.google.android.material.shape.ShapeAppearanceModel
|
||||
import org.oxycblt.auxio.ui.BaseBottomSheetBehavior
|
||||
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
|
||||
@@ -43,7 +43,12 @@ class PlaybackBottomSheetBehavior<V : View>(context: Context, attributeSet: Attr
|
||||
val sheetBackgroundDrawable =
|
||||
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
|
||||
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerLow)
|
||||
setCornerSize(context.resources.getDimension(R.dimen.size_corners_mid_large))
|
||||
shapeAppearanceModel =
|
||||
ShapeAppearanceModel.builder(
|
||||
context,
|
||||
MR.style.ShapeAppearance_Material3_Corner_ExtraLarge,
|
||||
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
|
||||
.build()
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||
import org.oxycblt.auxio.playback.ui.PlaybackPagerAdapter
|
||||
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
||||
import org.oxycblt.auxio.playback.ui.SwipeCoverView
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
@@ -65,7 +64,6 @@ class PlaybackPanelFragment :
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
private val listModel: ListViewModel by activityViewModels()
|
||||
private var equalizerLauncher: ActivityResultLauncher<Intent>? = null
|
||||
private var coverAdapter: PlaybackPagerAdapter? = null
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) =
|
||||
FragmentPlaybackPanelBinding.inflate(inflater)
|
||||
@@ -129,7 +127,6 @@ class PlaybackPanelFragment :
|
||||
|
||||
override fun onDestroyBinding(binding: FragmentPlaybackPanelBinding) {
|
||||
equalizerLauncher = null
|
||||
coverAdapter = null
|
||||
binding.playbackSong.isSelected = false
|
||||
binding.playbackToolbar.setOnMenuItemClickListener(null)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.WindowInsets
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.google.android.material.R as MR
|
||||
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.util.getAttrColorCompat
|
||||
@@ -65,7 +66,12 @@ class QueueBottomSheetBehavior<V : View>(context: Context, attributeSet: Attribu
|
||||
MaterialShapeDrawable.createWithElevationOverlay(context).apply {
|
||||
// The queue sheet's background is a static elevated background.
|
||||
fillColor = context.getAttrColorCompat(MR.attr.colorSurfaceContainerHigh)
|
||||
setCornerSize(context.resources.getDimension(R.dimen.size_corners_mid_large))
|
||||
shapeAppearanceModel =
|
||||
ShapeAppearanceModel.builder(
|
||||
context,
|
||||
MR.style.ShapeAppearance_Material3_Corner_ExtraLarge,
|
||||
MR.style.ShapeAppearanceOverlay_Material3_Corner_Top)
|
||||
.build()
|
||||
}
|
||||
|
||||
override fun applyWindowInsets(child: View, insets: WindowInsets): WindowInsets {
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* PlaybackPagerAdapter.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.playback.ui
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlin.jvm.internal.Intrinsics
|
||||
import org.oxycblt.auxio.databinding.ItemPlaybackSongBinding
|
||||
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/** @author Koitharu, Alexander Capehart (OxygenCobalt) */
|
||||
class PlaybackPagerAdapter(private val listener: Listener) :
|
||||
FlexibleListAdapter<Song, CoverViewHolder>(CoverViewHolder.DIFF_CALLBACK) {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CoverViewHolder {
|
||||
return CoverViewHolder.from(parent)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CoverViewHolder, position: Int) {
|
||||
holder.bind(getItem(position), listener)
|
||||
}
|
||||
|
||||
override fun onViewRecycled(holder: CoverViewHolder) {
|
||||
holder.recycle()
|
||||
super.onViewRecycled(holder)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun navigateToCurrentArtist()
|
||||
|
||||
fun navigateToCurrentAlbum()
|
||||
|
||||
fun navigateToCurrentSong()
|
||||
|
||||
fun navigateToMenu()
|
||||
}
|
||||
}
|
||||
|
||||
class CoverViewHolder private constructor(private val binding: ItemPlaybackSongBinding) :
|
||||
RecyclerView.ViewHolder(binding.root), DefaultLifecycleObserver {
|
||||
init {
|
||||
binding.root.layoutParams =
|
||||
RecyclerView.LayoutParams(
|
||||
RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT)
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind new data to this instance.
|
||||
*
|
||||
* @param item The new [Song] to bind.
|
||||
*/
|
||||
fun bind(item: Song, listener: PlaybackPagerAdapter.Listener) {
|
||||
val context = binding.root.context
|
||||
binding.playbackCover.bind(item)
|
||||
// binding.playbackCover.bind(item)
|
||||
binding.playbackSong.apply { text = item.name.resolve(context) }
|
||||
binding.playbackArtist.apply {
|
||||
text = item.artists.resolveNames(context)
|
||||
setOnClickListener { listener.navigateToCurrentArtist() }
|
||||
}
|
||||
binding.playbackAlbum.apply {
|
||||
text = item.album.name.resolve(context)
|
||||
setOnClickListener { listener.navigateToCurrentAlbum() }
|
||||
}
|
||||
setSelected(true)
|
||||
}
|
||||
|
||||
fun recycle() {
|
||||
// Marquee elements leak if they are not disabled when the views are destroyed.
|
||||
// TODO: Move to TextView impl to avoid having to deal with lifecycle here
|
||||
setSelected(false)
|
||||
}
|
||||
|
||||
private fun setSelected(value: Boolean) {
|
||||
binding.playbackSong.isSelected = value
|
||||
binding.playbackArtist.isSelected = value
|
||||
binding.playbackAlbum.isSelected = value
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun from(parent: ViewGroup) =
|
||||
CoverViewHolder(ItemPlaybackSongBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
object : DiffUtil.ItemCallback<Song>() {
|
||||
override fun areItemsTheSame(oldItem: Song, newItem: Song) =
|
||||
oldItem.uid == newItem.uid
|
||||
|
||||
override fun areContentsTheSame(oldItem: Song, newItem: Song): Boolean {
|
||||
return Intrinsics.areEqual(oldItem, newItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,8 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowInsets
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.google.android.material.R as MR
|
||||
import com.google.android.material.bottomsheet.BackportBottomSheetBehavior
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.util.getDimen
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.systemGestureInsetsCompat
|
||||
@@ -87,7 +87,7 @@ abstract class BaseBottomSheetBehavior<V : View>(context: Context, attributeSet:
|
||||
logD("Not initialized, setting up child")
|
||||
child.apply {
|
||||
// Set up compat elevation attributes. These are only shown below API 28.
|
||||
translationZ = context.getDimen(R.dimen.elevation_normal)
|
||||
translationZ = context.getDimen(MR.dimen.m3_sys_elevation_level1)
|
||||
// Background differs depending on concrete implementation.
|
||||
background = createBackground(context)
|
||||
setOnApplyWindowInsetsListener(::applyWindowInsets)
|
||||
|
||||
@@ -39,7 +39,7 @@ class AccentGridLayoutManager(
|
||||
) : GridLayoutManager(context, attrs, defStyleAttr, defStyleRes) {
|
||||
// We use 56dp here since that's the rough size of the accent item.
|
||||
// This will need to be modified if this is used beyond the accent dialog.
|
||||
private var columnWidth = context.getDimenPixels(R.dimen.size_accent_item)
|
||||
private var columnWidth = context.getDimenPixels(R.dimen.size_touchable_large)
|
||||
private var lastWidth = -1
|
||||
private var lastHeight = -1
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ constructor(
|
||||
} else if (uiSettings.roundMode) {
|
||||
// < Android 12, but the user still enabled round mode.
|
||||
logD("Using default corner radius")
|
||||
context.getDimenPixels(R.dimen.size_corners_medium)
|
||||
context.getDimenPixels(R.dimen.m3_shape_corners_large)
|
||||
} else {
|
||||
// User did not enable round mode.
|
||||
logD("Using no corner radius")
|
||||
|
||||
Reference in New Issue
Block a user