Merge pull request #745 from Bnyro/master

improve player controls
This commit is contained in:
Bnyro 2022-07-10 14:09:22 +02:00 committed by GitHub
commit a6328533d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import android.app.PictureInPictureParams
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.graphics.Color
import android.graphics.Rect import android.graphics.Rect
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
@ -336,7 +337,7 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.GONE binding.linLayout.visibility = View.GONE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE playerBinding.exoTitle.visibility = View.VISIBLE
if (chapters.isNotEmpty()) playerBinding.chapterLL.visibility = View.VISIBLE playerBinding.chapterLL.isClickable = true
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
val fullscreenOrientationPref = PreferenceHelper val fullscreenOrientationPref = PreferenceHelper
@ -373,7 +374,7 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.VISIBLE binding.linLayout.visibility = View.VISIBLE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE playerBinding.exoTitle.visibility = View.INVISIBLE
playerBinding.chapterLL.visibility = View.INVISIBLE playerBinding.chapterLL.isClickable = false
scaleControls(1F) scaleControls(1F)
@ -685,7 +686,6 @@ class PlayerFragment : Fragment() {
setShowSubtitleButton(true) setShowSubtitleButton(true)
setShowNextButton(false) setShowNextButton(false)
setShowPreviousButton(false) setShowPreviousButton(false)
setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
// controllerShowTimeoutMs = 1500 // controllerShowTimeoutMs = 1500
controllerHideOnTouch = true controllerHideOnTouch = true
useController = false useController = false
@ -715,6 +715,8 @@ class PlayerFragment : Fragment() {
if (response.chapters != null) { if (response.chapters != null) {
chapters = response.chapters chapters = response.chapters
initializeChapters() initializeChapters()
// disabling chapterName click in portrait mode
playerBinding.chapterLL.isClickable = false
} }
// set default playback speed // set default playback speed
@ -806,6 +808,18 @@ class PlayerFragment : Fragment() {
} }
}) })
// repeat toggle button
playerBinding.repeatToggle.setOnClickListener {
if (exoPlayer.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL) {
// turn off repeat mode
exoPlayer.repeatMode = RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE
playerBinding.repeatToggle.setColorFilter(Color.GRAY)
} else {
exoPlayer.repeatMode = RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL
playerBinding.repeatToggle.setColorFilter(Color.WHITE)
}
}
// share button // share button
binding.relPlayerShare.setOnClickListener { binding.relPlayerShare.setOnClickListener {
val shareDialog = ShareDialog(videoId!!, false) val shareDialog = ShareDialog(videoId!!, false)
@ -976,11 +990,12 @@ class PlayerFragment : Fragment() {
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer) binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
binding.chaptersRecView.visibility = View.VISIBLE binding.chaptersRecView.visibility = View.VISIBLE
// enable chapters in the player // enable the chapters dialog in the player
val titles = mutableListOf<String>() val titles = mutableListOf<String>()
chapters.forEach { chapters.forEach {
titles += it.title!! titles += it.title!!
} }
playerBinding.chapterLL.visibility = View.VISIBLE
playerBinding.chapterLL.setOnClickListener { playerBinding.chapterLL.setOnClickListener {
MaterialAlertDialogBuilder(requireContext()) MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.chapters) .setTitle(R.string.chapters)
@ -1213,6 +1228,7 @@ class PlayerFragment : Fragment() {
} }
} }
// lock the player
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

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z" />
</vector>

View File

