mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #1880 from Bnyro/master
show the current preferred audio language
This commit is contained in:
commit
6f960e94a7
@ -3,6 +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 getCurrent: () -> String? = { null },
|
||||||
val onClick: () -> Unit = {}
|
val onClick: () -> Unit = {}
|
||||||
)
|
)
|
||||||
|
@ -68,7 +68,6 @@ class OfflinePlayerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.player.initialize(
|
binding.player.initialize(
|
||||||
supportFragmentManager,
|
|
||||||
null,
|
null,
|
||||||
binding.doubleTapOverlay.binding,
|
binding.doubleTapOverlay.binding,
|
||||||
null
|
null
|
||||||
|
@ -24,13 +24,13 @@ class BottomSheetAdapter(
|
|||||||
override fun onBindViewHolder(holder: BottomSheetViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: BottomSheetViewHolder, position: Int) {
|
||||||
val item = items[position]
|
val item = items[position]
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
|
val current = item.getCurrent()
|
||||||
title.text =
|
title.text =
|
||||||
if (item.currentValue != null) "${item.title} (${item.currentValue})" else item.title
|
if (current != null) "${item.title} ($current)" else item.title
|
||||||
if (item.drawable != null) {
|
if (item.drawable != null) {
|
||||||
drawable.setImageResource(item.drawable)
|
drawable.setImageResource(item.drawable)
|
||||||
} else {
|
} else {
|
||||||
drawable.visibility =
|
drawable.visibility = View.GONE
|
||||||
View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
|
@ -757,7 +757,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
private fun initializePlayerView(response: Streams) {
|
private fun initializePlayerView(response: Streams) {
|
||||||
// initialize the player view actions
|
// initialize the player view actions
|
||||||
binding.player.initialize(
|
binding.player.initialize(
|
||||||
childFragmentManager,
|
|
||||||
this,
|
this,
|
||||||
doubleTapOverlayBinding,
|
doubleTapOverlayBinding,
|
||||||
trackSelector
|
trackSelector
|
||||||
|
@ -8,13 +8,13 @@ import android.os.Looper
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
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.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.base.BaseActivity
|
||||||
import com.github.libretube.ui.interfaces.DoubleTapInterface
|
import com.github.libretube.ui.interfaces.DoubleTapInterface
|
||||||
import com.github.libretube.ui.interfaces.DoubleTapListener
|
import com.github.libretube.ui.interfaces.DoubleTapListener
|
||||||
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
|
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
|
||||||
@ -41,7 +41,6 @@ internal class CustomExoPlayerView(
|
|||||||
*/
|
*/
|
||||||
private var doubleTapListener: DoubleTapInterface? = null
|
private var doubleTapListener: DoubleTapInterface? = null
|
||||||
private var playerOptionsInterface: OnlinePlayerOptions? = null
|
private var playerOptionsInterface: OnlinePlayerOptions? = null
|
||||||
private lateinit var childFragmentManager: FragmentManager
|
|
||||||
private var trackSelector: TrackSelector? = null
|
private var trackSelector: TrackSelector? = null
|
||||||
|
|
||||||
private val runnableHandler = Handler(Looper.getMainLooper())
|
private val runnableHandler = Handler(Looper.getMainLooper())
|
||||||
@ -58,6 +57,9 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
private var resizeModePref = PlayerHelper.resizeModePref
|
private var resizeModePref = PlayerHelper.resizeModePref
|
||||||
|
|
||||||
|
private val supportFragmentManager
|
||||||
|
get() = (context as BaseActivity).supportFragmentManager
|
||||||
|
|
||||||
private fun toggleController() {
|
private fun toggleController() {
|
||||||
if (isControllerFullyVisible) hideController() else showController()
|
if (isControllerFullyVisible) hideController() else showController()
|
||||||
}
|
}
|
||||||
@ -73,12 +75,10 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun initialize(
|
fun initialize(
|
||||||
childFragmentManager: FragmentManager,
|
|
||||||
playerViewInterface: OnlinePlayerOptions?,
|
playerViewInterface: OnlinePlayerOptions?,
|
||||||
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
||||||
trackSelector: TrackSelector?
|
trackSelector: TrackSelector?
|
||||||
) {
|
) {
|
||||||
this.childFragmentManager = childFragmentManager
|
|
||||||
this.playerOptionsInterface = playerViewInterface
|
this.playerOptionsInterface = playerViewInterface
|
||||||
this.doubleTapOverlayBinding = doubleTapOverlayBinding
|
this.doubleTapOverlayBinding = doubleTapOverlayBinding
|
||||||
this.trackSelector = trackSelector
|
this.trackSelector = trackSelector
|
||||||
@ -142,44 +142,52 @@ internal class CustomExoPlayerView(
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
onAutoplayClicked()
|
onAutoplayClicked()
|
||||||
},
|
},
|
||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.repeat_mode),
|
context.getString(R.string.repeat_mode),
|
||||||
R.drawable.ic_repeat,
|
R.drawable.ic_repeat,
|
||||||
|
{
|
||||||
if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
|
if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
|
||||||
context.getString(R.string.repeat_mode_none)
|
context.getString(R.string.repeat_mode_none)
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.repeat_mode_current)
|
context.getString(R.string.repeat_mode_current)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
onRepeatModeClicked()
|
onRepeatModeClicked()
|
||||||
},
|
},
|
||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.player_resize_mode),
|
context.getString(R.string.player_resize_mode),
|
||||||
R.drawable.ic_aspect_ratio,
|
R.drawable.ic_aspect_ratio,
|
||||||
|
{
|
||||||
when (resizeMode) {
|
when (resizeMode) {
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
|
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
|
||||||
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
|
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
|
||||||
else -> context.getString(R.string.resize_mode_zoom)
|
else -> context.getString(R.string.resize_mode_zoom)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
onResizeModeClicked()
|
onResizeModeClicked()
|
||||||
},
|
},
|
||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.playback_speed),
|
context.getString(R.string.playback_speed),
|
||||||
R.drawable.ic_speed,
|
R.drawable.ic_speed,
|
||||||
|
{
|
||||||
"${
|
"${
|
||||||
player?.playbackParameters?.speed
|
player?.playbackParameters?.speed
|
||||||
.toString()
|
.toString()
|
||||||
.replace(".0", "")
|
.replace(".0", "")
|
||||||
}x"
|
}x"
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
onPlaybackSpeedClicked()
|
onPlaybackSpeedClicked()
|
||||||
}
|
}
|
||||||
@ -190,7 +198,7 @@ internal class CustomExoPlayerView(
|
|||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.quality),
|
context.getString(R.string.quality),
|
||||||
R.drawable.ic_hd,
|
R.drawable.ic_hd,
|
||||||
"${player?.videoSize?.height}p"
|
{ "${player?.videoSize?.height}p" }
|
||||||
) {
|
) {
|
||||||
playerOptionsInterface?.onQualityClicked()
|
playerOptionsInterface?.onQualityClicked()
|
||||||
}
|
}
|
||||||
@ -198,7 +206,10 @@ internal class CustomExoPlayerView(
|
|||||||
items.add(
|
items.add(
|
||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.audio_track),
|
context.getString(R.string.audio_track),
|
||||||
R.drawable.ic_audio
|
R.drawable.ic_audio,
|
||||||
|
{
|
||||||
|
trackSelector?.parameters?.preferredAudioLanguages?.firstOrNull()
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
playerOptionsInterface?.onAudioStreamClicked()
|
playerOptionsInterface?.onAudioStreamClicked()
|
||||||
}
|
}
|
||||||
@ -207,11 +218,13 @@ internal class CustomExoPlayerView(
|
|||||||
BottomSheetItem(
|
BottomSheetItem(
|
||||||
context.getString(R.string.captions),
|
context.getString(R.string.captions),
|
||||||
R.drawable.ic_caption,
|
R.drawable.ic_caption,
|
||||||
|
{
|
||||||
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
|
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
|
||||||
trackSelector!!.parameters.preferredTextLanguages[0]
|
trackSelector!!.parameters.preferredTextLanguages[0]
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.none)
|
context.getString(R.string.none)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
playerOptionsInterface?.onCaptionsClicked()
|
playerOptionsInterface?.onCaptionsClicked()
|
||||||
}
|
}
|
||||||
@ -219,7 +232,7 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val bottomSheetFragment = BaseBottomSheet().setItems(items, null)
|
val bottomSheetFragment = BaseBottomSheet().setItems(items, null)
|
||||||
bottomSheetFragment.show(childFragmentManager, null)
|
bottomSheetFragment.show(supportFragmentManager, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,11 +345,11 @@ internal class CustomExoPlayerView(
|
|||||||
1 -> autoplayEnabled = false
|
1 -> autoplayEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.show(childFragmentManager)
|
.show(supportFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlaybackSpeedClicked() {
|
override fun onPlaybackSpeedClicked() {
|
||||||
player?.let { PlaybackSpeedSheet(it).show(childFragmentManager) }
|
player?.let { PlaybackSpeedSheet(it).show(supportFragmentManager) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResizeModeClicked() {
|
override fun onResizeModeClicked() {
|
||||||
@ -354,7 +367,7 @@ internal class CustomExoPlayerView(
|
|||||||
.setSimpleItems(aspectRatioModeNames) { index ->
|
.setSimpleItems(aspectRatioModeNames) { index ->
|
||||||
resizeMode = aspectRatioModes[index]
|
resizeMode = aspectRatioModes[index]
|
||||||
}
|
}
|
||||||
.show(childFragmentManager)
|
.show(supportFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRepeatModeClicked() {
|
override fun onRepeatModeClicked() {
|
||||||
@ -373,7 +386,7 @@ internal class CustomExoPlayerView(
|
|||||||
.setSimpleItems(repeatModeNames) { index ->
|
.setSimpleItems(repeatModeNames) { index ->
|
||||||
player?.repeatMode = repeatModes[index]
|
player?.repeatMode = repeatModes[index]
|
||||||
}
|
}
|
||||||
.show(childFragmentManager)
|
.show(supportFragmentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration?) {
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user