rewrite double tap forward/rewind UI

This commit is contained in:
Bnyro 2022-07-18 16:55:48 +02:00
parent 599eafddf2
commit e48da1109a
5 changed files with 125 additions and 51 deletions

View File

@ -250,7 +250,7 @@ class PlayerFragment : Fragment() {
playbackSpeed = PreferenceHelper.getString( playbackSpeed = PreferenceHelper.getString(
PreferenceKeys.PLAYBACK_SPEED, PreferenceKeys.PLAYBACK_SPEED,
"1" "1"
)!! )!!.replace("F", "") // due to old way to handle it (with float)
fullscreenOrientationPref = PreferenceHelper.getString( fullscreenOrientationPref = PreferenceHelper.getString(
PreferenceKeys.FULLSCREEN_ORIENTATION, PreferenceKeys.FULLSCREEN_ORIENTATION,
@ -1061,21 +1061,17 @@ class PlayerFragment : Fragment() {
} }
private fun enableDoubleTapToSeek() { private fun enableDoubleTapToSeek() {
val hideDoubleTapOverlayDelay = 700L // set seek increment text
val seekIncrementText = (seekIncrement / 1000).toString()
binding.rewindTV.text = seekIncrementText
binding.forwardTV.text = seekIncrementText
// enable rewind button // enable rewind button
val rewindGestureDetector = GestureDetector( val rewindGestureDetector = GestureDetector(
context, context,
object : SimpleOnGestureListener() { object : SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent): Boolean { override fun onDoubleTap(e: MotionEvent): Boolean {
exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) rewind()
// show the rewind button
binding.rewindBTN.apply {
visibility = View.VISIBLE
removeCallbacks(hideRewindButtonRunnable)
postDelayed(hideRewindButtonRunnable, hideDoubleTapOverlayDelay)
}
return super.onDoubleTap(e) return super.onDoubleTap(e)
} }
@ -1097,14 +1093,7 @@ class PlayerFragment : Fragment() {
context, context,
object : SimpleOnGestureListener() { object : SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent): Boolean { override fun onDoubleTap(e: MotionEvent): Boolean {
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) forward()
// show the forward button
binding.forwardBTN.apply {
visibility = View.VISIBLE
removeCallbacks(hideForwardButtonRunnable)
postDelayed(hideForwardButtonRunnable, hideDoubleTapOverlayDelay)
}
return super.onDoubleTap(e) return super.onDoubleTap(e)
} }
@ -1122,8 +1111,64 @@ class PlayerFragment : Fragment() {
} }
} }
private val hideForwardButtonRunnable = Runnable { binding.forwardBTN.visibility = View.GONE } private fun rewind() {
private val hideRewindButtonRunnable = Runnable { binding.rewindBTN.visibility = View.GONE } exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
// show the rewind button
binding.rewindBTN.apply {
visibility = View.VISIBLE
// clear previous animation
animate().rotation(0F).setDuration(0).start()
// start new animation
animate()
.rotation(-30F)
.setDuration(100)
.withEndAction {
// reset the animation when finished
animate().rotation(0F).setDuration(100).start()
}
.start()
removeCallbacks(hideRewindButtonRunnable)
// start callback to hide the button
postDelayed(hideRewindButtonRunnable, 700)
}
}
private fun forward() {
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
// show the forward button
binding.forwardBTN.apply {
visibility = View.VISIBLE
// clear previous animation
animate().rotation(0F).setDuration(0).start()
// start new animation
animate()
.rotation(30F)
.setDuration(100)
.withEndAction {
// reset the animation when finished
animate().rotation(0F).setDuration(100).start()
}
.start()
// start callback to hide the button
removeCallbacks(hideForwardButtonRunnable)
postDelayed(hideForwardButtonRunnable, 700)
}
}
private val hideForwardButtonRunnable = Runnable {
binding.forwardBTN.apply {
visibility = View.GONE
}
}
private val hideRewindButtonRunnable = Runnable {
binding.rewindBTN.apply {
visibility = View.GONE
}
}
// enable seek bar preview // enable seek bar preview
private fun enableSeekbarPreview() { private fun enableSeekbarPreview() {

View File

@ -1,10 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="40dp"
android:height="24dp" android:height="40dp"
android:tint="@android:color/white" android:tint="@android:color/white"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="@android:color/white" android:fillColor="@android:color/white"
android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z" /> android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8c4.42,0 8,-3.58 8,-8H18z" />
</vector> </vector>

View File

@ -1,10 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="40dp"
android:height="24dp" android:height="40dp"
android:tint="@android:color/white" android:tint="@android:color/white"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="@android:color/white" android:pathData="m6,13c0,3.31 2.69,6 6,6 3.31,0 6,-2.69 6,-6 0,-3.31 -2.69,-6 -6,-6v4L7,6 12,1v4c4.42,0 8,3.58 8,8 0,4.42 -3.58,8 -8,8 -4.42,0 -8,-3.58 -8,-8z"
android:pathData="M11,18L11,6l-8.5,6 8.5,6zM11.5,12l8.5,6L20,6l-8.5,6z" /> android:fillColor="@android:color/white"/>
</vector> </vector>

View File

@ -379,51 +379,80 @@
android:id="@+id/doubleTapOverlayLL" android:id="@+id/doubleTapOverlayLL"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="70dp" android:layout_marginVertical="65dp">
android:layout_marginBottom="60dp">
<!-- double tap rewind btn --> <!-- double tap rewind btn -->
<FrameLayout <FrameLayout
android:id="@+id/rewindFL" android:id="@+id/rewindFL"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight=".35"> android:layout_weight=".40">
<ImageButton <FrameLayout
android:id="@+id/rewindBTN" android:id="@+id/rewindBTN"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless" android:layout_gravity="center"
android:clickable="false" android:layout_marginStart="30dp"
android:visibility="invisible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_rewind" android:src="@drawable/ic_rewind"
android:visibility="invisible"
app:tint="@android:color/white" /> app:tint="@android:color/white" />
<TextView
android:id="@+id/rewindTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="@android:color/white"
android:textSize="11sp" />
</FrameLayout>
</FrameLayout> </FrameLayout>
<!-- place holder for the center controls --> <!-- place holder for the center controls -->
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight=".30" /> android:layout_weight=".20" />
<!-- double tap forward btn --> <!-- double tap forward btn -->
<FrameLayout <FrameLayout
android:id="@+id/forwardFL" android:id="@+id/forwardFL"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight=".35"> android:layout_weight=".40">
<ImageButton <FrameLayout
android:id="@+id/forwardBTN" android:id="@+id/forwardBTN"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless" android:layout_gravity="center"
android:clickable="false" android:layout_marginEnd="30dp"
android:visibility="invisible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_forward" android:src="@drawable/ic_forward"
android:visibility="invisible"
app:tint="@android:color/white" /> app:tint="@android:color/white" />
<TextView
android:id="@+id/forwardTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="@android:color/white"
android:textSize="11sp" />
</FrameLayout>
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>