mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
basic double tap implementation
This commit is contained in:
parent
dbea7652ee
commit
61721fd2df
@ -1,15 +0,0 @@
|
|||||||
package com.github.libretube.activities
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Bundle
|
|
||||||
import com.github.libretube.R
|
|
||||||
import com.google.android.material.color.DynamicColors
|
|
||||||
|
|
||||||
class Player : Activity() {
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
DynamicColors.applyToActivityIfAvailable(this)
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.activity_player)
|
|
||||||
}
|
|
||||||
}
|
|
@ -54,6 +54,7 @@ import com.github.libretube.util.CronetHelper
|
|||||||
import com.github.libretube.util.DescriptionAdapter
|
import com.github.libretube.util.DescriptionAdapter
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import com.github.libretube.util.formatShort
|
import com.github.libretube.util.formatShort
|
||||||
|
import com.github.libretube.views.DoubleClickListener
|
||||||
import com.google.android.exoplayer2.C
|
import com.google.android.exoplayer2.C
|
||||||
import com.google.android.exoplayer2.DefaultLoadControl
|
import com.google.android.exoplayer2.DefaultLoadControl
|
||||||
import com.google.android.exoplayer2.ExoPlayer
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
@ -319,10 +320,6 @@ class PlayerFragment : Fragment() {
|
|||||||
isFullScreen = !isFullScreen
|
isFullScreen = !isFullScreen
|
||||||
|
|
||||||
// scale the exo player center controls
|
// scale the exo player center controls
|
||||||
playerBinding.exoFfwdWithAmount.scaleX = scaleFactor
|
|
||||||
playerBinding.exoFfwdWithAmount.scaleY = scaleFactor
|
|
||||||
playerBinding.exoRewWithAmount.scaleX = scaleFactor
|
|
||||||
playerBinding.exoRewWithAmount.scaleY = scaleFactor
|
|
||||||
playerBinding.exoPlayPause.scaleX = scaleFactor
|
playerBinding.exoPlayPause.scaleX = scaleFactor
|
||||||
playerBinding.exoPlayPause.scaleY = scaleFactor
|
playerBinding.exoPlayPause.scaleY = scaleFactor
|
||||||
}
|
}
|
||||||
@ -691,6 +688,8 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
playerBinding.exoTitle.text = response.title
|
playerBinding.exoTitle.text = response.title
|
||||||
|
|
||||||
|
enableDoubleTapToSeek()
|
||||||
|
|
||||||
// init the chapters recyclerview
|
// init the chapters recyclerview
|
||||||
if (response.chapters != null) initializeChapters(response.chapters)
|
if (response.chapters != null) initializeChapters(response.chapters)
|
||||||
|
|
||||||
@ -844,6 +843,31 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun enableDoubleTapToSeek() {
|
||||||
|
val seekIncrement =
|
||||||
|
PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000
|
||||||
|
|
||||||
|
playerBinding.rewindFL.setOnClickListener(
|
||||||
|
DoubleClickListener(
|
||||||
|
callback = object : DoubleClickListener.Callback {
|
||||||
|
override fun doubleClicked() {
|
||||||
|
exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
playerBinding.forwardFL.setOnClickListener(
|
||||||
|
DoubleClickListener(
|
||||||
|
callback = object : DoubleClickListener.Callback {
|
||||||
|
override fun doubleClicked() {
|
||||||
|
exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
||||||
if (chapters.isNotEmpty()) {
|
if (chapters.isNotEmpty()) {
|
||||||
binding.chaptersRecView.layoutManager =
|
binding.chaptersRecView.layoutManager =
|
||||||
@ -1064,8 +1088,6 @@ class PlayerFragment : Fragment() {
|
|||||||
val visibility = if (isLocked) View.VISIBLE else View.GONE
|
val visibility = if (isLocked) View.VISIBLE else View.GONE
|
||||||
playerBinding.exoTopBarRight.visibility = visibility
|
playerBinding.exoTopBarRight.visibility = visibility
|
||||||
playerBinding.exoPlayPause.visibility = visibility
|
playerBinding.exoPlayPause.visibility = visibility
|
||||||
playerBinding.exoFfwdWithAmount.visibility = visibility
|
|
||||||
playerBinding.exoRewWithAmount.visibility = visibility
|
|
||||||
playerBinding.exoBottomBar.visibility = visibility
|
playerBinding.exoBottomBar.visibility = visibility
|
||||||
playerBinding.closeImageButton.visibility = visibility
|
playerBinding.closeImageButton.visibility = visibility
|
||||||
playerBinding.exoTitle.visibility = visibility
|
playerBinding.exoTitle.visibility = visibility
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.github.libretube.views
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
class DoubleClickListener(private val doubleClickTimeLimitMills: Long = 500, private val callback: Callback) : View.OnClickListener {
|
||||||
|
private var lastClicked: Long = -1L
|
||||||
|
|
||||||
|
override fun onClick(v: View?) {
|
||||||
|
lastClicked = when {
|
||||||
|
lastClicked == -1L -> {
|
||||||
|
System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
isDoubleClicked() -> {
|
||||||
|
callback.doubleClicked()
|
||||||
|
-1L
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTimeDiff(from: Long, to: Long): Long {
|
||||||
|
return to - from
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isDoubleClicked(): Boolean {
|
||||||
|
return getTimeDiff(
|
||||||
|
lastClicked,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
) <= doubleClickTimeLimitMills
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
fun doubleClicked()
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@android:color/black"
|
|
||||||
tools:context=".activities.Player">
|
|
||||||
|
|
||||||
<com.github.libretube.views.CustomExoPlayerView
|
|
||||||
android:id="@+id/fullscreen_player"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="@android:color/black" />
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
@ -1,26 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright 2020 The Android Open Source Project
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<!-- 0dp dimensions are used to prevent this view from influencing the size of
|
|
||||||
the parent view if it uses "wrap_content". It is expanded to occupy the
|
|
||||||
entirety of the parent in code, after the parent's size has been
|
|
||||||
determined. See: https://github.com/google/ExoPlayer/issues/8726.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@id/exo_controls_background"
|
android:id="@id/exo_controls_background"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -231,42 +212,47 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="@dimen/exo_styled_controls_padding">
|
android:padding="@dimen/exo_styled_controls_padding">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="0dp"
|
android:id="@+id/rewindFL"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<Button
|
<ImageButton
|
||||||
android:id="@id/exo_rew_with_amount"
|
android:id="@+id/rewindBTN"
|
||||||
style="@style/ExoStyledControls.Button.Center.RewWithAmount"
|
android:layout_width="150dp"
|
||||||
android:layout_gravity="center"
|
android:layout_height="200dp"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_gravity="center_vertical"
|
||||||
android:paddingLeft="4dp"
|
android:background="?android:selectableItemBackground"
|
||||||
android:paddingRight="4dp" />
|
android:src="@drawable/ic_three_dots"
|
||||||
|
android:clickable="false"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@id/exo_play_pause"
|
android:id="@id/exo_play_pause"
|
||||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||||
app:tint="@android:color/white" />
|
app:tint="@android:color/white" />
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="0dp"
|
android:id="@+id/forwardFL"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<Button
|
<ImageButton
|
||||||
android:id="@id/exo_ffwd_with_amount"
|
android:id="@+id/forwardBTN"
|
||||||
style="@style/ExoStyledControls.Button.Center.FfwdWithAmount"
|
android:layout_width="150dp"
|
||||||
android:layout_gravity="center"
|
android:layout_height="200dp"
|
||||||
android:layout_marginEnd="20dp"
|
android:layout_gravity="center_vertical|end"
|
||||||
android:paddingLeft="4dp"
|
android:background="?android:selectableItemBackground"
|
||||||
android:paddingRight="4dp" />
|
android:src="@drawable/ic_three_dots"
|
||||||
|
android:clickable="false"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user