all: reformat

This commit is contained in:
Alexander Capehart 2025-01-04 11:08:01 -07:00
parent 533702ca1e
commit 7e6865c6b3
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 71 additions and 61 deletions

View file

@ -24,6 +24,8 @@ import org.oxycblt.musikr.tag.Name
fun Name.thumb() = fun Name.thumb() =
when (this) { when (this) {
is Name.Known -> is Name.Known ->
tokens.firstOrNull()?.let { if (it.value.isDigitsOnly()) "#" else it.value.first().uppercase() } tokens.firstOrNull()?.let {
if (it.value.isDigitsOnly()) "#" else it.value.first().uppercase()
}
is Name.Unknown -> "?" is Name.Unknown -> "?"
} }

View file

@ -91,8 +91,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private var thumbAnimator: Animator? = null private var thumbAnimator: Animator? = null
private val thumbView = private val thumbView =
context.inflater.inflate(R.layout.view_scroll_thumb, null) context.inflater.inflate(R.layout.view_scroll_thumb, null).apply {
.apply { thumbSlider.jumpOut(this) } thumbSlider.jumpOut(this)
}
private val thumbPadding = Rect(0, 0, 0, 0) private val thumbPadding = Rect(0, 0, 0, 0)
private var thumbOffset = 0 private var thumbOffset = 0
@ -103,28 +104,28 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
} }
private val popupView = MaterialTextView(context).apply { private val popupView =
MaterialTextView(context).apply {
minimumWidth = context.getDimenPixels(R.dimen.size_touchable_large) minimumWidth = context.getDimenPixels(R.dimen.size_touchable_large)
minimumHeight = context.getDimenPixels(R.dimen.size_touchable_small) minimumHeight = context.getDimenPixels(R.dimen.size_touchable_small)
TextViewCompat.setTextAppearance(this, R.style.TextAppearance_Auxio_HeadlineMedium) TextViewCompat.setTextAppearance(this, R.style.TextAppearance_Auxio_HeadlineMedium)
setTextColor(context.getAttrColorCompat(com.google.android.material.R.attr.colorOnSecondary)) setTextColor(
context.getAttrColorCompat(com.google.android.material.R.attr.colorOnSecondary))
ellipsize = TextUtils.TruncateAt.MIDDLE ellipsize = TextUtils.TruncateAt.MIDDLE
gravity = Gravity.CENTER gravity = Gravity.CENTER
includeFontPadding = false includeFontPadding = false
elevation = elevation =
context.getDimenPixels(com.google.android.material.R.dimen.m3_sys_elevation_level1) context
.getDimenPixels(com.google.android.material.R.dimen.m3_sys_elevation_level1)
.toFloat() .toFloat()
background = context.getDrawableCompat(R.drawable.ui_popup) background = context.getDrawableCompat(R.drawable.ui_popup)
updatePaddingRelative(end = context.getDimenPixels(R.dimen.spacing_tiny) / 2) updatePaddingRelative(end = context.getDimenPixels(R.dimen.spacing_tiny) / 2)
layoutParams = layoutParams =
FrameLayout.LayoutParams( FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
) .apply { gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP }
.apply {
gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
}
} }
private val popupSlider = private val popupSlider =
MaterialFadingSlider(MaterialSlider.large(context, popupView.minimumWidth / 2)).apply { MaterialFadingSlider(MaterialSlider.large(context, popupView.minimumWidth / 2)).apply {
@ -226,8 +227,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
thumbView.layoutDirection = layoutDirection thumbView.layoutDirection = layoutDirection
thumbView.measure( thumbView.measure(
MeasureSpec.makeMeasureSpec(thumbWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(thumbWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(thumbHeight, MeasureSpec.EXACTLY) MeasureSpec.makeMeasureSpec(thumbHeight, MeasureSpec.EXACTLY))
)
val thumbTop = thumbPadding.top + thumbOffset val thumbTop = thumbPadding.top + thumbOffset
val thumbLeft = val thumbLeft =
if (isRtl) { if (isRtl) {
@ -270,8 +270,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
thumbWidth + thumbWidth +
popupLayoutParams.leftMargin + popupLayoutParams.leftMargin +
popupLayoutParams.rightMargin, popupLayoutParams.rightMargin,
popupLayoutParams.width popupLayoutParams.width)
)
val heightMeasureSpec = val heightMeasureSpec =
ViewGroup.getChildMeasureSpec( ViewGroup.getChildMeasureSpec(
@ -280,11 +279,11 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
thumbPadding.bottom + thumbPadding.bottom +
popupLayoutParams.topMargin + popupLayoutParams.topMargin +
popupLayoutParams.bottomMargin, popupLayoutParams.bottomMargin,
popupLayoutParams.height popupLayoutParams.height)
)
popupView.measure(widthMeasureSpec, heightMeasureSpec) popupView.measure(widthMeasureSpec, heightMeasureSpec)
Timber.d("Updating popup text to ${popupView.measuredHeight} ${popupView.measuredWidth}") Timber.d(
"Updating popup text to ${popupView.measuredHeight} ${popupView.measuredWidth}")
} }
val popupWidth = popupView.measuredWidth val popupWidth = popupView.measuredWidth
@ -293,7 +292,12 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
thumbPadding.left + thumbWidth + popupLayoutParams.leftMargin + popupWidth / 2 thumbPadding.left + thumbWidth + popupLayoutParams.leftMargin + popupWidth / 2
} else { } else {
width - thumbPadding.right - thumbWidth - popupLayoutParams.rightMargin - popupWidth - popupWidth / 2 width -
thumbPadding.right -
thumbWidth -
popupLayoutParams.rightMargin -
popupWidth -
popupWidth / 2
} }
val popupAnchorY = popupHeight / 2 val popupAnchorY = popupHeight / 2
@ -303,8 +307,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
(thumbTop + thumbAnchorY - popupAnchorY) (thumbTop + thumbAnchorY - popupAnchorY)
.coerceAtLeast(thumbPadding.top + popupLayoutParams.topMargin) .coerceAtLeast(thumbPadding.top + popupLayoutParams.topMargin)
.coerceAtMost( .coerceAtMost(
height - thumbPadding.bottom - popupLayoutParams.bottomMargin - popupHeight height - thumbPadding.bottom - popupLayoutParams.bottomMargin - popupHeight)
)
popupView.layout(popupLeft, popupTop, popupLeft + popupWidth, popupTop + popupHeight) popupView.layout(popupLeft, popupTop, popupLeft + popupWidth, popupTop + popupHeight)
} }
@ -374,12 +377,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
dragging = true dragging = true
} }
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
if (!dragging && if (!dragging &&
thumbView.isUnder(downX, thumbView.top.toFloat(), minTouchTargetSize) && thumbView.isUnder(downX, thumbView.top.toFloat(), minTouchTargetSize) &&
abs(eventY - downY) > touchSlop abs(eventY - downY) > touchSlop) {
) {
if (thumbView.isUnder(downX, downY, minTouchTargetSize)) { if (thumbView.isUnder(downX, downY, minTouchTargetSize)) {
dragStartY = lastY dragStartY = lastY
dragStartThumbOffset = thumbOffset dragStartThumbOffset = thumbOffset
@ -398,7 +399,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
scrollToThumbOffset(thumbOffset) scrollToThumbOffset(thumbOffset)
} }
} }
MotionEvent.ACTION_UP, MotionEvent.ACTION_UP,
MotionEvent.ACTION_CANCEL -> dragging = false MotionEvent.ACTION_CANCEL -> dragging = false
} }

