Skip to content

Commit c94bd6d

Browse files
committed
feat: allow seeking with single tap after first double click
1 parent 5b3c520 commit c94bd6d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

app/src/main/java/com/github/libretube/ui/listeners/PlayerGestureController.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.activity.viewModels
1313
import com.github.libretube.ui.base.BaseActivity
1414
import com.github.libretube.ui.interfaces.PlayerGestureOptions
1515
import com.github.libretube.ui.models.CommonPlayerViewModel
16+
import java.time.Instant
1617
import kotlin.math.abs
1718

1819
class PlayerGestureController(activity: BaseActivity, private val listener: PlayerGestureOptions) {
@@ -30,6 +31,7 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
3031
private var scaleGestureWasInProgress = false
3132
private var isMoving = false
3233
var longPressInProgress = false
34+
var lastDoublePressTime: Instant? = null
3335

3436
var areControlsLocked = false
3537

@@ -165,10 +167,29 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
165167
}
166168
}
167169

170+
lastDoublePressTime = Instant.now()
171+
168172
return true
169173
}
170174

171175
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
176+
// if there has been a recent double click within the threshold, single clicks
177+
// are being treated as a repetition of the double click
178+
// e.g. this allows to continue seeking forward using single clicks after double-clicking once
179+
lastDoublePressTime?.takeIf {
180+
val millisElapsedSinceDoubleClick = Instant.now().toEpochMilli() - it.toEpochMilli()
181+
millisElapsedSinceDoubleClick < DOUBLE_TAP_REPEAT_TIME_THRESHOLD_MILLIS
182+
}?.let {
183+
val upEvent = MotionEvent.obtain(e).apply {
184+
action = MotionEvent.ACTION_UP
185+
}
186+
onDoubleTapEvent(upEvent)
187+
upEvent.recycle()
188+
189+
lastDoublePressTime = Instant.now()
190+
return true
191+
}
192+
172193
listener.onSingleTap(false)
173194

174195
return true
@@ -219,5 +240,10 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
219240
private const val BORDER_THRESHOLD = 90
220241
private const val LEFT_AREA_VIEW_PERCENTAGE = 0.35f
221242
private const val RIGHT_AREA_VIEW_PERCENTAGE = 0.65f
243+
244+
/**
245+
* After a double click was processed, the user may use single clicks to trigger another double click.
246+
*/
247+
private const val DOUBLE_TAP_REPEAT_TIME_THRESHOLD_MILLIS = 700
222248
}
223249
}

0 commit comments

Comments
 (0)