mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #1434 from Bnyro/master
use bottom sheets for all player options
This commit is contained in:
commit
9476736bd3
@ -63,6 +63,7 @@ import com.github.libretube.ui.base.BaseFragment
|
|||||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||||
import com.github.libretube.ui.dialogs.DownloadDialog
|
import com.github.libretube.ui.dialogs.DownloadDialog
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
|
import com.github.libretube.ui.views.BottomSheet
|
||||||
import com.github.libretube.util.AutoPlayHelper
|
import com.github.libretube.util.AutoPlayHelper
|
||||||
import com.github.libretube.util.BackgroundHelper
|
import com.github.libretube.util.BackgroundHelper
|
||||||
import com.github.libretube.util.ImageHelper
|
import com.github.libretube.util.ImageHelper
|
||||||
@ -426,9 +427,8 @@ class PlayerFragment : BaseFragment() {
|
|||||||
subtitleCodesList += it.code!!
|
subtitleCodesList += it.code!!
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
BottomSheet()
|
||||||
.setTitle(R.string.captions)
|
.setSimpleItems(subtitlesNamesList) { index ->
|
||||||
.setItems(subtitlesNamesList.toTypedArray()) { _, index ->
|
|
||||||
val newParams = if (index != 0) {
|
val newParams = if (index != 0) {
|
||||||
// caption selected
|
// caption selected
|
||||||
|
|
||||||
@ -449,7 +449,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
// set the new caption language
|
// set the new caption language
|
||||||
trackSelector.setParameters(newParams)
|
trackSelector.setParameters(newParams)
|
||||||
}
|
}
|
||||||
.show()
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQualityClicked() {
|
override fun onQualityClicked() {
|
||||||
@ -458,11 +458,10 @@ class PlayerFragment : BaseFragment() {
|
|||||||
|
|
||||||
// Dialog for quality selection
|
// Dialog for quality selection
|
||||||
val lastPosition = exoPlayer.currentPosition
|
val lastPosition = exoPlayer.currentPosition
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
BottomSheet()
|
||||||
.setTitle(R.string.choose_quality_dialog)
|
.setSimpleItems(
|
||||||
.setItems(
|
videosNameArray.toList()
|
||||||
videosNameArray
|
) { which ->
|
||||||
) { _, which ->
|
|
||||||
if (
|
if (
|
||||||
videosNameArray[which] == getString(R.string.hls) ||
|
videosNameArray[which] == getString(R.string.hls) ||
|
||||||
videosNameArray[which] == "LBRY HLS"
|
videosNameArray[which] == "LBRY HLS"
|
||||||
@ -477,7 +476,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
exoPlayer.seekTo(lastPosition)
|
exoPlayer.seekTo(lastPosition)
|
||||||
}
|
}
|
||||||
.show()
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.github.libretube.databinding.PlaybackBottomSheetBinding
|
import com.github.libretube.databinding.PlaybackBottomSheetBinding
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
|
||||||
@ -32,4 +33,9 @@ class PlaybackSpeedSheet(
|
|||||||
onChange.invoke(binding.speed.value, value)
|
onChange.invoke(binding.speed.value, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun show(fragmentManager: FragmentManager) = show(
|
||||||
|
fragmentManager,
|
||||||
|
null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.github.libretube.databinding.BottomSheetBinding
|
import com.github.libretube.databinding.BottomSheetBinding
|
||||||
import com.github.libretube.obj.BottomSheetItem
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
@ -31,7 +32,7 @@ open class BottomSheet : BottomSheetDialogFragment() {
|
|||||||
binding.optionsRecycler.adapter = BottomSheetAdapter(items, listener)
|
binding.optionsRecycler.adapter = BottomSheetAdapter(items, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setItems(items: List<BottomSheetItem>, listener: (index: Int) -> Unit) {
|
fun setItems(items: List<BottomSheetItem>, listener: (index: Int) -> Unit) = apply {
|
||||||
this.items = items
|
this.items = items
|
||||||
this.listener = { index ->
|
this.listener = { index ->
|
||||||
listener.invoke(index)
|
listener.invoke(index)
|
||||||
@ -39,11 +40,16 @@ open class BottomSheet : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSimpleItems(titles: List<String>, listener: (index: Int) -> Unit) {
|
fun setSimpleItems(titles: List<String>, listener: (index: Int) -> Unit) = apply {
|
||||||
this.items = titles.map { BottomSheetItem(it) }
|
this.items = titles.map { BottomSheetItem(it) }
|
||||||
this.listener = { index ->
|
this.listener = { index ->
|
||||||
listener.invoke(index)
|
listener.invoke(index)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun show(fragmentManager: FragmentManager) = show(
|
||||||
|
fragmentManager,
|
||||||
|
null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelector
|
|||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil
|
import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@ -58,7 +57,7 @@ internal class CustomExoPlayerView(
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
val playbackSpeed = PreferenceHelper.getString(
|
private val playbackSpeed = PreferenceHelper.getString(
|
||||||
PreferenceKeys.PLAYBACK_SPEED,
|
PreferenceKeys.PLAYBACK_SPEED,
|
||||||
"1"
|
"1"
|
||||||
).replace("F", "")
|
).replace("F", "")
|
||||||
@ -323,68 +322,66 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAutoplayClicked() {
|
private fun onAutoplayClicked() {
|
||||||
// autoplay options dialog
|
// autoplay options dialog
|
||||||
MaterialAlertDialogBuilder(context)
|
BottomSheet()
|
||||||
.setTitle(R.string.player_autoplay)
|
.setSimpleItems(
|
||||||
.setItems(
|
listOf(
|
||||||
arrayOf(
|
|
||||||
context.getString(R.string.enabled),
|
context.getString(R.string.enabled),
|
||||||
context.getString(R.string.disabled)
|
context.getString(R.string.disabled)
|
||||||
)
|
)
|
||||||
) { _, index ->
|
) { index ->
|
||||||
when (index) {
|
when (index) {
|
||||||
0 -> autoplayEnabled = true
|
0 -> autoplayEnabled = true
|
||||||
1 -> autoplayEnabled = false
|
1 -> autoplayEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.show()
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPlaybackSpeedClicked() {
|
private fun onPlaybackSpeedClicked() {
|
||||||
PlaybackSpeedSheet { speed, pitch ->
|
PlaybackSpeedSheet { speed, pitch ->
|
||||||
player?.playbackParameters = PlaybackParameters(
|
player?.playbackParameters = PlaybackParameters(
|
||||||
speed,
|
speed,
|
||||||
pitch
|
pitch
|
||||||
)
|
)
|
||||||
}.show(childFragmentManager, null)
|
}.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onResizeModeClicked() {
|
private fun onResizeModeClicked() {
|
||||||
// switching between original aspect ratio (black bars) and zoomed to fill device screen
|
// switching between original aspect ratio (black bars) and zoomed to fill device screen
|
||||||
val aspectRatioModeNames = context.resources?.getStringArray(R.array.resizeMode)
|
val aspectRatioModeNames = context.resources?.getStringArray(R.array.resizeMode)
|
||||||
|
?.toList().orEmpty()
|
||||||
|
|
||||||
val aspectRatioModes = arrayOf(
|
val aspectRatioModes = listOf(
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FIT,
|
AspectRatioFrameLayout.RESIZE_MODE_FIT,
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_ZOOM,
|
AspectRatioFrameLayout.RESIZE_MODE_ZOOM,
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FILL
|
AspectRatioFrameLayout.RESIZE_MODE_FILL
|
||||||
)
|
)
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(context)
|
BottomSheet()
|
||||||
.setTitle(R.string.aspect_ratio)
|
.setSimpleItems(aspectRatioModeNames) { index ->
|
||||||
.setItems(aspectRatioModeNames) { _, index ->
|
|
||||||
resizeMode = aspectRatioModes[index]
|
resizeMode = aspectRatioModes[index]
|
||||||
}
|
}
|
||||||
.show()
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRepeatModeClicked() {
|
private fun onRepeatModeClicked() {
|
||||||
val repeatModeNames = arrayOf(
|
val repeatModeNames = listOf(
|
||||||
context.getString(R.string.repeat_mode_none),
|
context.getString(R.string.repeat_mode_none),
|
||||||
context.getString(R.string.repeat_mode_current)
|
context.getString(R.string.repeat_mode_current)
|
||||||
)
|
)
|
||||||
|
|
||||||
val repeatModes = arrayOf(
|
val repeatModes = listOf(
|
||||||
RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE,
|
RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE,
|
||||||
RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL
|
RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL
|
||||||
|
|
||||||
)
|
)
|
||||||
// repeat mode options dialog
|
// repeat mode options dialog
|
||||||
MaterialAlertDialogBuilder(context)
|
BottomSheet()
|
||||||
.setTitle(R.string.repeat_mode)
|
.setSimpleItems(repeatModeNames) { index ->
|
||||||
.setItems(repeatModeNames) { _, index ->
|
|
||||||
player?.repeatMode = repeatModes[index]
|
player?.repeatMode = repeatModes[index]
|
||||||
}
|
}
|
||||||
.show()
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user