@ -75,7 +75,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp" android:layout_marginHorizontal="5dp"
android:background="#00FFFFFF" android:background="?attr/selectableItemBackground"
android:padding="@dimen/exo_icon_padding" android:padding="@dimen/exo_icon_padding"
android:src="@drawable/ic_aspect_ratio" /> android:src="@drawable/ic_aspect_ratio" />
@ -83,8 +83,9 @@
android:id="@+id/speed_text" android:id="@+id/speed_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/exo_icon_padding" android:padding="@dimen/exo_icon_padding"
android:text="1x" android:text="1x"
android:textColor="#FFFFFF" /> android:textColor="#FFFFFF" />
@ -93,8 +94,9 @@
android:id="@+id/quality_text" android:id="@+id/quality_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginHorizontal="5dp"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/exo_icon_padding" android:padding="@dimen/exo_icon_padding"
android:text="@string/hls" android:text="@string/hls"
android:textColor="#FFFFFF" /> android:textColor="#FFFFFF" />
@ -114,7 +116,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="-10dp" android:layout_marginBottom="-5dp"
android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding" android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding" android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding" android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding"
@ -125,7 +127,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginLeft="5dp"> android:layout_marginStart="5dp">
<TextView <TextView
android:id="@id/exo_position" android:id="@id/exo_position"
@ -162,7 +164,6 @@
android:layout_height="15dp" android:layout_height="15dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginStart="3dp" android:layout_marginStart="3dp"
android:layout_marginTop="2dp"
android:src="@drawable/ic_arrow_right" /> android:src="@drawable/ic_arrow_right" />
</LinearLayout> </LinearLayout>
@ -173,16 +174,18 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageButton <ImageButton
android:id="@id/exo_repeat_toggle" android:id="@+id/repeat_toggle"
style="@style/ExoStyledControls.Button.Bottom.RepeatToggle" /> style="@style/PlayerButton"
android:src="@drawable/ic_repeat"
app:tint="@android:color/darker_gray"/>
<ImageButton <ImageButton
android:id="@id/exo_subtitle" android:id="@id/exo_subtitle"
style="@style/ExoStyledControls.Button.Bottom.CC" /> style="@style/PlayerButton" />
<ImageButton <ImageButton
android:id="@+id/fullscreen" android:id="@+id/fullscreen"
style="@style/ExoStyledControls.Button.Bottom.FullScreen" style="@style/PlayerButton"
android:src="@drawable/ic_fullscreen" android:src="@drawable/ic_fullscreen"
app:tint="@android:color/white" /> app:tint="@android:color/white" />

View File

@ -49,7 +49,7 @@
android:id="@+id/player_description_arrow" android:id="@+id/player_description_arrow"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
@ -73,7 +73,7 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="3dp" android:layout_marginStart="3dp"
android:layout_marginTop="2dp"> android:layout_marginTop="2dp">
<ImageView <ImageView
@ -93,7 +93,7 @@
android:layout_width="12dp" android:layout_width="12dp"
android:layout_height="12dp" android:layout_height="12dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginLeft="5dp" android:layout_marginStart="5dp"
android:rotation="180" android:rotation="180"
android:src="@drawable/ic_like" /> android:src="@drawable/ic_like" />
@ -119,7 +119,6 @@
android:id="@+id/chapters_recView" android:id="@+id/chapters_recView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/comments_toggle"
android:layout_marginHorizontal="3dp" android:layout_marginHorizontal="3dp"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:nestedScrollingEnabled="false" android:nestedScrollingEnabled="false"
@ -245,7 +244,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginLeft="5dp" android:layout_marginStart="5dp"
android:layout_toStartOf="@+id/player_subscribe" android:layout_toStartOf="@+id/player_subscribe"
android:layout_toEndOf="@+id/player_channelImage" android:layout_toEndOf="@+id/player_channelImage"
android:ellipsize="end" android:ellipsize="end"
@ -297,7 +296,7 @@
android:id="@+id/commentsToggle_textView" android:id="@+id/commentsToggle_textView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp"
android:text="@string/comments" android:text="@string/comments"
android:textSize="17sp" android:textSize="17sp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -307,7 +306,7 @@
android:id="@+id/commentsToggle_imageView" android:id="@+id/commentsToggle_imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="3dp" android:layout_marginEnd="3dp"
android:src="@drawable/ic_arrow_up_down" android:src="@drawable/ic_arrow_up_down"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View File

@ -114,4 +114,14 @@
</style> </style>
<style name="PlayerButton">
<item name="android:padding">6dp</item>
<item name="android:layout_height">36dp</item>
<item name="android:layout_width">36dp</item>
<item name="android:layout_gravity">center</item>
<item name="android:background">?attr/selectableItemBackground</item>
</style>
</resources> </resources>