toggle autoplay while playing video

This commit is contained in:
Bnyro 2022-07-27 11:57:04 +02:00
parent 05ad4363ff
commit c9740a2d5f
13 changed files with 111 additions and 38 deletions

View File

@ -284,7 +284,8 @@
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" />
<service android:name=".services.BackgroundMode" <service
android:name=".services.BackgroundMode"
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" />
</application> </application>

View File

@ -31,7 +31,8 @@ class ChaptersAdapter(
if (selectedPosition == position) { if (selectedPosition == position) {
// get the color for highlighted controls // get the color for highlighted controls
val color = ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight) val color =
ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight)
chapterLL.setBackgroundColor(color) chapterLL.setBackgroundColor(color)
} else chapterLL.setBackgroundColor(Color.TRANSPARENT) } else chapterLL.setBackgroundColor(Color.TRANSPARENT)
root.setOnClickListener { root.setOnClickListener {

View File

@ -202,6 +202,7 @@ class PlayerFragment : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
binding = FragmentPlayerBinding.inflate(layoutInflater, container, false) binding = FragmentPlayerBinding.inflate(layoutInflater, container, false)
exoPlayerView = binding.player
playerBinding = binding.player.binding playerBinding = binding.player.binding
doubleTapOverlayBinding = binding.doubleTapOverlay.binding doubleTapOverlayBinding = binding.doubleTapOverlay.binding
@ -215,6 +216,8 @@ class PlayerFragment : Fragment() {
setUserPrefs() setUserPrefs()
if (autoplayEnabled == true) playerBinding.autoplayIV.setImageResource(R.drawable.ic_toggle_on)
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
if (autoRotationEnabled) { if (autoRotationEnabled) {
// enable auto rotation // enable auto rotation
@ -345,8 +348,6 @@ class PlayerFragment : Fragment() {
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
mainActivity.binding.container.visibility = View.VISIBLE mainActivity.binding.container.visibility = View.VISIBLE
exoPlayerView = binding.player
binding.playerMotionLayout.addTransitionListener(object : MotionLayout.TransitionListener { binding.playerMotionLayout.addTransitionListener(object : MotionLayout.TransitionListener {
override fun onTransitionStarted( override fun onTransitionStarted(
motionLayout: MotionLayout?, motionLayout: MotionLayout?,
@ -427,6 +428,16 @@ class PlayerFragment : Fragment() {
playerBinding.advancedOptions.visibility = View.VISIBLE playerBinding.advancedOptions.visibility = View.VISIBLE
} }
} }
// autoplay toggle button
playerBinding.autoplayLL.setOnClickListener {
autoplayEnabled = if (autoplayEnabled) {
playerBinding.autoplayIV.setImageResource(R.drawable.ic_toggle_off)
false
} else {
playerBinding.autoplayIV.setImageResource(R.drawable.ic_toggle_on)
true
}
}
binding.playImageView.setOnClickListener { binding.playImageView.setOnClickListener {
if (!exoPlayer.isPlaying) { if (!exoPlayer.isPlaying) {
// start or go on playing // start or go on playing
@ -680,8 +691,9 @@ class PlayerFragment : Fragment() {
) as NotificationManager ) as NotificationManager
notificationManager.cancel(1) notificationManager.cancel(1)
exoPlayer.release() exoPlayer.release()
activity?.requestedOrientation = if ((activity as MainActivity).autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER activity?.requestedOrientation =
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT if ((activity as MainActivity).autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
} catch (e: Exception) { } catch (e: Exception) {
} }
} }

View File

@ -122,7 +122,10 @@ class PlaylistFragment : Fragment() {
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val response = try { val response = try {
// load locally stored playlists with the auth api // load locally stored playlists with the auth api
if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylistNextPage(playlistId!!, nextPage!!) if (isPipedPlaylist()) RetrofitInstance.authApi.getPlaylistNextPage(
playlistId!!,
nextPage!!
)
RetrofitInstance.api.getPlaylistNextPage(playlistId!!, nextPage!!) RetrofitInstance.api.getPlaylistNextPage(playlistId!!, nextPage!!)
} catch (e: IOException) { } catch (e: IOException) {
println(e) println(e)

View File

@ -65,10 +65,12 @@ class AppearanceSettings : PreferenceFragmentCompat() {
true true
} }
val systemCaptionStyle = findPreference<SwitchPreferenceCompat>(PreferenceKeys.SYSTEM_CAPTION_STYLE) val systemCaptionStyle =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.SYSTEM_CAPTION_STYLE)
val captionSettings = findPreference<Preference>(PreferenceKeys.CAPTION_SETTINGS) val captionSettings = findPreference<Preference>(PreferenceKeys.CAPTION_SETTINGS)
captionSettings?.isVisible = PreferenceHelper.getBoolean(PreferenceKeys.SYSTEM_CAPTION_STYLE, true) captionSettings?.isVisible =
PreferenceHelper.getBoolean(PreferenceKeys.SYSTEM_CAPTION_STYLE, true)
systemCaptionStyle?.setOnPreferenceChangeListener { _, newValue -> systemCaptionStyle?.setOnPreferenceChangeListener { _, newValue ->
captionSettings?.isVisible = newValue as Boolean captionSettings?.isVisible = newValue as Boolean
true true

View File

@ -264,7 +264,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
val token = PreferenceHelper.getToken() val token = PreferenceHelper.getToken()
if (token != "") { if (token != "") {
// check StorageAccess // check StorageAccess
val accessGranted = PermissionHelper.isStoragePermissionGranted(activity as AppCompatActivity) val accessGranted =
PermissionHelper.isStoragePermissionGranted(activity as AppCompatActivity)
if (accessGranted) getContent.launch("*/*") if (accessGranted) getContent.launch("*/*")
else PermissionHelper.requestReadWrite(activity as AppCompatActivity) else PermissionHelper.requestReadWrite(activity as AppCompatActivity)
} else { } else {

View File

@ -8,7 +8,6 @@ import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity import com.github.libretube.activities.SettingsActivity
import java.util.* import java.util.*
import kotlin.collections.ArrayList
class PlayerSettings : PreferenceFragmentCompat() { class PlayerSettings : PreferenceFragmentCompat() {
val TAG = "PlayerSettings" val TAG = "PlayerSettings"
@ -51,8 +50,9 @@ class PlayerSettings : PreferenceFragmentCompat() {
} }
defaultSubtitle?.entries = localeNames.toTypedArray() defaultSubtitle?.entries = localeNames.toTypedArray()
defaultSubtitle?.entryValues = localeCodes.toTypedArray() defaultSubtitle?.entryValues = localeCodes.toTypedArray()
defaultSubtitle?.summaryProvider = Preference.SummaryProvider<ListPreference> { preference -> defaultSubtitle?.summaryProvider =
preference.entry Preference.SummaryProvider<ListPreference> { preference ->
} preference.entry
}
} }
} }

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:color/white"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M14,36q-5,0 -8.5,-3.5T2,24q0,-5 3.5,-8.5T14,12h20q5,0 8.5,3.5T46,24q0,5 -3.5,8.5T34,36ZM14,33h20q3.75,0 6.375,-2.625T43,24q0,-3.75 -2.625,-6.375T34,15L14,15q-3.75,0 -6.375,2.625T5,24q0,3.75 2.625,6.375T14,33ZM13.95,29.05q2.1,0 3.575,-1.475T19,24q0,-2.1 -1.475,-3.575T13.95,18.95q-2.1,0 -3.575,1.475T8.9,24q0,2.1 1.475,3.575t3.575,1.475ZM24,24Z" />
</vector>

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:color/white"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M14,36q-5,0 -8.5,-3.5T2,24q0,-5 3.5,-8.5T14,12h20q5,0 8.5,3.5T46,24q0,5 -3.5,8.5T34,36ZM14,33h20q3.75,0 6.375,-2.625T43,24q0,-3.75 -2.625,-6.375T34,15L14,15q-3.75,0 -6.375,2.625T5,24q0,3.75 2.625,6.375T14,33ZM34.05,29.05q2.1,0 3.575,-1.475T39.1,24q0,-2.1 -1.475,-3.575T34.05,18.95q-2.1,0 -3.575,1.475T29,24q0,2.1 1.475,3.575t3.575,1.475ZM24,24Z" />
</vector>

View File

@ -89,30 +89,63 @@
<LinearLayout <LinearLayout
android:id="@+id/advanced_options" android:id="@+id/advanced_options"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginHorizontal="3dp"
android:layout_marginTop="-12dp" android:layout_marginTop="-12dp"
android:layout_marginEnd="3dp" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal">
android:visibility="gone">
<ImageButton <LinearLayout
android:id="@+id/captions" android:id="@+id/autoplayLL"
style="@style/PlayerControlTop" android:layout_width="0dp"
android:src="@drawable/ic_caption_outlined" android:layout_height="match_parent"
app:tint="@android:color/white" /> android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageButton <TextView
android:id="@+id/repeat_toggle" android:layout_width="wrap_content"
style="@style/PlayerControlTop" android:layout_height="wrap_content"
android:src="@drawable/ic_repeat" android:layout_gravity="center"
app:tint="@android:color/darker_gray" /> android:layout_marginBottom="1.5dp"
android:text="@string/player_autoplay"
android:textColor="@android:color/white" />
<ImageView <ImageView
android:id="@+id/aspect_ratio_button" android:id="@+id/autoplayIV"
style="@style/PlayerControlTop" android:layout_width="wrap_content"
android:src="@drawable/ic_aspect_ratio" /> android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:src="@drawable/ic_toggle_off" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/captions"
style="@style/PlayerControlTop"
android:src="@drawable/ic_caption_outlined"
app:tint="@android:color/white" />
<ImageButton
android:id="@+id/repeat_toggle"
style="@style/PlayerControlTop"
android:src="@drawable/ic_repeat"
app:tint="@android:color/darker_gray" />
<ImageView
android:id="@+id/aspect_ratio_button"
style="@style/PlayerControlTop"
android:src="@drawable/ic_aspect_ratio" />
</LinearLayout>
</LinearLayout> </LinearLayout>
@ -129,6 +162,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:baselineAligned="false"
android:paddingStart="10dp" android:paddingStart="10dp"
android:paddingEnd="15dp"> android:paddingEnd="15dp">

View File

@ -372,7 +372,7 @@
app:layout_constraintBottom_toBottomOf="@id/main_container" app:layout_constraintBottom_toBottomOf="@id/main_container"
app:layout_constraintStart_toStartOf="@id/main_container" app:layout_constraintStart_toStartOf="@id/main_container"
app:layout_constraintTop_toTopOf="@id/main_container" app:layout_constraintTop_toTopOf="@id/main_container"
app:show_buffering="when_playing" > app:show_buffering="when_playing">
<com.github.libretube.views.DoubleTapOverlay <com.github.libretube.views.DoubleTapOverlay
android:id="@+id/doubleTapOverlay" android:id="@+id/doubleTapOverlay"
@ -382,7 +382,6 @@
</com.github.libretube.views.CustomExoPlayerView> </com.github.libretube.views.CustomExoPlayerView>
<ImageView <ImageView
android:id="@+id/close_imageView" android:id="@+id/close_imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -96,11 +96,11 @@
<RelativeLayout <RelativeLayout
android:id="@+id/sub_channels_container" android:id="@+id/sub_channels_container"
android:visibility="gone"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"> android:descendantFocusability="blocksDescendants"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/sub_channels" android:id="@+id/sub_channels"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -6,8 +6,8 @@
<Preference <Preference
android:icon="@drawable/ic_settings" android:icon="@drawable/ic_settings"
app:key="general"
android:summary="@string/general_summary" android:summary="@string/general_summary"
app:key="general"
app:title="@string/general" /> app:title="@string/general" />
<Preference <Preference