mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
show current value in bottom sheet
This commit is contained in:
parent
a455fe52be
commit
b6fb971142
@ -64,7 +64,7 @@ import com.github.libretube.util.SubscriptionHelper
|
|||||||
import com.github.libretube.util.formatShort
|
import com.github.libretube.util.formatShort
|
||||||
import com.github.libretube.util.hideKeyboard
|
import com.github.libretube.util.hideKeyboard
|
||||||
import com.github.libretube.util.toID
|
import com.github.libretube.util.toID
|
||||||
import com.github.libretube.views.BottomSheetFragment
|
import com.github.libretube.views.PlayerOptionsBottomSheet
|
||||||
import com.google.android.exoplayer2.C
|
import com.google.android.exoplayer2.C
|
||||||
import com.google.android.exoplayer2.DefaultLoadControl
|
import com.google.android.exoplayer2.DefaultLoadControl
|
||||||
import com.google.android.exoplayer2.ExoPlayer
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
@ -87,8 +87,8 @@ import com.google.android.exoplayer2.upstream.DefaultDataSource
|
|||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil
|
import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||||
import com.google.android.exoplayer2.video.VideoSize
|
import com.google.android.exoplayer2.video.VideoSize
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import kotlinx.android.synthetic.main.bottom_sheet.repeatMode
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -220,7 +220,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
|
|
||||||
createExoPlayer()
|
createExoPlayer()
|
||||||
initializeTransitionLayout()
|
initializeTransitionLayout()
|
||||||
initializeOnClickActions()
|
initializeOnClickActions(requireContext())
|
||||||
playVideo()
|
playVideo()
|
||||||
|
|
||||||
showBottomBar()
|
showBottomBar()
|
||||||
@ -444,10 +444,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
|
|
||||||
// select the new caption preference
|
// select the new caption preference
|
||||||
trackSelector.buildUponParameters()
|
trackSelector.buildUponParameters()
|
||||||
.setPreferredTextLanguages(
|
.setPreferredTextLanguage(captionLanguageCode)
|
||||||
captionLanguage,
|
|
||||||
captionLanguageCode
|
|
||||||
)
|
|
||||||
.setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION)
|
.setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION)
|
||||||
} else {
|
} else {
|
||||||
// none selected
|
// none selected
|
||||||
@ -552,7 +549,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// actions that don't depend on video information
|
// actions that don't depend on video information
|
||||||
private fun initializeOnClickActions() {
|
private fun initializeOnClickActions(context: Context) {
|
||||||
binding.closeImageView.setOnClickListener {
|
binding.closeImageView.setOnClickListener {
|
||||||
Globals.MINI_PLAYER_VISIBLE = false
|
Globals.MINI_PLAYER_VISIBLE = false
|
||||||
binding.playerMotionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
@ -571,8 +568,38 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
// show the advanced player options
|
// show the advanced player options
|
||||||
playerBinding.toggleOptions.setOnClickListener {
|
playerBinding.toggleOptions.setOnClickListener {
|
||||||
val bottomSheetFragment = BottomSheetFragment().apply {
|
val bottomSheetFragment = PlayerOptionsBottomSheet().apply {
|
||||||
setOnClickListeners(playerOptionsInterface)
|
setOnClickListeners(playerOptionsInterface)
|
||||||
|
// set the auto play mode
|
||||||
|
currentAutoplayMode = if (autoplayEnabled) context.getString(R.string.enabled)
|
||||||
|
else context.getString(R.string.disabled)
|
||||||
|
// set the current caption language
|
||||||
|
currentCaptions = if (trackSelector.parameters.preferredTextLanguages.isNotEmpty()) {
|
||||||
|
trackSelector.parameters.preferredTextLanguages[0]
|
||||||
|
} else context.getString(R.string.none)
|
||||||
|
// set the playback speed
|
||||||
|
val playbackSpeeds = context.resources.getStringArray(R.array.playbackSpeed)
|
||||||
|
val playbackSpeedValues = context.resources.getStringArray(R.array.playbackSpeedValues)
|
||||||
|
val playbackSpeed = exoPlayer.playbackParameters.speed.toString()
|
||||||
|
currentPlaybackSpeed = playbackSpeeds[playbackSpeedValues.indexOf(playbackSpeed)]
|
||||||
|
// set the quality text
|
||||||
|
val isAdaptive = exoPlayer.videoFormat?.codecs != null
|
||||||
|
val quality = exoPlayer.videoSize.height
|
||||||
|
if (quality != 0) {
|
||||||
|
currentQuality =
|
||||||
|
if (isAdaptive) "${context.getString(R.string.hls)} • ${quality}p"
|
||||||
|
else "${quality}p"
|
||||||
|
}
|
||||||
|
// set the repeat mode
|
||||||
|
currentRepeatMode = if (exoPlayer.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
|
||||||
|
context.getString(R.string.repeat_mode_none)
|
||||||
|
} else context.getString(R.string.repeat_mode_current)
|
||||||
|
// set the aspect ratio mode
|
||||||
|
currentAspectRatio = when (exoPlayerView.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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bottomSheetFragment.show(childFragmentManager, null)
|
bottomSheetFragment.show(childFragmentManager, null)
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,33 @@ 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 android.widget.TextView
|
||||||
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.BottomSheetBinding
|
import com.github.libretube.databinding.BottomSheetBinding
|
||||||
import com.github.libretube.interfaces.PlayerOptionsInterface
|
import com.github.libretube.interfaces.PlayerOptionsInterface
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
|
||||||
class BottomSheetFragment : BottomSheetDialogFragment() {
|
/**
|
||||||
|
* Bottom Sheet including all the player options
|
||||||
|
*/
|
||||||
|
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||||
|
private val TAG = this::class.java.name.toString()
|
||||||
|
|
||||||
lateinit var binding: BottomSheetBinding
|
lateinit var binding: BottomSheetBinding
|
||||||
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
private lateinit var playerOptionsInterface: PlayerOptionsInterface
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current values
|
||||||
|
*/
|
||||||
|
var currentPlaybackSpeed: String? = null
|
||||||
|
var currentAutoplayMode: String? = null
|
||||||
|
var currentRepeatMode: String? = null
|
||||||
|
var currentQuality: String? = null
|
||||||
|
var currentAspectRatio: String? = null
|
||||||
|
var currentCaptions: String? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
@ -39,6 +56,22 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the text if a value is selected
|
||||||
|
*/
|
||||||
|
|
||||||
|
binding.autoplay.updateText(currentAutoplayMode)
|
||||||
|
|
||||||
|
binding.captions.updateText(currentCaptions)
|
||||||
|
|
||||||
|
binding.playbackSpeed.updateText(currentPlaybackSpeed)
|
||||||
|
|
||||||
|
binding.quality.updateText(currentQuality)
|
||||||
|
|
||||||
|
binding.repeatMode.updateText(currentRepeatMode)
|
||||||
|
|
||||||
|
binding.aspectRatio.updateText(currentAspectRatio)
|
||||||
|
|
||||||
binding.aspectRatio.setOnClickListener {
|
binding.aspectRatio.setOnClickListener {
|
||||||
playerOptionsInterface.onAspectRatioClicked()
|
playerOptionsInterface.onAspectRatioClicked()
|
||||||
this.dismiss()
|
this.dismiss()
|
||||||
@ -69,4 +102,9 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
|
|||||||
this.dismiss()
|
this.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun TextView.updateText(currentValue: String?) {
|
||||||
|
if (currentValue == null) return
|
||||||
|
this.text = "${this.text} ($currentValue)"
|
||||||
|
}
|
||||||
}
|
}
|
@ -656,12 +656,12 @@
|
|||||||
<item>0.25</item>
|
<item>0.25</item>
|
||||||
<item>0.5</item>
|
<item>0.5</item>
|
||||||
<item>0.75</item>
|
<item>0.75</item>
|
||||||
<item>1</item>
|
<item>1.0</item>
|
||||||
<item>1.25</item>
|
<item>1.25</item>
|
||||||
<item>1.5</item>
|
<item>1.5</item>
|
||||||
<item>2</item>
|
<item>2.0</item>
|
||||||
<item>3</item>
|
<item>3.0</item>
|
||||||
<item>4</item>
|
<item>4.0</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="downloadLocation">
|
<string-array name="downloadLocation">
|
||||||
|
Loading…
Reference in New Issue
Block a user