mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
player view cleanup
This commit is contained in:
parent
ae3f48fc45
commit
c8c2ab02e2
@ -1,7 +1,7 @@
|
|||||||
package com.github.libretube.models.interfaces
|
package com.github.libretube.models.interfaces
|
||||||
|
|
||||||
interface PlayerOptionsInterface {
|
interface OnlinePlayerOptions {
|
||||||
fun onCaptionClicked()
|
fun onCaptionsClicked()
|
||||||
|
|
||||||
fun onQualityClicked()
|
fun onQualityClicked()
|
||||||
}
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.github.libretube.models.interfaces
|
||||||
|
|
||||||
|
interface PlayerOptions {
|
||||||
|
fun onAutoplayClicked()
|
||||||
|
|
||||||
|
fun onPlaybackSpeedClicked()
|
||||||
|
|
||||||
|
fun onResizeModeClicked()
|
||||||
|
|
||||||
|
fun onRepeatModeClicked()
|
||||||
|
}
|
@ -3,5 +3,6 @@ package com.github.libretube.obj
|
|||||||
data class BottomSheetItem(
|
data class BottomSheetItem(
|
||||||
val title: String,
|
val title: String,
|
||||||
val drawable: Int? = null,
|
val drawable: Int? = null,
|
||||||
val currentValue: String? = null
|
val currentValue: String? = null,
|
||||||
|
val onClick: () -> Unit = {}
|
||||||
)
|
)
|
||||||
|
@ -34,6 +34,7 @@ class BottomSheetAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
|
item.onClick.invoke()
|
||||||
listener.invoke(position)
|
listener.invoke(position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ import com.github.libretube.extensions.query
|
|||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.extensions.toStreamItem
|
import com.github.libretube.extensions.toStreamItem
|
||||||
import com.github.libretube.models.PlayerViewModel
|
import com.github.libretube.models.PlayerViewModel
|
||||||
import com.github.libretube.models.interfaces.PlayerOptionsInterface
|
import com.github.libretube.models.interfaces.OnlinePlayerOptions
|
||||||
import com.github.libretube.services.BackgroundMode
|
import com.github.libretube.services.BackgroundMode
|
||||||
import com.github.libretube.services.DownloadService
|
import com.github.libretube.services.DownloadService
|
||||||
import com.github.libretube.ui.activities.MainActivity
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
@ -105,7 +105,7 @@ import java.io.IOException
|
|||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class PlayerFragment : BaseFragment(), PlayerOptionsInterface {
|
class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||||
|
|
||||||
lateinit var binding: FragmentPlayerBinding
|
lateinit var binding: FragmentPlayerBinding
|
||||||
private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
|
private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
|
||||||
@ -1319,7 +1319,7 @@ class PlayerFragment : BaseFragment(), PlayerOptionsInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCaptionClicked() {
|
override fun onCaptionsClicked() {
|
||||||
if (!this@PlayerFragment::streams.isInitialized ||
|
if (!this@PlayerFragment::streams.isInitialized ||
|
||||||
streams.subtitles == null ||
|
streams.subtitles == null ||
|
||||||
streams.subtitles!!.isEmpty()
|
streams.subtitles!!.isEmpty()
|
||||||
|
@ -32,18 +32,18 @@ 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) = apply {
|
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)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setSimpleItems(titles: List<String>, listener: (index: Int) -> Unit) = apply {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ import com.github.libretube.databinding.DoubleTapOverlayBinding
|
|||||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.github.libretube.extensions.toDp
|
import com.github.libretube.extensions.toDp
|
||||||
import com.github.libretube.models.interfaces.DoubleTapInterface
|
import com.github.libretube.models.interfaces.DoubleTapInterface
|
||||||
import com.github.libretube.models.interfaces.PlayerOptionsInterface
|
import com.github.libretube.models.interfaces.OnlinePlayerOptions
|
||||||
|
import com.github.libretube.models.interfaces.PlayerOptions
|
||||||
import com.github.libretube.obj.BottomSheetItem
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
import com.github.libretube.ui.activities.MainActivity
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
|
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
|
||||||
@ -30,7 +31,7 @@ import com.google.android.exoplayer2.util.RepeatModeUtil
|
|||||||
internal class CustomExoPlayerView(
|
internal class CustomExoPlayerView(
|
||||||
context: Context,
|
context: Context,
|
||||||
attributeSet: AttributeSet? = null
|
attributeSet: AttributeSet? = null
|
||||||
) : StyledPlayerView(context, attributeSet) {
|
) : StyledPlayerView(context, attributeSet), PlayerOptions {
|
||||||
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
val binding: ExoStyledPlayerControlViewBinding = ExoStyledPlayerControlViewBinding.bind(this)
|
||||||
private var doubleTapOverlayBinding: DoubleTapOverlayBinding? = null
|
private var doubleTapOverlayBinding: DoubleTapOverlayBinding? = null
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ internal class CustomExoPlayerView(
|
|||||||
* Objects from the parent fragment
|
* Objects from the parent fragment
|
||||||
*/
|
*/
|
||||||
private var doubleTapListener: DoubleTapInterface? = null
|
private var doubleTapListener: DoubleTapInterface? = null
|
||||||
private var playerOptionsInterface: PlayerOptionsInterface? = null
|
private var playerOptionsInterface: OnlinePlayerOptions? = null
|
||||||
private lateinit var childFragmentManager: FragmentManager
|
private lateinit var childFragmentManager: FragmentManager
|
||||||
private var trackSelector: TrackSelector? = null
|
private var trackSelector: TrackSelector? = null
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
fun initialize(
|
fun initialize(
|
||||||
childFragmentManager: FragmentManager,
|
childFragmentManager: FragmentManager,
|
||||||
playerViewInterface: PlayerOptionsInterface?,
|
playerViewInterface: OnlinePlayerOptions?,
|
||||||
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
||||||
trackSelector: TrackSelector?
|
trackSelector: TrackSelector?
|
||||||
) {
|
) {
|
||||||
@ -136,78 +137,79 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
private fun initializeAdvancedOptions(context: Context) {
|
private fun initializeAdvancedOptions(context: Context) {
|
||||||
binding.toggleOptions.setOnClickListener {
|
binding.toggleOptions.setOnClickListener {
|
||||||
val bottomSheetFragment = BottomSheet().apply {
|
val items = mutableListOf(
|
||||||
val items = mutableListOf(
|
BottomSheetItem(
|
||||||
BottomSheetItem(
|
context.getString(R.string.player_autoplay),
|
||||||
context.getString(R.string.player_autoplay),
|
R.drawable.ic_play,
|
||||||
R.drawable.ic_play,
|
if (autoplayEnabled) {
|
||||||
if (autoplayEnabled) {
|
context.getString(R.string.enabled)
|
||||||
context.getString(R.string.enabled)
|
} else {
|
||||||
} else {
|
context.getString(R.string.disabled)
|
||||||
context.getString(R.string.disabled)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.repeat_mode),
|
|
||||||
R.drawable.ic_repeat,
|
|
||||||
if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
|
|
||||||
context.getString(R.string.repeat_mode_none)
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.repeat_mode_current)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.player_resize_mode),
|
|
||||||
R.drawable.ic_aspect_ratio,
|
|
||||||
when (resizeMode) {
|
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
|
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
|
|
||||||
else -> context.getString(R.string.resize_mode_zoom)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.playback_speed),
|
|
||||||
R.drawable.ic_speed,
|
|
||||||
"${
|
|
||||||
player?.playbackParameters?.speed
|
|
||||||
.toString()
|
|
||||||
.replace(".0", "")
|
|
||||||
}x"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (playerOptionsInterface != null) {
|
|
||||||
items.add(
|
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.quality),
|
|
||||||
R.drawable.ic_hd,
|
|
||||||
"${player?.videoSize?.height}p"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
items.add(
|
|
||||||
BottomSheetItem(
|
|
||||||
context.getString(R.string.captions),
|
|
||||||
R.drawable.ic_caption,
|
|
||||||
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
|
|
||||||
trackSelector!!.parameters.preferredTextLanguages[0]
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.none)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
setItems(items) { index ->
|
|
||||||
when (index) {
|
|
||||||
0 -> onAutoplayClicked()
|
|
||||||
1 -> onRepeatModeClicked()
|
|
||||||
2 -> onResizeModeClicked()
|
|
||||||
3 -> onPlaybackSpeedClicked()
|
|
||||||
4 -> playerOptionsInterface?.onQualityClicked()
|
|
||||||
5 -> playerOptionsInterface?.onCaptionClicked()
|
|
||||||
}
|
}
|
||||||
|
) {
|
||||||
|
onAutoplayClicked()
|
||||||
|
},
|
||||||
|
BottomSheetItem(
|
||||||
|
context.getString(R.string.repeat_mode),
|
||||||
|
R.drawable.ic_repeat,
|
||||||
|
if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
|
||||||
|
context.getString(R.string.repeat_mode_none)
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.repeat_mode_current)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
onRepeatModeClicked()
|
||||||
|
},
|
||||||
|
BottomSheetItem(
|
||||||
|
context.getString(R.string.player_resize_mode),
|
||||||
|
R.drawable.ic_aspect_ratio,
|
||||||
|
when (resizeMode) {
|
||||||
|
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
|
||||||
|
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
|
||||||
|
else -> context.getString(R.string.resize_mode_zoom)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
onResizeModeClicked()
|
||||||
|
},
|
||||||
|
BottomSheetItem(
|
||||||
|
context.getString(R.string.playback_speed),
|
||||||
|
R.drawable.ic_speed,
|
||||||
|
"${
|
||||||
|
player?.playbackParameters?.speed
|
||||||
|
.toString()
|
||||||
|
.replace(".0", "")
|
||||||
|
}x"
|
||||||
|
) {
|
||||||
|
onPlaybackSpeedClicked()
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (playerOptionsInterface != null) {
|
||||||
|
items.add(
|
||||||
|
BottomSheetItem(
|
||||||
|
context.getString(R.string.quality),
|
||||||
|
R.drawable.ic_hd,
|
||||||
|
"${player?.videoSize?.height}p"
|
||||||
|
) {
|
||||||
|
playerOptionsInterface?.onQualityClicked()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
items.add(
|
||||||
|
BottomSheetItem(
|
||||||
|
context.getString(R.string.captions),
|
||||||
|
R.drawable.ic_caption,
|
||||||
|
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
|
||||||
|
trackSelector!!.parameters.preferredTextLanguages[0]
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.none)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
playerOptionsInterface?.onCaptionsClicked()
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val bottomSheetFragment = BottomSheet().setItems(items, null)
|
||||||
bottomSheetFragment.show(childFragmentManager, null)
|
bottomSheetFragment.show(childFragmentManager, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +309,7 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onAutoplayClicked() {
|
override fun onAutoplayClicked() {
|
||||||
// autoplay options dialog
|
// autoplay options dialog
|
||||||
BottomSheet()
|
BottomSheet()
|
||||||
.setSimpleItems(
|
.setSimpleItems(
|
||||||
@ -324,11 +326,11 @@ internal class CustomExoPlayerView(
|
|||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPlaybackSpeedClicked() {
|
override fun onPlaybackSpeedClicked() {
|
||||||
player?.let { PlaybackSpeedSheet(it).show(childFragmentManager) }
|
player?.let { PlaybackSpeedSheet(it).show(childFragmentManager) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onResizeModeClicked() {
|
override 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()
|
?.toList().orEmpty()
|
||||||
@ -346,7 +348,7 @@ internal class CustomExoPlayerView(
|
|||||||
.show(childFragmentManager)
|
.show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onRepeatModeClicked() {
|
override fun onRepeatModeClicked() {
|
||||||
val repeatModeNames = listOf(
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user