Merge pull request #736 from Bnyro/master

small double tap fixes
This commit is contained in:
Bnyro 2022-07-09 18:28:25 +02:00 committed by GitHub
commit 5f702da866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 43 deletions

View File

@ -340,9 +340,7 @@ class PlayerFragment : Fragment() {
val fullscreenOrientationPref = PreferenceHelper val fullscreenOrientationPref = PreferenceHelper
.getString(requireContext(), "fullscreen_orientation", "ratio") .getString(requireContext(), "fullscreen_orientation", "ratio")
val scaleFactor = 1.3F scaleControls(1.3F)
playerBinding.exoPlayPause.scaleX = scaleFactor
playerBinding.exoPlayPause.scaleY = scaleFactor
val orientation = when (fullscreenOrientationPref) { val orientation = when (fullscreenOrientationPref) {
"ratio" -> { "ratio" -> {
@ -375,9 +373,7 @@ class PlayerFragment : Fragment() {
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE playerBinding.exoTitle.visibility = View.INVISIBLE
val scaleFactor = 1F scaleControls(1F)
playerBinding.exoPlayPause.scaleX = scaleFactor
playerBinding.exoPlayPause.scaleY = scaleFactor
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
@ -385,6 +381,11 @@ class PlayerFragment : Fragment() {
isFullScreen = false isFullScreen = false
} }
private fun scaleControls(scaleFactor: Float) {
playerBinding.exoPlayPause.scaleX = scaleFactor
playerBinding.exoPlayPause.scaleY = scaleFactor
}
private fun toggleComments() { private fun toggleComments() {
binding.commentsRecView.visibility = binding.commentsRecView.visibility =
if (binding.commentsRecView.isVisible) View.GONE else View.VISIBLE if (binding.commentsRecView.isVisible) View.GONE else View.VISIBLE
@ -903,6 +904,12 @@ class PlayerFragment : Fragment() {
) )
} }
private fun disableDoubleTapToSeek() {
// disable fast forward and rewind by double tapping
binding.forwardFL.visibility = View.GONE
binding.rewindFL.visibility = View.GONE
}
// toggle the visibility of the player controller // toggle the visibility of the player controller
private fun toggleController() { private fun toggleController() {
if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController()
@ -1147,11 +1154,15 @@ class PlayerFragment : Fragment() {
private fun lockPlayer(isLocked: Boolean) { private fun lockPlayer(isLocked: Boolean) {
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.exoBottomBar.visibility = visibility playerBinding.exoBottomBar.visibility = visibility
playerBinding.closeImageButton.visibility = visibility playerBinding.closeImageButton.visibility = visibility
playerBinding.exoTitle.visibility = visibility playerBinding.exoTitle.visibility = visibility
// disable double tap to seek when the player is locked
if (isLocked) enableDoubleTapToSeek() else disableDoubleTapToSeek()
} }
private fun isSubscribed(button: MaterialButton, channel_id: String) { private fun isSubscribed(button: MaterialButton, channel_id: String) {
@ -1305,28 +1316,29 @@ class PlayerFragment : Fragment() {
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode) super.onPictureInPictureModeChanged(isInPictureInPictureMode)
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
// hide and disable exoPlayer controls
exoPlayerView.hideController() exoPlayerView.hideController()
exoPlayerView.useController = false exoPlayerView.useController = false
// hide anything but the player
binding.linLayout.visibility = View.GONE binding.linLayout.visibility = View.GONE
binding.mainContainer.isClickable = true
with(binding.playerMotionLayout) { with(binding.playerMotionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1) getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
enableTransition(R.id.yt_transition, false) enableTransition(R.id.yt_transition, false)
} }
binding.mainContainer.isClickable = true
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
isFullScreen = false isFullScreen = false
} else { } else {
with(binding.playerMotionLayout) { // enable exoPlayer controls again
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
enableTransition(R.id.yt_transition, true)
}
exoPlayerView.useController = true exoPlayerView.useController = true
binding.linLayout.visibility = View.VISIBLE
binding.mainContainer.isClickable = false // switch back to portrait mode
unsetFullscreen()
} }
} }

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layoutDescription="@xml/activity_main_scene" app:layoutDescription="@xml/activity_main_scene"
tools:context=".MainActivity"> tools:context=".activities.MainActivity">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"

View File

@ -363,43 +363,58 @@
app:layout_constraintTop_toTopOf="@id/main_container" app:layout_constraintTop_toTopOf="@id/main_container"
app:show_buffering="when_playing"> app:show_buffering="when_playing">
<FrameLayout <!-- double tap to rewind/forward overlay -->
android:id="@+id/forwardFL" <LinearLayout
android:layout_width="wrap_content" android:id="@+id/doubleTapOverlayLL"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:layout_marginVertical="50dp"> android:layout_marginVertical="50dp">
<ImageButton <!-- double tap rewind btn -->
android:id="@+id/forwardBTN" <FrameLayout
android:layout_width="150dp" android:id="@+id/rewindFL"
android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless" android:layout_weight=".40">
android:clickable="false"
android:src="@drawable/ic_forward"
android:visibility="invisible"
app:tint="@android:color/white" />
</FrameLayout> <ImageButton
android:id="@+id/rewindBTN"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless"
android:clickable="false"
android:src="@drawable/ic_rewind"
android:visibility="invisible"
app:tint="@android:color/white" />
<FrameLayout </FrameLayout>
android:id="@+id/rewindFL"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|start"
android:layout_marginVertical="50dp">
<ImageButton <!-- place holder for the center controls -->
android:id="@+id/rewindBTN" <LinearLayout
android:layout_width="150dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless" android:layout_weight=".20" />
android:clickable="false"
android:src="@drawable/ic_rewind"
android:visibility="invisible"
app:tint="@android:color/white" />
</FrameLayout> <!-- double tap forward btn -->
<FrameLayout
android:id="@+id/forwardFL"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40">
<ImageButton
android:id="@+id/forwardBTN"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless"
android:clickable="false"
android:src="@drawable/ic_forward"
android:visibility="invisible"
app:tint="@android:color/white" />
</FrameLayout>
</LinearLayout>
</com.github.libretube.views.CustomExoPlayerView> </com.github.libretube.views.CustomExoPlayerView>