all: reformat

This commit is contained in:
Alexander Capehart
2026-05-24 18:50:04 -06:00
parent 2ce250f3b7
commit 9c048a001d
11 changed files with 204 additions and 190 deletions
@@ -38,14 +38,13 @@ import androidx.core.graphics.withSave
import androidx.core.view.isVisible
import androidx.dynamicanimation.animation.FloatValueHolder
import androidx.dynamicanimation.animation.SpringAnimation
import com.google.android.material.R as MR
import com.google.android.material.motion.MotionUtils
import org.oxycblt.auxio.R
import timber.log.Timber
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.max
import kotlin.math.min
import com.google.android.material.R as MR
import org.oxycblt.auxio.R
import timber.log.Timber
/**
* Slider with active-track wave rendering that ports MDC LinearProgressIndicator's wavy draw
@@ -153,19 +152,24 @@ constructor(
strokeCap = Paint.Cap.BUTT
strokeWidth = trackHeight.toFloat()
isAntiAlias = true
color = trackActiveTintList.getColorForState(
drawableState,
trackActiveTintList.defaultColor
)
color =
trackActiveTintList.getColorForState(
drawableState,
trackActiveTintList.defaultColor,
)
}
updateActiveTrackSuppression()
if (trackCornerSize < trackHeight) {
Timber.w("WavySlider can only be fully rounded. Clamping corner size down to trackHeight / 2")
Timber.w(
"WavySlider can only be fully rounded. Clamping corner size down to trackHeight / 2"
)
trackCornerSize = trackHeight
}
if (trackInsideCornerSize < trackHeight) {
Timber.w("WavySlider can only be fully rounded. Clamping inner corner size down to trackHeight / 2")
Timber.w(
"WavySlider can only be fully rounded. Clamping inner corner size down to trackHeight / 2"
)
trackInsideCornerSize = trackHeight
}
}
@@ -251,10 +255,7 @@ constructor(
displayedTrackThickness = trackHeight.toFloat()
displayedCornerRadius =
min(
min(displayedTrackThickness / 2f, trackCornerSize.toFloat()),
trackLength / 2f,
)
min(min(displayedTrackThickness / 2f, trackCornerSize.toFloat()), trackLength / 2f)
displayedInnerCornerRadius = displayedCornerRadius
// Calculate the actual wave path or re-use it
@@ -357,9 +358,7 @@ constructor(
startPoint.translate(startBlockCenterX + originX, trackCenterY)
endPoint.translate(endBlockCenterX + originX, trackCenterY)
if (
startBound <= 0f && endBlockCenterX < startBlockCenterX
) {
if (startBound <= 0f && endBlockCenterX < startBlockCenterX) {
drawRoundedBlock(
canvas = canvas,
drawCenter = startPoint,
@@ -392,13 +391,7 @@ constructor(
)
canvas.drawPath(displayedWavePath, wavePaint)
} else {
canvas.drawLine(
startPoint.x,
startPoint.y,
endPoint.x,
endPoint.y,
wavePaint,
)
canvas.drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, wavePaint)
}
}
@@ -423,15 +416,14 @@ constructor(
canvas: Canvas,
drawCenter: PointF,
clipCenter: PointF,
clipRight: Boolean
clipRight: Boolean,
) {
wavePaint.style = Paint.Style.FILL
canvas.withSave {
var clipWidth = trackHeight.toFloat()
val halfHeight = trackHeight / 2f
if (clipRight) {
val leftEdgeDiff =
(clipCenter.x - trackHeight / 2f) - (drawCenter.x - trackHeight)
val leftEdgeDiff = (clipCenter.x - trackHeight / 2f) - (drawCenter.x - trackHeight)
if (leftEdgeDiff > 0f) {
clipCenter.translate(-leftEdgeDiff / 2f, 0f)
clipWidth += leftEdgeDiff
@@ -443,8 +435,7 @@ constructor(
drawCenter.y + halfHeight,
)
} else {
val rightEdgeDiff =
(clipCenter.x + trackHeight / 2f) - (drawCenter.x + trackHeight)
val rightEdgeDiff = (clipCenter.x + trackHeight / 2f) - (drawCenter.x + trackHeight)
if (rightEdgeDiff < 0f) {
clipCenter.translate(-rightEdgeDiff / 2f, 0f)
clipWidth -= rightEdgeDiff
@@ -477,7 +468,7 @@ constructor(
clipRect,
trackHeight.toFloat(),
trackHeight.toFloat(),
Path.Direction.CCW
Path.Direction.CCW,
)
clipPath(roundedRectPath)
@@ -32,14 +32,12 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.transition.MaterialSharedAxis
import dagger.hilt.android.AndroidEntryPoint
import java.lang.reflect.Field
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentHomeBinding
import org.oxycblt.auxio.detail.DetailViewModel
@@ -65,7 +63,6 @@ import org.oxycblt.auxio.ui.FadingToolbarOffsetListener
import org.oxycblt.auxio.util.collect
import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.dampen
import org.oxycblt.auxio.util.lazyReflectedField
import org.oxycblt.auxio.util.navigateSafe
import org.oxycblt.auxio.util.showToast
import org.oxycblt.musikr.IndexingProgress
@@ -34,6 +34,7 @@ import androidx.dynamicanimation.animation.SpringForce
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import kotlin.math.abs
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
import org.oxycblt.auxio.detail.DetailViewModel
@@ -43,11 +44,11 @@ import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.playback.queue.QueueViewModel
import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.playback.ui.StyledSeekBar
import org.oxycblt.auxio.playback.ui.stepper.Direction
import org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
import org.oxycblt.auxio.playback.ui.swiper.CarouselTransformer
import org.oxycblt.auxio.playback.ui.swiper.CoverPagerAdapter
import org.oxycblt.auxio.playback.ui.swiper.UserAwarePagerCallback
import org.oxycblt.auxio.playback.ui.stepper.Direction
import org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.dampen
@@ -56,7 +57,6 @@ import org.oxycblt.auxio.util.showToast
import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.Song
import kotlin.math.abs
import timber.log.Timber as L
/**
@@ -73,7 +73,7 @@ class PlaybackPanelFragment :
Toolbar.OnMenuItemClickListener,
StyledSeekBar.Listener,
PlayerFastSeekOverlay.PerformListener {
private val coverPagerAdapter = CoverPagerAdapter(this)
private val coverPagerAdapter = CoverPagerAdapter(this)
private val playbackModel: PlaybackViewModel by activityViewModels()
private val detailModel: DetailViewModel by activityViewModels()
private val listModel: ListViewModel by activityViewModels()
@@ -112,11 +112,13 @@ class PlaybackPanelFragment :
binding.playbackPager?.apply {
adapter = coverPagerAdapter
userAwarePagerCallback = UserAwarePagerCallback(this) {
// Posting the queue goto command prevents the seekbar pos from desyncing
// from the song's duration, which creates a visual flicker in the seekbar.
post { queueModel.goto(it) }
}.also { it.attach() }
userAwarePagerCallback =
UserAwarePagerCallback(this) {
// Posting the queue goto command prevents the seekbar pos from desyncing
// from the song's duration, which creates a visual flicker in the seekbar.
post { queueModel.goto(it) }
}
.also { it.attach() }
setPageTransformer(CarouselTransformer())
recycler().apply {
// Make it possible to collapse the bottom sheet from the ViewPager's touch area.
@@ -179,39 +181,39 @@ class PlaybackPanelFragment :
}
// FIXME: Old code!! Maybe not necessary anymore?
// override fun onStart() {
// super.onStart()
// playbackModel.song.value?.let { requireBinding().playbackCover.bind(it) }
// requireBinding().root.viewTreeObserver.addOnGlobalLayoutListener(this)
// }
// override fun onStart() {
// super.onStart()
// playbackModel.song.value?.let { requireBinding().playbackCover.bind(it) }
// requireBinding().root.viewTreeObserver.addOnGlobalLayoutListener(this)
// }
// override fun onStop() {
// super.onStop()
// requireBinding().root.viewTreeObserver.removeOnGlobalLayoutListener(this)
// }
// override fun onStop() {
// super.onStop()
// requireBinding().root.viewTreeObserver.removeOnGlobalLayoutListener(this)
// }
// override fun onGlobalLayout() {
// if (binding == null || lastCoverWidth < 0) {
// return
// }
// Hacky workaround for cover radius not being preserved in between sizing changes
// (i.e split screen or landscape mode)
// For some reason ConstraintLayout does several passes on 1:1 elements that causes their
// size to radically change, so we wait until it stabilizes and then force an image
// reload if needed. Optimistically this is a no-op from coil caching, but when the cover
// did accidentally load the wrong image (with weird corner radius intended for bigger
// covers) we can force it to reload.
// If this breaks, it's fine since we also started a load as we normally did w/state
// updates, so the cover will not break.
// val binding = requireBinding()
// val coverWidth = binding.playbackCover.width
// if (lastCoverWidth != coverWidth) {
// lastCoverWidth = coverWidth
// } else {
// playbackModel.song.value?.let { binding.playbackCover.bind(it) }
// lastCoverWidth = -1
// }
// }
// override fun onGlobalLayout() {
// if (binding == null || lastCoverWidth < 0) {
// return
// }
// Hacky workaround for cover radius not being preserved in between sizing changes
// (i.e split screen or landscape mode)
// For some reason ConstraintLayout does several passes on 1:1 elements that causes their
// size to radically change, so we wait until it stabilizes and then force an image
// reload if needed. Optimistically this is a no-op from coil caching, but when the cover
// did accidentally load the wrong image (with weird corner radius intended for bigger
// covers) we can force it to reload.
// If this breaks, it's fine since we also started a load as we normally did w/state
// updates, so the cover will not break.
// val binding = requireBinding()
// val coverWidth = binding.playbackCover.width
// if (lastCoverWidth != coverWidth) {
// lastCoverWidth = coverWidth
// } else {
// playbackModel.song.value?.let { binding.playbackCover.bind(it) }
// lastCoverWidth = -1
// }
// }
override fun onDestroyBinding(binding: FragmentPlaybackPanelBinding) {
equalizerLauncher = null
@@ -323,7 +325,10 @@ class PlaybackPanelFragment :
// user scroll, carry on
return
}
binding.playbackPager.setCurrentItem(command.scroll, command.update == null && abs(delta) == 1)
binding.playbackPager.setCurrentItem(
command.scroll,
command.update == null && abs(delta) == 1,
)
}
}
@@ -346,7 +351,5 @@ class PlaybackPanelFragment :
}
}
private companion object {
}
private companion object {}
}
@@ -143,12 +143,7 @@ constructor(
_positionDs.value = playbackManager.progression.calculateElapsedPositionMs().msToDs()
_song.value = playbackManager.currentSong
_pagerCommand.put(
PagerCommand(
update = null,
scroll = index
)
)
_pagerCommand.put(PagerCommand(update = null, scroll = index))
_pagerQueue.value = _pagerQueue.value.copy(index = index)
}
@@ -162,29 +157,18 @@ constructor(
_pagerCommand.put(
PagerCommand(
update = change.instructions,
scroll = index.takeIf { change.type != QueueChange.Type.MAPPING }
scroll = index.takeIf { change.type != QueueChange.Type.MAPPING },
)
)
_pagerQueue.value = PagerQueue(
queue = queue,
index = index
)
_pagerQueue.value = PagerQueue(queue = queue, index = index)
}
override fun onQueueReordered(queue: List<Song>, index: Int, isShuffled: Boolean) {
L.d("Queue completely changed, updating current song")
_isShuffled.value = isShuffled
_pagerCommand.put(
PagerCommand(
update = UpdateInstructions.Replace(0),
scroll = index
)
)
_pagerQueue.value = PagerQueue(
queue = queue,
index = index
)
_pagerCommand.put(PagerCommand(update = UpdateInstructions.Replace(0), scroll = index))
_pagerQueue.value = PagerQueue(queue = queue, index = index)
}
override fun onNewPlayback(
@@ -198,16 +182,8 @@ constructor(
_parent.value = parent
_isShuffled.value = isShuffled
_pagerCommand.put(
PagerCommand(
update = UpdateInstructions.Replace(0),
scroll = index
)
)
_pagerQueue.value = PagerQueue(
queue = queue,
index = index
)
_pagerCommand.put(PagerCommand(update = UpdateInstructions.Replace(0), scroll = index))
_pagerQueue.value = PagerQueue(queue = queue, index = index)
}
override fun onProgressionChanged(progression: Progression) {
@@ -493,7 +469,8 @@ constructor(
val currentPositionMs = playbackManager.progression.calculateElapsedPositionMs()
val currentSong = playbackManager.currentSong
if (currentSong != null) {
val newPositionMs = (currentPositionMs + STEP_INCREMENT).coerceAtMost(currentSong.durationMs)
val newPositionMs =
(currentPositionMs + STEP_INCREMENT).coerceAtMost(currentSong.durationMs)
playbackManager.seekTo(newPositionMs)
}
}
@@ -684,16 +661,9 @@ constructor(
}
}
data class PagerQueue(val queue: List<Song>, val index: Int)
data class PagerQueue(
val queue: List<Song>,
val index: Int
)
data class PagerCommand(
val update: UpdateInstructions?,
val scroll: Int?
)
data class PagerCommand(val update: UpdateInstructions?, val scroll: Int?)
/**
* Command for controlling the main playback panel UI.
@@ -31,14 +31,14 @@ import androidx.dynamicanimation.animation.SpringAnimation
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.Effect
import org.oxycblt.auxio.ui.UISettings
import javax.inject.Inject
enum class Direction {
FORWARDS,
BACKWARDS
BACKWARDS,
}
@AndroidEntryPoint
@@ -46,8 +46,11 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
ConstraintLayout(context, attrs), GestureDetector.OnDoubleTapListener {
private sealed interface OverlayState {
data object Invisible : OverlayState
data class Entering(val tap: SpringAnimation, val seconds: SpringAnimation) : OverlayState
data class Wait(val runnable: Runnable) : OverlayState
data class Exiting(val tap: SpringAnimation, val seconds: SpringAnimation) : OverlayState
}
@@ -63,7 +66,6 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
private val alphaSpring = Effect.FAST
private var leftOverlayState: OverlayState = OverlayState.Invisible
private var rightOverlayState: OverlayState = OverlayState.Invisible
@@ -79,17 +81,17 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
val shapeAppearanceRes =
getResourceId(
R.styleable.PlayerFastSeekOverlay_shapeAppearance,
com.google.android.material.R.style
.ShapeAppearance_Material3_Corner_Medium
com.google.android.material.R.style.ShapeAppearance_Material3_Corner_Medium,
)
background =
MaterialShapeDrawable().apply {
shapeAppearanceModel = if (uiSettings.roundMode) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder().build()
}
shapeAppearanceModel =
if (uiSettings.roundMode) {
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder().build()
}
// Set transparent background as we only want the clipping
fillColor = ColorStateList.valueOf(Color.TRANSPARENT)
}
@@ -131,22 +133,22 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
rightTapView.setDirection(Direction.FORWARDS) // isLeft = false for right side
}
override fun onTouchEvent(event: MotionEvent): Boolean =
gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
override fun onSingleTapConfirmed(e: MotionEvent) = false
private fun enter(secondsView: SecondsView, tapView: TapView, overlayState: (OverlayState) -> Unit) {
private fun enter(
secondsView: SecondsView,
tapView: TapView,
overlayState: (OverlayState) -> Unit,
) {
// start animating the seconds icon
secondsView.startAnimation()
val secondsIn = alphaSpring.alpha(secondsView, 1.0f)
val tapIn = alphaSpring.alpha(tapView, 1.0f)
// will execute after a delay
val out = Runnable {
exit(secondsView, tapView, overlayState)
}
val out = Runnable { exit(secondsView, tapView, overlayState) }
tapIn.addEndListener { _, cancelled, _, _ ->
if (!cancelled) {
postDelayed(out, EXIT_DELAY_MS)
@@ -156,7 +158,11 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
overlayState(OverlayState.Entering(secondsIn, tapIn))
}
private fun exit(secondsView: SecondsView, tapView: TapView, overlayState: (OverlayState) -> Unit) {
private fun exit(
secondsView: SecondsView,
tapView: TapView,
overlayState: (OverlayState) -> Unit,
) {
val secondsOut = alphaSpring.alpha(secondsView, 0.0f)
val tapOut = alphaSpring.alpha(tapView, 0.0f)
tapOut.addEndListener { _, cancelled, _, _ ->
@@ -257,7 +263,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
rightSecondsView,
rightTapView,
rightOverlayState,
{ rightOverlayState = it }
{ rightOverlayState = it },
)
}
@@ -18,13 +18,11 @@
package org.oxycblt.auxio.playback.ui.stepper
import android.animation.ValueAnimator
import android.content.Context
import android.provider.Settings
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.animation.addListener
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.dynamicanimation.animation.SpringAnimation
import org.oxycblt.auxio.R
@@ -100,13 +98,24 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
}
// cycle animation for the 3 icons
private val cyclicAlpha = floatArrayOf(
1.00f, 0.25f, 0.25f,
1.00f, 1.00f, 0.25f,
0.25f, 1.00f, 1.00f,
0.25f, 0.25f, 1.00f,
0.25f, 0.25f, 0.25f,
)
private val cyclicAlpha =
floatArrayOf(
1.00f,
0.25f,
0.25f,
1.00f,
1.00f,
0.25f,
0.25f,
1.00f,
1.00f,
0.25f,
0.25f,
1.00f,
0.25f,
0.25f,
0.25f,
)
private fun cycle(at: Int = 0) {
animations.forEach { it.cancel() }
@@ -114,11 +123,12 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
val one = alphaSpring.alpha(binding.icon1, cyclicAlpha[row])
val two = alphaSpring.alpha(binding.icon2, cyclicAlpha[row + 1])
val three = alphaSpring.alpha(binding.icon3, cyclicAlpha[row + 2])
val endListener = DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) {
cycle((at + 1) % 5)
val endListener =
DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) {
cycle((at + 1) % 5)
}
}
}
when {
cyclicAlpha[row] != binding.icon1.alpha -> {
one.addEndListener(endListener)
@@ -132,5 +142,4 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
}
animations = listOf(one, two, three)
}
}
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2025 Auxio Project
* CircleClipTapView.kt is part of Auxio.
* TapView.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
@@ -25,9 +25,7 @@ import android.graphics.Path
import android.util.AttributeSet
import android.view.View
/**
* Cricle
*/
/** Cricle */
class TapView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var backgroundPaint = Paint()
@@ -1,12 +1,27 @@
/*
* Copyright (c) 2026 Auxio Project
* CarouselTransformer.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.swiper
import android.graphics.RectF
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.carousel.MaskableFrameLayout
import com.google.android.material.math.MathUtils.lerp
import kotlin.math.abs
class CarouselTransformer : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) {
@@ -54,17 +69,14 @@ class CarouselTransformer : ViewPager2.PageTransformer {
when {
// gap is not fully grown yet, so we do the gap size * how close we are to a fully
// grown gap
p < gapEnterBreakpoint ->
maxGap * (p / gapEnterBreakpoint)
p < gapEnterBreakpoint -> maxGap * (p / gapEnterBreakpoint)
// gap should be shrinking, so we need to downscale maxgap by how close we are
// actually to the end
p > gapExitBreakpoint ->
maxGap * ((1f - p) / (1f - gapExitBreakpoint))
p > gapExitBreakpoint -> maxGap * ((1f - p) / (1f - gapExitBreakpoint))
// not growing or shrinking
else ->
maxGap
else -> maxGap
}
// then we need to get how much we actually want to reveal the incoming covers post-gap
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2026 Auxio Project
* CoverPagerAdapter.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.swiper
import android.view.ViewGroup
@@ -14,13 +32,11 @@ import org.oxycblt.musikr.Song
* gesture overlays.
*
* @param listener The [PlayerFastSeekOverlay.PerformListener] that step gesture events will be
* forwarded to
*
* forwarded to
* @author Alexander Capehart (OxygenCobalt)
*/
class CoverPagerAdapter(
private val listener: PlayerFastSeekOverlay.PerformListener
) : FlexibleListAdapter<Song, CoverViewHolder>(CoverViewHolder.DIFF_CALLBACK) {
class CoverPagerAdapter(private val listener: PlayerFastSeekOverlay.PerformListener) :
FlexibleListAdapter<Song, CoverViewHolder>(CoverViewHolder.DIFF_CALLBACK) {
override fun onCreateViewHolder(parent: ViewGroup, pos: Int) = CoverViewHolder.from(parent)
@@ -54,7 +70,8 @@ class CoverViewHolder private constructor(private val binding: ItemCoverBinding)
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: ViewGroup) = CoverViewHolder(ItemCoverBinding.inflate(parent.context.inflater, parent, false))
fun from(parent: ViewGroup) =
CoverViewHolder(ItemCoverBinding.inflate(parent.context.inflater, parent, false))
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -1,18 +1,38 @@
/*
* Copyright (c) 2026 Auxio Project
* UserAwarePagerCallback.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.swiper
import androidx.viewpager2.widget.ViewPager2
/**
* A [ViewPager2.OnPageChangeCallback] that only fires [userCallback] when a user actually
* enagages in a swipe action. [ViewPager2] doesn't normally supply this so we have to do it
* via a stateful object.
* A [ViewPager2.OnPageChangeCallback] that only fires [userCallback] when a user actually enagages
* in a swipe action. [ViewPager2] doesn't normally supply this so we have to do it via a stateful
* object.
*
* @param viewPager [ViewPager2] that this will be attached to (must do this separately)
* @param userCallback The callback to run on a user-driven swipe
*
* @author Alexander Capehart (OxygenCobalt), Idea from GPT-5.5 (Rewritten)
*/
class UserAwarePagerCallback(private val viewPager: ViewPager2, private val userCallback: (Int) -> Unit) : ViewPager2.OnPageChangeCallback() {
class UserAwarePagerCallback(
private val viewPager: ViewPager2,
private val userCallback: (Int) -> Unit,
) : ViewPager2.OnPageChangeCallback() {
private var user = false
override fun onPageScrollStateChanged(state: Int) {
@@ -37,17 +57,13 @@ class UserAwarePagerCallback(private val viewPager: ViewPager2, private val user
}
}
/**
* Attach this to the passed [viewPager].
*/
/** Attach this to the passed [viewPager]. */
fun attach() {
viewPager.registerOnPageChangeCallback(this)
}
/**
* Detach this from the passed [viewPager].
*/
/** Detach this from the passed [viewPager]. */
fun release() {
viewPager.unregisterOnPageChangeCallback(this)
}
}
}
@@ -36,18 +36,14 @@ import androidx.core.net.toUri
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import androidx.viewpager2.widget.ViewPager2
import java.lang.IllegalArgumentException
import java.lang.reflect.Field
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.Spatial
import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.Song
import java.lang.reflect.Field
import kotlin.math.abs
import kotlin.math.sign
import timber.log.Timber as L
/**
@@ -149,10 +145,9 @@ private val RV_TOUCH_SLOP_FIELD: Field by lazyReflectedField(RecyclerView::class
/**
* Dampen a [ViewPager2] so that vertical scrolls can still easily occur.
*
* By default, ViewPager2's sensitivity is high enough to result in vertical scroll
* events being registered as horizontal scroll events. Reflect into the internal
* RecyclerView and change the touch slope so that touch actions will act more as a
* scroll than as a swipe. Derived from:
* By default, ViewPager2's sensitivity is high enough to result in vertical scroll events being
* registered as horizontal scroll events. Reflect into the internal RecyclerView and change the
* touch slope so that touch actions will act more as a scroll than as a swipe. Derived from:
* https://al-e-shevelev.medium.com/how-to-reduce-scroll-sensitivity-of-viewpager2-widget-87797ad02414
*/
fun ViewPager2.dampen() {