diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 92f720ba5..f149862c1 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -38,7 +38,6 @@ import com.github.libretube.util.LocaleHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.ThemeHelper import com.google.android.material.color.DynamicColors -import com.google.android.material.color.MaterialColors import com.google.android.material.elevation.SurfaceColors class MainActivity : AppCompatActivity() { @@ -100,7 +99,7 @@ class MainActivity : AppCompatActivity() { navController = findNavController(R.id.fragment) binding.bottomNav.setupWithNavController(navController) - + // gets the surface color of the bottom navigation view val color = SurfaceColors.getColorForElevation(this, 10F) diff --git a/app/src/main/java/com/github/libretube/activities/Player.kt b/app/src/main/java/com/github/libretube/activities/Player.kt deleted file mode 100644 index aa0a3cbec..000000000 --- a/app/src/main/java/com/github/libretube/activities/Player.kt +++ /dev/null @@ -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) - } -} diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index dccc5a21c..6fb47e1fc 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -11,6 +11,8 @@ import android.net.Uri import android.os.Build import android.os.Build.VERSION.SDK_INT import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.os.PowerManager import android.support.v4.media.session.MediaSessionCompat import android.text.Html @@ -21,6 +23,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.constraintlayout.motion.widget.MotionLayout +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.core.view.isVisible @@ -54,6 +57,7 @@ import com.github.libretube.util.CronetHelper import com.github.libretube.util.DescriptionAdapter import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort +import com.github.libretube.views.DoubleClickListener import com.google.android.exoplayer2.C import com.google.android.exoplayer2.DefaultLoadControl import com.google.android.exoplayer2.ExoPlayer @@ -75,6 +79,7 @@ import com.google.android.exoplayer2.upstream.DataSource import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil +import com.google.android.exoplayer2.video.VideoSize import com.google.android.material.button.MaterialButton import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.picasso.Picasso @@ -319,10 +324,6 @@ class PlayerFragment : Fragment() { isFullScreen = !isFullScreen // 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.scaleY = scaleFactor } @@ -691,6 +692,8 @@ class PlayerFragment : Fragment() { playerBinding.exoTitle.text = response.title + enableDoubleTapToSeek() + // init the chapters recyclerview if (response.chapters != null) initializeChapters(response.chapters) @@ -705,7 +708,6 @@ class PlayerFragment : Fragment() { } } - /* override fun onVideoSizeChanged( videoSize: VideoSize ) { @@ -713,14 +715,14 @@ class PlayerFragment : Fragment() { // height or width must be cast to float as int/int will give 0 // Redraw the player container with the new layout height + val params = binding.player.layoutParams + params.height = videoSize.height / videoSize.width * params.width + binding.player.layoutParams = params + binding.player.requestLayout() (binding.mainContainer.layoutParams as ConstraintLayout.LayoutParams).apply { - matchConstraintPercentHeight = ( - videoSize.height / videoSize.width - ).toFloat() + matchConstraintPercentHeight = (videoSize.height / videoSize.width).toFloat() } - binding.mainContainer.requestLayout() } - */ @Deprecated(message = "Deprecated", level = DeprecationLevel.HIDDEN) override fun onPlayerStateChanged( @@ -844,6 +846,51 @@ class PlayerFragment : Fragment() { } } + private fun enableDoubleTapToSeek() { + val seekIncrement = + PreferenceHelper.getString(requireContext(), "seek_increment", "5")?.toLong()!! * 1000 + + // enable rewind button + binding.rewindFL.setOnClickListener( + DoubleClickListener( + callback = object : DoubleClickListener.Callback { + override fun doubleClicked() { + binding.rewindBTN.visibility = View.VISIBLE + exoPlayer.seekTo(exoPlayer.currentPosition - seekIncrement) + Handler(Looper.getMainLooper()).postDelayed({ + binding.rewindBTN.visibility = View.INVISIBLE + }, 700) + } + + override fun singleClicked() { + if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() + else exoPlayerView.showController() + } + } + ) + ) + + // enable fast forward button + binding.forwardFL.setOnClickListener( + DoubleClickListener( + callback = object : DoubleClickListener.Callback { + override fun doubleClicked() { + binding.forwardBTN.visibility = View.VISIBLE + exoPlayer.seekTo(exoPlayer.currentPosition + seekIncrement) + Handler(Looper.getMainLooper()).postDelayed({ + binding.forwardBTN.visibility = View.INVISIBLE + }, 700) + } + + override fun singleClicked() { + if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() + else exoPlayerView.showController() + } + } + ) + ) + } + private fun initializeChapters(chapters: List) { if (chapters.isNotEmpty()) { binding.chaptersRecView.layoutManager = @@ -1064,8 +1111,6 @@ class PlayerFragment : Fragment() { val visibility = if (isLocked) View.VISIBLE else View.GONE playerBinding.exoTopBarRight.visibility = visibility playerBinding.exoPlayPause.visibility = visibility - playerBinding.exoFfwdWithAmount.visibility = visibility - playerBinding.exoRewWithAmount.visibility = visibility playerBinding.exoBottomBar.visibility = visibility playerBinding.closeImageButton.visibility = visibility playerBinding.exoTitle.visibility = visibility diff --git a/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt b/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt new file mode 100644 index 000000000..f4de71793 --- /dev/null +++ b/app/src/main/java/com/github/libretube/views/DoubleClickListener.kt @@ -0,0 +1,49 @@ +package com.github.libretube.views + +import android.os.Handler +import android.os.Looper +import android.view.View + +class DoubleClickListener( + private val doubleClickTimeLimitMills: Long = 300, + private val callback: Callback +) : View.OnClickListener { + private var lastClicked: Long = -1L + private var doubleClicked: Boolean = false + + override fun onClick(v: View?) { + lastClicked = when { + lastClicked == -1L -> { + doubleClicked = false + System.currentTimeMillis() + } + isDoubleClicked() -> { + doubleClicked = true + callback.doubleClicked() + -1L + } + else -> { + Handler(Looper.getMainLooper()).postDelayed({ + if (!doubleClicked) callback.singleClicked() + }, doubleClickTimeLimitMills) + 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() + fun singleClicked() + } +} diff --git a/app/src/main/res/drawable/ic_forward.xml b/app/src/main/res/drawable/ic_forward.xml new file mode 100644 index 000000000..8108f0bc6 --- /dev/null +++ b/app/src/main/res/drawable/ic_forward.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_rewind.xml b/app/src/main/res/drawable/ic_rewind.xml new file mode 100644 index 000000000..54921898a --- /dev/null +++ b/app/src/main/res/drawable/ic_rewind.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml deleted file mode 100644 index 8075249cf..000000000 --- a/app/src/main/res/layout/activity_player.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index ddb5a8a18..059fb7020 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -1,26 +1,7 @@ - + - - - - -