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

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.oxycblt.auxio.list.recycler package org.oxycblt.auxio.list.recycler
import android.animation.Animator import android.animation.Animator
@ -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,29 +104,29 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
} }
} }
private val popupView = MaterialTextView(context).apply { private val popupView =
minimumWidth = context.getDimenPixels(R.dimen.size_touchable_large) MaterialTextView(context).apply {
minimumHeight = context.getDimenPixels(R.dimen.size_touchable_small) minimumWidth = context.getDimenPixels(R.dimen.size_touchable_large)
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(
ellipsize = TextUtils.TruncateAt.MIDDLE context.getAttrColorCompat(com.google.android.material.R.attr.colorOnSecondary))
gravity = Gravity.CENTER ellipsize = TextUtils.TruncateAt.MIDDLE
includeFontPadding = false gravity = Gravity.CENTER
includeFontPadding = false
elevation = elevation =
context.getDimenPixels(com.google.android.material.R.dimen.m3_sys_elevation_level1) context
.toFloat() .getDimenPixels(com.google.android.material.R.dimen.m3_sys_elevation_level1)
background = context.getDrawableCompat(R.drawable.ui_popup) .toFloat()
updatePaddingRelative(end = context.getDimenPixels(R.dimen.spacing_tiny) / 2) background = context.getDrawableCompat(R.drawable.ui_popup)
layoutParams = updatePaddingRelative(end = context.getDimenPixels(R.dimen.spacing_tiny) / 2)
FrameLayout.LayoutParams( layoutParams =
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT FrameLayout.LayoutParams(
) ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.apply { .apply { gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP }
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 {
jumpOut(popupView) jumpOut(popupView)
@ -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) {
@ -266,25 +266,24 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
ViewGroup.getChildMeasureSpec( ViewGroup.getChildMeasureSpec(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
thumbPadding.left + thumbPadding.left +
thumbPadding.right + thumbPadding.right +
thumbWidth + thumbWidth +
popupLayoutParams.leftMargin + popupLayoutParams.leftMargin +
popupLayoutParams.rightMargin, popupLayoutParams.rightMargin,
popupLayoutParams.width popupLayoutParams.width)
)
val heightMeasureSpec = val heightMeasureSpec =
ViewGroup.getChildMeasureSpec( ViewGroup.getChildMeasureSpec(
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
thumbPadding.top + thumbPadding.top +
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,19 +249,21 @@ 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 =
duration = slideOut.duration ValueAnimator.ofFloat(1f, 0f).apply {
addUpdateListener { view.alpha = it.animatedValue as Float } duration = slideOut.duration
} addUpdateListener { view.alpha = it.animatedValue as Float }
}
return AnimatorSet().apply { playTogether(slideOut, alphaOut) } return AnimatorSet().apply { playTogether(slideOut, alphaOut) }
} }
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 =
duration = slideIn.duration ValueAnimator.ofFloat(0f, 1f).apply {
addUpdateListener { view.alpha = it.animatedValue as Float } duration = slideIn.duration
} addUpdateListener { view.alpha = it.animatedValue as Float }
}
return AnimatorSet().apply { playTogether(slideIn, alphaIn) } return AnimatorSet().apply { playTogether(slideIn, alphaIn) }
} }
} }