Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't seek after scrubbing when stopping gesture above timebar #5700

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class OfflinePlayerActivity : BaseActivity() {
super.onPlaybackStateChanged(playbackState)
// setup seekbar preview
if (playbackState == Player.STATE_READY) {
binding.player.binding.exoProgress.addListener(
binding.player.binding.exoProgress.addSeekBarListener(
SeekbarPreviewListener(
timeFrameReceiver ?: return,
binding.player.binding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
player = exoPlayer
}

playerBinding.exoProgress.setPlayer(exoPlayer)

initializePlayerView()

// don't continue playback when the fragment is re-created after Android killed it
Expand Down Expand Up @@ -1095,7 +1093,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.seekbarPreview.isGone = true
seekBarPreviewListener?.let { playerBinding.exoProgress.removeListener(it) }
seekBarPreviewListener = createSeekbarPreviewListener().also {
playerBinding.exoProgress.addListener(it)
playerBinding.exoProgress.addSeekBarListener(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@
}
})

player?.let { binding.exoProgress.setPlayer(it) }
// prevent the controls from disappearing while scrubbing the time bar
binding.exoProgress.addListener(object : TimeBar.OnScrubListener {
binding.exoProgress.addSeekBarListener(object : TimeBar.OnScrubListener {

Check failure on line 187 in app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt:187:48: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
override fun onScrubStart(timeBar: TimeBar, position: Long) {
cancelHideControllerTask()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.libretube.ui.views

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.DefaultTimeBar
import androidx.media3.ui.PlayerControlView
import androidx.media3.ui.TimeBar
import androidx.media3.ui.TimeBar.OnScrubListener
import com.github.libretube.extensions.dpToPx

@UnstableApi
open class DismissableTimeBar(
context: Context,
attributeSet: AttributeSet? = null

Check failure on line 18 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:18:39: error: Missing trailing comma before ")" (standard:trailing-comma-on-declaration-site)
): DefaultTimeBar(context, attributeSet) {

Check failure on line 19 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing spacing before ":" Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:19:2: error: Missing spacing before ":" (standard:colon-spacing)
private var shouldAddListener = false
var exoPlayer: Player? = null
private var lastYPosition = 0f

init {
addSeekBarListener(object : OnScrubListener {

Check failure on line 25 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:25:28: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
override fun onScrubStart(timeBar: TimeBar, position: Long) = Unit

Check failure on line 26 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected after opening parenthesis Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:26:39: error: Newline expected after opening parenthesis (standard:function-signature)

Check failure on line 26 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:26:57: error: Parameter should start on a newline (standard:function-signature)

Check failure on line 26 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected before closing parenthesis Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:26:71: error: Newline expected before closing parenthesis (standard:function-signature)

override fun onScrubMove(timeBar: TimeBar, position: Long) = Unit

Check failure on line 28 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected after opening parenthesis Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:28:38: error: Newline expected after opening parenthesis (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/ui/views/DismissableTimeBar.kt:28:56: error: Parameter should start on a newline (standard:function-signature)

override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) {
if (lastYPosition > MINIMUM_ACCEPTED_HEIGHT.dpToPx()) exoPlayer?.seekTo(position)
}
})
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
lastYPosition = event.y

return super.onTouchEvent(event)
}

/**
* DO NOT CALL THIS METHOD DIRECTLY. Use [addSeekBarListener] instead!
*/
override fun addListener(listener: OnScrubListener) {
if (shouldAddListener) super.addListener(listener)
}

/**
* Wrapper to circumvent adding the listener created by [PlayerControlView]
*/
fun addSeekBarListener(listener: OnScrubListener) {
shouldAddListener = true
addListener(listener)
shouldAddListener = false
}

fun setPlayer(player: Player) {
this.exoPlayer = player
}

companion object {
private const val MINIMUM_ACCEPTED_HEIGHT = -70f
}
}
14 changes: 3 additions & 11 deletions app/src/main/java/com/github/libretube/ui/views/MarkableTimeBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import androidx.core.view.marginLeft
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.DefaultTimeBar
import com.github.libretube.api.obj.Segment
import com.github.libretube.extensions.dpToPx
import com.github.libretube.helpers.PreferenceHelper
Expand All @@ -23,10 +21,8 @@ import com.google.android.material.R
class MarkableTimeBar(
context: Context,
attributeSet: AttributeSet? = null
) : DefaultTimeBar(context, attributeSet) {

) : DismissableTimeBar(context, attributeSet) {
private var segments = listOf<Segment>()
private var player: Player? = null
private var length: Int = 0

private val progressBarHeight = 2f.dpToPx()
Expand All @@ -37,7 +33,7 @@ class MarkableTimeBar(
}

private fun drawSegments(canvas: Canvas) {
if (player == null) return
if (exoPlayer == null) return

canvas.save()
val horizontalOffset = (parent as View).marginLeft
Expand Down Expand Up @@ -68,7 +64,7 @@ class MarkableTimeBar(
}

private fun Float.toLength(): Int {
return (this * 1000 / player!!.duration * length).toInt()
return (this * 1000 / exoPlayer!!.duration * length).toInt()
}

fun setSegments(segments: List<Segment>) {
Expand All @@ -78,8 +74,4 @@ class MarkableTimeBar(
fun clearSegments() {
segments = listOf()
}

fun setPlayer(player: Player) {
this.player = player
}
}
Loading