View file

@ -201,7 +201,13 @@ class MaterialFlipper(context: Context) {
} }
} }
class MaterialSlider private constructor(context: Context, private val x: Int?, inDuration: Pair<Int, Int>, outDuration: Pair<Int, Int>) { class MaterialSlider
private constructor(
context: Context,
private val x: Int?,
inDuration: Pair<Int, Int>,
outDuration: Pair<Int, Int>
) {
private val outConfig = AnimConfig.of(context, AnimConfig.EMPHASIZED_ACCELERATE, outDuration) private val outConfig = AnimConfig.of(context, AnimConfig.EMPHASIZED_ACCELERATE, outDuration)
private val inConfig = AnimConfig.of(context, AnimConfig.EMPHASIZED_DECELERATE, inDuration) private val inConfig = AnimConfig.of(context, AnimConfig.EMPHASIZED_DECELERATE, inDuration)
@ -217,8 +223,7 @@ class MaterialSlider private constructor(context: Context, private val x: Int?,
if (view.translationX > target) { if (view.translationX > target) {
view.translationX = target view.translationX = target
} }
val animator = val animator = outConfig.genericFloat(view.translationX, target) { view.translationX = it }
outConfig.genericFloat(view.translationX, target) { view.translationX = it }
return animator return animator
} }
@ -228,10 +233,11 @@ class MaterialSlider private constructor(context: Context, private val x: Int?,
} }
companion object { companion object {
fun small(context: Context, x: Int?) = MaterialSlider(context, x, AnimConfig.SHORT3, AnimConfig.MEDIUM1) fun small(context: Context, x: Int?) =
MaterialSlider(context, x, AnimConfig.SHORT3, AnimConfig.MEDIUM1)
fun large(context: Context, x: Int?) = MaterialSlider(context, x, AnimConfig.MEDIUM3, AnimConfig.SHORT3)
fun large(context: Context, x: Int?) =
MaterialSlider(context, x, AnimConfig.MEDIUM3, AnimConfig.SHORT3)
} }
} }
@ -243,7 +249,8 @@ class MaterialFadingSlider(private val slider: MaterialSlider) {
fun slideOut(view: View): Animator { fun slideOut(view: View): Animator {
val slideOut = slider.slideOut(view) val slideOut = slider.slideOut(view)
val alphaOut = ValueAnimator.ofFloat(1f, 0f).apply { val alphaOut =
ValueAnimator.ofFloat(1f, 0f).apply {
duration = slideOut.duration duration = slideOut.duration
addUpdateListener { view.alpha = it.animatedValue as Float } addUpdateListener { view.alpha = it.animatedValue as Float }
} }
@ -252,7 +259,8 @@ class MaterialFadingSlider(private val slider: MaterialSlider) {
fun slideIn(view: View): Animator { fun slideIn(view: View): Animator {
val slideIn = slider.slideIn(view) val slideIn = slider.slideIn(view)
val alphaIn = ValueAnimator.ofFloat(0f, 1f).apply { val alphaIn =
ValueAnimator.ofFloat(0f, 1f).apply {
duration = slideIn.duration duration = slideIn.duration
addUpdateListener { view.alpha = it.animatedValue as Float } addUpdateListener { view.alpha = it.animatedValue as Float }
} }