playback: prototype stepping support
This commit is contained in:
@@ -38,8 +38,8 @@ import org.oxycblt.auxio.list.ListViewModel
|
||||
import org.oxycblt.auxio.music.resolve
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||
import org.oxycblt.auxio.playback.ui.ControlledCoverView
|
||||
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
||||
import org.oxycblt.auxio.playback.ui.SwipeCoverView
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
@@ -61,7 +61,7 @@ class PlaybackPanelFragment :
|
||||
ViewBindingFragment<FragmentPlaybackPanelBinding>(),
|
||||
Toolbar.OnMenuItemClickListener,
|
||||
StyledSeekBar.Listener,
|
||||
SwipeCoverView.OnSwipeListener,
|
||||
ControlledCoverView.OnSwipeListener,
|
||||
ViewTreeObserver.OnGlobalLayoutListener {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
@@ -213,6 +213,14 @@ class PlaybackPanelFragment :
|
||||
playbackModel.next()
|
||||
}
|
||||
|
||||
override fun onStepBack() {
|
||||
playbackModel.stepBack()
|
||||
}
|
||||
|
||||
override fun onStepForward() {
|
||||
playbackModel.stepForward()
|
||||
}
|
||||
|
||||
private fun updateSong(song: Song?) {
|
||||
if (song == null) {
|
||||
// Nothing to do.
|
||||
|
||||
@@ -424,6 +424,25 @@ constructor(
|
||||
playbackManager.seekTo(positionDs.dsToMs())
|
||||
}
|
||||
|
||||
/** Step back by 10 seconds in the current song. */
|
||||
fun stepBack() {
|
||||
L.d("Stepping back 10 seconds")
|
||||
val currentPositionMs = playbackManager.progression.calculateElapsedPositionMs()
|
||||
val newPositionMs = (currentPositionMs - 10000).coerceAtLeast(0)
|
||||
playbackManager.seekTo(newPositionMs)
|
||||
}
|
||||
|
||||
/** Step forward by 10 seconds in the current song. */
|
||||
fun stepForward() {
|
||||
L.d("Stepping forward 10 seconds")
|
||||
val currentPositionMs = playbackManager.progression.calculateElapsedPositionMs()
|
||||
val currentSong = playbackManager.currentSong
|
||||
if (currentSong != null) {
|
||||
val newPositionMs = (currentPositionMs + 10000).coerceAtMost(currentSong.durationMs)
|
||||
playbackManager.seekTo(newPositionMs)
|
||||
}
|
||||
}
|
||||
|
||||
// --- QUEUE FUNCTIONS ---
|
||||
|
||||
/** Skip to the next [Song]. */
|
||||
|
||||
+39
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* SwipeCoverView.kt is part of Auxio.
|
||||
* ControlledCoverView.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
|
||||
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.OnDoubleTapListener
|
||||
import android.view.GestureDetector.OnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
@@ -30,12 +31,13 @@ import kotlin.math.abs
|
||||
import org.oxycblt.auxio.image.CoverView
|
||||
import org.oxycblt.auxio.util.isRtl
|
||||
|
||||
class SwipeCoverView
|
||||
class ControlledCoverView
|
||||
@JvmOverloads
|
||||
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
||||
CoverView(context, attrs, defStyleAttr), OnGestureListener {
|
||||
CoverView(context, attrs, defStyleAttr), OnGestureListener, OnDoubleTapListener {
|
||||
|
||||
private val gestureDetector = GestureDetector(context, this)
|
||||
private val gestureDetector =
|
||||
GestureDetector(context, this).apply { setOnDoubleTapListener(this@ControlledCoverView) }
|
||||
private val viewConfig = ViewConfiguration.get(context)
|
||||
|
||||
var onSwipeListener: OnSwipeListener? = null
|
||||
@@ -90,6 +92,35 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
|
||||
override fun onLongPress(e: MotionEvent) = Unit
|
||||
|
||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean = false
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
val width = width
|
||||
val tapX = e.x
|
||||
|
||||
when {
|
||||
tapX < width * 0.33f -> {
|
||||
if (isRtl) {
|
||||
onSwipeListener?.onStepForward()
|
||||
} else {
|
||||
onSwipeListener?.onStepBack()
|
||||
}
|
||||
return true
|
||||
}
|
||||
tapX > width * 0.67f -> {
|
||||
if (isRtl) {
|
||||
onSwipeListener?.onStepBack()
|
||||
} else {
|
||||
onSwipeListener?.onStepForward()
|
||||
}
|
||||
return true
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDoubleTapEvent(e: MotionEvent): Boolean = false
|
||||
|
||||
private fun onSwipeRight() {
|
||||
onSwipeListener?.run { if (isRtl) onSwipeNext() else onSwipePrevious() }
|
||||
}
|
||||
@@ -103,5 +134,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
||||
fun onSwipePrevious()
|
||||
|
||||
fun onSwipeNext()
|
||||
|
||||
fun onStepBack()
|
||||
|
||||
fun onStepForward()
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
tools:subtitle="@string/lbl_all_songs" />
|
||||
|
||||
|
||||
<org.oxycblt.auxio.playback.ui.SwipeCoverView
|
||||
<org.oxycblt.auxio.playback.ui.ControlledCoverView
|
||||
android:id="@+id/playback_cover"
|
||||
style="@style/Widget.Auxio.Image.Full"
|
||||
android:layout_marginStart="@dimen/spacing_medium"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
app:titleTextAppearance="@style/TextAppearance.Auxio.LabelLarge"
|
||||
tools:subtitle="@string/lbl_all_songs" />
|
||||
|
||||
<org.oxycblt.auxio.playback.ui.SwipeCoverView
|
||||
<org.oxycblt.auxio.playback.ui.ControlledCoverView
|
||||
android:id="@+id/playback_cover"
|
||||
style="@style/Widget.Auxio.Image.Full"
|
||||
android:layout_margin="@dimen/spacing_medium"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
tools:subtitle="@string/lbl_all_songs" />
|
||||
|
||||
|
||||
<org.oxycblt.auxio.playback.ui.SwipeCoverView
|
||||
<org.oxycblt.auxio.playback.ui.ControlledCoverView
|
||||
android:id="@+id/playback_cover"
|
||||
style="@style/Widget.Auxio.Image.Full"
|
||||
android:layout_marginVertical="@dimen/spacing_small"
|
||||
|
||||
Reference in New Issue
Block a user