playback: prototype stepping indicator v2
This commit is contained in:
@@ -40,6 +40,8 @@ import org.oxycblt.auxio.music.resolveNames
|
|||||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||||
import org.oxycblt.auxio.playback.ui.ControlledCoverView
|
import org.oxycblt.auxio.playback.ui.ControlledCoverView
|
||||||
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
||||||
|
import org.oxycblt.auxio.playback.ui.stepper.DisplayPortion
|
||||||
|
import org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
|
||||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||||
import org.oxycblt.auxio.util.collectImmediately
|
import org.oxycblt.auxio.util.collectImmediately
|
||||||
import org.oxycblt.auxio.util.showToast
|
import org.oxycblt.auxio.util.showToast
|
||||||
@@ -61,8 +63,8 @@ class PlaybackPanelFragment :
|
|||||||
ViewBindingFragment<FragmentPlaybackPanelBinding>(),
|
ViewBindingFragment<FragmentPlaybackPanelBinding>(),
|
||||||
Toolbar.OnMenuItemClickListener,
|
Toolbar.OnMenuItemClickListener,
|
||||||
StyledSeekBar.Listener,
|
StyledSeekBar.Listener,
|
||||||
ControlledCoverView.OnSwipeListener,
|
ViewTreeObserver.OnGlobalLayoutListener,
|
||||||
ViewTreeObserver.OnGlobalLayoutListener {
|
PlayerFastSeekOverlay.PerformListener {
|
||||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||||
private val detailModel: DetailViewModel by activityViewModels()
|
private val detailModel: DetailViewModel by activityViewModels()
|
||||||
private val listModel: ListViewModel by activityViewModels()
|
private val listModel: ListViewModel by activityViewModels()
|
||||||
@@ -97,7 +99,14 @@ class PlaybackPanelFragment :
|
|||||||
setOnMenuItemClickListener(this@PlaybackPanelFragment)
|
setOnMenuItemClickListener(this@PlaybackPanelFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.playbackCover.onSwipeListener = this
|
// Disable swipe gestures on cover for now
|
||||||
|
binding.playbackCover.onSwipeListener = null
|
||||||
|
|
||||||
|
// Set up fast seek overlay
|
||||||
|
binding.playbackFastSeekOverlay?.apply {
|
||||||
|
performListener(this@PlaybackPanelFragment)
|
||||||
|
seekSecondsSupplier { 10 } // 10 seconds per double-tap
|
||||||
|
}
|
||||||
binding.playbackSong.apply {
|
binding.playbackSong.apply {
|
||||||
isSelected = true
|
isSelected = true
|
||||||
setOnClickListener { navigateToCurrentSong() }
|
setOnClickListener { navigateToCurrentSong() }
|
||||||
@@ -205,21 +214,6 @@ class PlaybackPanelFragment :
|
|||||||
playbackModel.seekTo(positionDs)
|
playbackModel.seekTo(positionDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSwipePrevious() {
|
|
||||||
playbackModel.prev()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSwipeNext() {
|
|
||||||
playbackModel.next()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStepBack() {
|
|
||||||
playbackModel.stepBack()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStepForward() {
|
|
||||||
playbackModel.stepForward()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateSong(song: Song?) {
|
private fun updateSong(song: Song?) {
|
||||||
if (song == null) {
|
if (song == null) {
|
||||||
@@ -274,4 +268,31 @@ class PlaybackPanelFragment :
|
|||||||
private fun navigateToCurrentAlbum() {
|
private fun navigateToCurrentAlbum() {
|
||||||
playbackModel.song.value?.let { detailModel.showAlbum(it.album) }
|
playbackModel.song.value?.let { detailModel.showAlbum(it.album) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlayerFastSeekOverlay.PerformListener implementation
|
||||||
|
override fun onDoubleTap() {
|
||||||
|
// Already handled by onStepForward/onStepBack
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTapEnd() {
|
||||||
|
// Animation cleanup is handled by the overlay
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFastSeekDirection(portion: DisplayPortion): PlayerFastSeekOverlay.PerformListener.FastSeekDirection {
|
||||||
|
return when (portion) {
|
||||||
|
DisplayPortion.LEFT, DisplayPortion.LEFT_HALF ->
|
||||||
|
PlayerFastSeekOverlay.PerformListener.FastSeekDirection.BACKWARD
|
||||||
|
DisplayPortion.RIGHT, DisplayPortion.RIGHT_HALF ->
|
||||||
|
PlayerFastSeekOverlay.PerformListener.FastSeekDirection.FORWARD
|
||||||
|
else -> PlayerFastSeekOverlay.PerformListener.FastSeekDirection.NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun seek(forward: Boolean) {
|
||||||
|
if (forward) {
|
||||||
|
playbackModel.stepForward()
|
||||||
|
} else {
|
||||||
|
playbackModel.stepBack()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* CircleClipTapView.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.stepper
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Path
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
class CircleClipTapView(context: Context?, attrs: AttributeSet) : View(context, attrs) {
|
||||||
|
|
||||||
|
private var backgroundPaint = Paint()
|
||||||
|
|
||||||
|
private var widthPx = 0
|
||||||
|
private var heightPx = 0
|
||||||
|
|
||||||
|
// Background
|
||||||
|
|
||||||
|
private var shapePath = Path()
|
||||||
|
private var arcSize: Float = 80f
|
||||||
|
private var isLeft = true
|
||||||
|
|
||||||
|
init {
|
||||||
|
requireNotNull(context) { "Context is null." }
|
||||||
|
|
||||||
|
backgroundPaint.apply {
|
||||||
|
style = Paint.Style.FILL
|
||||||
|
isAntiAlias = true
|
||||||
|
color = 0x30000000
|
||||||
|
}
|
||||||
|
|
||||||
|
val dm = context.resources.displayMetrics
|
||||||
|
widthPx = dm.widthPixels
|
||||||
|
heightPx = dm.heightPixels
|
||||||
|
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateArcSize(baseView: View) {
|
||||||
|
val newArcSize = baseView.height / 11.4f
|
||||||
|
if (arcSize != newArcSize) {
|
||||||
|
arcSize = newArcSize
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updatePosition(newIsLeft: Boolean) {
|
||||||
|
if (isLeft != newIsLeft) {
|
||||||
|
isLeft = newIsLeft
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePathShape() {
|
||||||
|
val halfWidth = widthPx * 0.5f
|
||||||
|
|
||||||
|
shapePath.reset()
|
||||||
|
|
||||||
|
val w = if (isLeft) 0f else widthPx.toFloat()
|
||||||
|
val f = if (isLeft) 1 else -1
|
||||||
|
|
||||||
|
shapePath.moveTo(w, 0f)
|
||||||
|
shapePath.lineTo(f * (halfWidth - arcSize) + w, 0f)
|
||||||
|
shapePath.quadTo(
|
||||||
|
f * (halfWidth + arcSize) + w,
|
||||||
|
heightPx.toFloat() / 2,
|
||||||
|
f * (halfWidth - arcSize) + w,
|
||||||
|
heightPx.toFloat())
|
||||||
|
shapePath.lineTo(w, heightPx.toFloat())
|
||||||
|
|
||||||
|
shapePath.close()
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
widthPx = w
|
||||||
|
heightPx = h
|
||||||
|
updatePathShape()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
|
||||||
|
canvas.clipPath(shapePath)
|
||||||
|
canvas.drawPath(shapePath, backgroundPaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* PlayerFastSeekOverlay.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.stepper
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.GestureDetector
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.START
|
||||||
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
|
import org.oxycblt.auxio.BuildConfig
|
||||||
|
import org.oxycblt.auxio.R
|
||||||
|
|
||||||
|
enum class DisplayPortion {
|
||||||
|
LEFT,
|
||||||
|
MIDDLE,
|
||||||
|
RIGHT,
|
||||||
|
LEFT_HALF,
|
||||||
|
RIGHT_HALF
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DoubleTapListener {
|
||||||
|
fun onDoubleTapStarted(portion: DisplayPortion)
|
||||||
|
|
||||||
|
fun onDoubleTapProgressDown(portion: DisplayPortion)
|
||||||
|
|
||||||
|
fun onDoubleTapFinished()
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
|
||||||
|
ConstraintLayout(context, attrs), DoubleTapListener, GestureDetector.OnDoubleTapListener {
|
||||||
|
|
||||||
|
private var secondsView: SecondsView
|
||||||
|
private var circleClipTapView: CircleClipTapView
|
||||||
|
private var rootConstraintLayout: ConstraintLayout
|
||||||
|
|
||||||
|
private var wasForwarding: Boolean = false
|
||||||
|
private val gestureDetector: GestureDetector
|
||||||
|
|
||||||
|
init {
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.player_fast_seek_overlay, this, true)
|
||||||
|
|
||||||
|
secondsView = findViewById(R.id.seconds_view)
|
||||||
|
circleClipTapView = findViewById(R.id.circle_clip_tap_view)
|
||||||
|
rootConstraintLayout = findViewById(R.id.root_constraint_layout)
|
||||||
|
|
||||||
|
// Hide overlay elements by default
|
||||||
|
secondsView.alpha = 0f
|
||||||
|
circleClipTapView.alpha = 0f
|
||||||
|
secondsView.visibility = INVISIBLE
|
||||||
|
circleClipTapView.visibility = INVISIBLE
|
||||||
|
|
||||||
|
// Set up gesture detection
|
||||||
|
gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
override fun onDown(e: MotionEvent) = true
|
||||||
|
})
|
||||||
|
gestureDetector.setOnDoubleTapListener(this)
|
||||||
|
|
||||||
|
addOnLayoutChangeListener { view, _, _, _, _, _, _, _, _ ->
|
||||||
|
circleClipTapView.updateArcSize(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var performListener: PerformListener? = null
|
||||||
|
|
||||||
|
fun performListener(listener: PerformListener?) = apply { performListener = listener }
|
||||||
|
|
||||||
|
private var seekSecondsSupplier: () -> Int = { 0 }
|
||||||
|
|
||||||
|
fun seekSecondsSupplier(supplier: (() -> Int)?) = apply {
|
||||||
|
seekSecondsSupplier = supplier ?: { 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indicates whether this (double) tap is the first of a series
|
||||||
|
// Decides whether to call performListener.onAnimationStart or not
|
||||||
|
private var initTap: Boolean = false
|
||||||
|
|
||||||
|
// Track if we're currently animating to avoid redundant animations
|
||||||
|
private var isAnimatingIn: Boolean = false
|
||||||
|
private var fadeOutRunnable: Runnable? = null
|
||||||
|
|
||||||
|
override fun onDoubleTapStarted(portion: DisplayPortion) {
|
||||||
|
if (DEBUG) Log.d(TAG, "onDoubleTapStarted called with portion = [$portion]")
|
||||||
|
|
||||||
|
initTap = false
|
||||||
|
|
||||||
|
secondsView.stopAnimation()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTapProgressDown(portion: DisplayPortion) {
|
||||||
|
val shouldForward: Boolean =
|
||||||
|
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
|
||||||
|
|
||||||
|
if (DEBUG)
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"onDoubleTapProgressDown called with " +
|
||||||
|
"shouldForward = [$shouldForward], " +
|
||||||
|
"wasForwarding = [$wasForwarding], " +
|
||||||
|
"initTap = [$initTap], ")
|
||||||
|
|
||||||
|
// Cancel any pending fade out
|
||||||
|
fadeOutRunnable?.let {
|
||||||
|
removeCallbacks(it)
|
||||||
|
fadeOutRunnable = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if a initial tap occurred or if direction was switched
|
||||||
|
*/
|
||||||
|
if (!initTap || wasForwarding != shouldForward) {
|
||||||
|
// Reset seconds and update position
|
||||||
|
secondsView.seconds = 0
|
||||||
|
changeConstraints(shouldForward)
|
||||||
|
circleClipTapView.updatePosition(!shouldForward)
|
||||||
|
secondsView.setForwarding(shouldForward)
|
||||||
|
|
||||||
|
wasForwarding = shouldForward
|
||||||
|
|
||||||
|
if (!initTap) {
|
||||||
|
initTap = true
|
||||||
|
// Only fade in if we're not already visible and animating
|
||||||
|
if (!isAnimatingIn && secondsView.alpha < 1f) {
|
||||||
|
isAnimatingIn = true
|
||||||
|
secondsView.visibility = VISIBLE
|
||||||
|
circleClipTapView.visibility = VISIBLE
|
||||||
|
secondsView.animate()
|
||||||
|
.alpha(1f)
|
||||||
|
.setDuration(200)
|
||||||
|
.withEndAction { isAnimatingIn = false }
|
||||||
|
.start()
|
||||||
|
circleClipTapView.animate()
|
||||||
|
.alpha(1f)
|
||||||
|
.setDuration(200)
|
||||||
|
.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For rapid taps, ensure we're fully visible without re-animating
|
||||||
|
if (secondsView.alpha < 1f && !isAnimatingIn) {
|
||||||
|
secondsView.alpha = 1f
|
||||||
|
circleClipTapView.alpha = 1f
|
||||||
|
secondsView.visibility = VISIBLE
|
||||||
|
circleClipTapView.visibility = VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
performListener?.onDoubleTap()
|
||||||
|
|
||||||
|
secondsView.seconds += seekSecondsSupplier.invoke()
|
||||||
|
performListener?.seek(forward = shouldForward)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTapFinished() {
|
||||||
|
if (DEBUG) Log.d(TAG, "onDoubleTapFinished called with initTap = [$initTap]")
|
||||||
|
|
||||||
|
if (initTap) performListener?.onDoubleTapEnd()
|
||||||
|
initTap = false
|
||||||
|
|
||||||
|
secondsView.stopAnimation()
|
||||||
|
|
||||||
|
// Cancel any existing fade out
|
||||||
|
fadeOutRunnable?.let {
|
||||||
|
removeCallbacks(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule fade out overlay after a delay
|
||||||
|
fadeOutRunnable = Runnable {
|
||||||
|
isAnimatingIn = false
|
||||||
|
secondsView.animate()
|
||||||
|
.alpha(0f)
|
||||||
|
.setDuration(200)
|
||||||
|
.withEndAction {
|
||||||
|
secondsView.visibility = INVISIBLE
|
||||||
|
}
|
||||||
|
.start()
|
||||||
|
circleClipTapView.animate()
|
||||||
|
.alpha(0f)
|
||||||
|
.setDuration(200)
|
||||||
|
.withEndAction {
|
||||||
|
circleClipTapView.visibility = INVISIBLE
|
||||||
|
}
|
||||||
|
.start()
|
||||||
|
fadeOutRunnable = null
|
||||||
|
}
|
||||||
|
postDelayed(fadeOutRunnable, 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun changeConstraints(forward: Boolean) {
|
||||||
|
val constraintSet = ConstraintSet()
|
||||||
|
with(constraintSet) {
|
||||||
|
clone(rootConstraintLayout)
|
||||||
|
clear(secondsView.id, if (forward) START else END)
|
||||||
|
connect(
|
||||||
|
secondsView.id, if (forward) END else START, PARENT_ID, if (forward) END else START)
|
||||||
|
secondsView.startAnimation()
|
||||||
|
applyTo(rootConstraintLayout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PerformListener {
|
||||||
|
fun onDoubleTap()
|
||||||
|
|
||||||
|
fun onDoubleTapEnd()
|
||||||
|
/** Determines if the playback should forward/rewind or do nothing. */
|
||||||
|
fun getFastSeekDirection(portion: DisplayPortion): FastSeekDirection
|
||||||
|
|
||||||
|
fun seek(forward: Boolean)
|
||||||
|
|
||||||
|
enum class FastSeekDirection(val directionAsBoolean: Boolean?) {
|
||||||
|
NONE(null),
|
||||||
|
FORWARD(true),
|
||||||
|
BACKWARD(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
return gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GestureDetector.OnDoubleTapListener implementation
|
||||||
|
override fun onSingleTapConfirmed(e: MotionEvent) = false
|
||||||
|
|
||||||
|
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||||
|
val width = width
|
||||||
|
val tapX = e.x
|
||||||
|
|
||||||
|
val portion = when {
|
||||||
|
tapX < width * 0.33f -> DisplayPortion.LEFT_HALF
|
||||||
|
tapX > width * 0.67f -> DisplayPortion.RIGHT_HALF
|
||||||
|
else -> DisplayPortion.MIDDLE
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portion != DisplayPortion.MIDDLE) {
|
||||||
|
onDoubleTapStarted(portion)
|
||||||
|
onDoubleTapProgressDown(portion)
|
||||||
|
onDoubleTapFinished()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTapEvent(e: MotionEvent) = false
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "PlayerFastSeekOverlay"
|
||||||
|
private val DEBUG = BuildConfig.DEBUG
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* SecondsView.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.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 org.oxycblt.auxio.R
|
||||||
|
import org.oxycblt.auxio.databinding.PlayerFastSeekSecondsViewBinding
|
||||||
|
|
||||||
|
class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ICON_ANIMATION_DURATION = 750L
|
||||||
|
}
|
||||||
|
|
||||||
|
var cycleDuration: Long = ICON_ANIMATION_DURATION
|
||||||
|
set(value) {
|
||||||
|
firstAnimator.duration = value / 5
|
||||||
|
secondAnimator.duration = value / 5
|
||||||
|
thirdAnimator.duration = value / 5
|
||||||
|
fourthAnimator.duration = value / 5
|
||||||
|
fifthAnimator.duration = value / 5
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var seconds: Int = 0
|
||||||
|
set(value) {
|
||||||
|
binding.tvSeconds.text =
|
||||||
|
context.resources.getQuantityString(R.plurals.fmt_seconds, value, value)
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done as a field so that we don't have to compute on each tab if animations are enabled
|
||||||
|
private val animationsEnabled =
|
||||||
|
Settings.System.getFloat(
|
||||||
|
context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1F) != 0F
|
||||||
|
|
||||||
|
val binding = PlayerFastSeekSecondsViewBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
|
||||||
|
init {
|
||||||
|
orientation = VERTICAL
|
||||||
|
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setForwarding(isForward: Boolean) {
|
||||||
|
binding.triangleContainer.rotation = if (isForward) 0f else 180f
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startAnimation() {
|
||||||
|
stopAnimation()
|
||||||
|
|
||||||
|
if (animationsEnabled) {
|
||||||
|
firstAnimator.start()
|
||||||
|
} else {
|
||||||
|
// If no animations are enable show the arrow(s) without animation
|
||||||
|
showWithoutAnimation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopAnimation() {
|
||||||
|
firstAnimator.cancel()
|
||||||
|
secondAnimator.cancel()
|
||||||
|
thirdAnimator.cancel()
|
||||||
|
fourthAnimator.cancel()
|
||||||
|
fifthAnimator.cancel()
|
||||||
|
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reset() {
|
||||||
|
binding.icon1.alpha = 0f
|
||||||
|
binding.icon2.alpha = 0f
|
||||||
|
binding.icon3.alpha = 0f
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showWithoutAnimation() {
|
||||||
|
binding.icon1.alpha = 1f
|
||||||
|
binding.icon2.alpha = 1f
|
||||||
|
binding.icon3.alpha = 1f
|
||||||
|
}
|
||||||
|
|
||||||
|
private val firstAnimator: ValueAnimator =
|
||||||
|
CustomValueAnimator(
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 0f
|
||||||
|
binding.icon2.alpha = 0f
|
||||||
|
binding.icon3.alpha = 0f
|
||||||
|
},
|
||||||
|
{ binding.icon1.alpha = it },
|
||||||
|
{ secondAnimator.start() })
|
||||||
|
|
||||||
|
private val secondAnimator: ValueAnimator =
|
||||||
|
CustomValueAnimator(
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 1f
|
||||||
|
binding.icon2.alpha = 0f
|
||||||
|
binding.icon3.alpha = 0f
|
||||||
|
},
|
||||||
|
{ binding.icon2.alpha = it },
|
||||||
|
{ thirdAnimator.start() })
|
||||||
|
|
||||||
|
private val thirdAnimator: ValueAnimator =
|
||||||
|
CustomValueAnimator(
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 1f
|
||||||
|
binding.icon2.alpha = 1f
|
||||||
|
binding.icon3.alpha = 0f
|
||||||
|
},
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 1f - binding.icon3.alpha
|
||||||
|
binding.icon3.alpha = it
|
||||||
|
},
|
||||||
|
{ fourthAnimator.start() })
|
||||||
|
|
||||||
|
private val fourthAnimator: ValueAnimator =
|
||||||
|
CustomValueAnimator(
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 0f
|
||||||
|
binding.icon2.alpha = 1f
|
||||||
|
binding.icon3.alpha = 1f
|
||||||
|
},
|
||||||
|
{ binding.icon2.alpha = 1f - it },
|
||||||
|
{ fifthAnimator.start() })
|
||||||
|
|
||||||
|
private val fifthAnimator: ValueAnimator =
|
||||||
|
CustomValueAnimator(
|
||||||
|
{
|
||||||
|
binding.icon1.alpha = 0f
|
||||||
|
binding.icon2.alpha = 0f
|
||||||
|
binding.icon3.alpha = 1f
|
||||||
|
},
|
||||||
|
{ binding.icon3.alpha = 1f - it },
|
||||||
|
{ firstAnimator.start() })
|
||||||
|
|
||||||
|
private inner class CustomValueAnimator(
|
||||||
|
start: () -> Unit,
|
||||||
|
update: (value: Float) -> Unit,
|
||||||
|
end: () -> Unit
|
||||||
|
) : ValueAnimator() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
duration = cycleDuration / 5
|
||||||
|
setFloatValues(0f, 1f)
|
||||||
|
|
||||||
|
addUpdateListener { update(it.animatedValue as Float) }
|
||||||
|
addListener(onStart = { start() }, onEnd = { end() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="16dp"
|
||||||
|
android:height="20dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:pathData="M3,2 L22,12 L3,22 Z" />
|
||||||
|
</vector>
|
||||||
@@ -32,6 +32,16 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/playback_toolbar"
|
app:layout_constraintTop_toBottomOf="@+id/playback_toolbar"
|
||||||
app:layout_constraintVertical_chainStyle="packed" />
|
app:layout_constraintVertical_chainStyle="packed" />
|
||||||
|
|
||||||
|
<org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
|
||||||
|
android:id="@+id/playback_fast_seek_overlay"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/playback_info_container"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/playback_toolbar"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/playback_info_container"
|
android:id="@+id/playback_info_container"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/root_constraint_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<org.oxycblt.auxio.playback.ui.stepper.CircleClipTapView
|
||||||
|
android:id="@+id/circle_clip_tap_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false" />
|
||||||
|
|
||||||
|
<org.oxycblt.auxio.playback.ui.stepper.SecondsView
|
||||||
|
android:id="@+id/seconds_view"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintWidth_default="percent"
|
||||||
|
app:layout_constraintWidth_percent="0.5" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:layout_height="wrap_content"
|
||||||
|
tools:layout_width="match_parent"
|
||||||
|
tools:orientation="vertical"
|
||||||
|
tools:parentTag="android.widget.LinearLayout">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/triangle_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/icon_1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_play_seek_triangle"
|
||||||
|
tools:alpha="0.18" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/icon_2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_play_seek_triangle"
|
||||||
|
tools:alpha="0.5" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/icon_3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_play_seek_triangle"
|
||||||
|
tools:alpha="1" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_seconds"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp"
|
||||||
|
tools:text="20 seconds" />
|
||||||
|
|
||||||
|
</merge>
|
||||||
@@ -485,4 +485,9 @@
|
|||||||
<item quantity="one">%d artist</item>
|
<item quantity="one">%d artist</item>
|
||||||
<item quantity="other">%d artists</item>
|
<item quantity="other">%d artists</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<plurals name="fmt_seconds">
|
||||||
|
<item quantity="one">%d second</item>
|
||||||
|
<item quantity="other">%d seconds</item>
|
||||||
|
</plurals>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user