diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt index 693b94a40..0105f8a85 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackPanelFragment.kt @@ -40,6 +40,8 @@ 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.stepper.DisplayPortion +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.showToast @@ -61,8 +63,8 @@ class PlaybackPanelFragment : ViewBindingFragment(), Toolbar.OnMenuItemClickListener, StyledSeekBar.Listener, - ControlledCoverView.OnSwipeListener, - ViewTreeObserver.OnGlobalLayoutListener { + ViewTreeObserver.OnGlobalLayoutListener, + PlayerFastSeekOverlay.PerformListener { private val playbackModel: PlaybackViewModel by activityViewModels() private val detailModel: DetailViewModel by activityViewModels() private val listModel: ListViewModel by activityViewModels() @@ -97,7 +99,14 @@ class 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 { isSelected = true setOnClickListener { navigateToCurrentSong() } @@ -205,21 +214,6 @@ class PlaybackPanelFragment : 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?) { if (song == null) { @@ -274,4 +268,31 @@ class PlaybackPanelFragment : private fun navigateToCurrentAlbum() { 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() + } + } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/CircleClipTapView.kt b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/CircleClipTapView.kt new file mode 100644 index 000000000..f307a15e7 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/CircleClipTapView.kt @@ -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 . + */ + +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) + } +} diff --git a/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/PlayerFastSeekOverlay.kt b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/PlayerFastSeekOverlay.kt new file mode 100644 index 000000000..a109030c7 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/PlayerFastSeekOverlay.kt @@ -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 . + */ + +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 + } +} diff --git a/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/SecondsView.kt b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/SecondsView.kt new file mode 100644 index 000000000..e81d319df --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/playback/ui/stepper/SecondsView.kt @@ -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 . + */ + +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() }) + } + } +} diff --git a/app/src/main/res/drawable/ic_play_seek_triangle.xml b/app/src/main/res/drawable/ic_play_seek_triangle.xml new file mode 100644 index 000000000..72a07009e --- /dev/null +++ b/app/src/main/res/drawable/ic_play_seek_triangle.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-h480dp/fragment_playback_panel.xml b/app/src/main/res/layout-h480dp/fragment_playback_panel.xml index d4bc3100d..0322d43fe 100644 --- a/app/src/main/res/layout-h480dp/fragment_playback_panel.xml +++ b/app/src/main/res/layout-h480dp/fragment_playback_panel.xml @@ -32,6 +32,16 @@ app:layout_constraintTop_toBottomOf="@+id/playback_toolbar" app:layout_constraintVertical_chainStyle="packed" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/player_fast_seek_seconds_view.xml b/app/src/main/res/layout/player_fast_seek_seconds_view.xml new file mode 100644 index 000000000..b76161179 --- /dev/null +++ b/app/src/main/res/layout/player_fast_seek_seconds_view.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 71980c107..ad5f7308f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -485,4 +485,9 @@ %d artist %d artists + + + %d second + %d seconds +