Merge pull request #1034 from Bnyro/master

show current value in bottom sheet
This commit is contained in:
Bnyro 2022-08-13 13:37:31 +02:00 committed by GitHub
commit 4fb6577ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 16 deletions

View File

@ -64,7 +64,7 @@ import com.github.libretube.util.SubscriptionHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.hideKeyboard
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.DefaultLoadControl
import com.google.android.exoplayer2.ExoPlayer
@ -88,6 +88,7 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.util.RepeatModeUtil
import com.google.android.exoplayer2.video.VideoSize
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.bottom_sheet.repeatMode
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -219,7 +220,7 @@ class PlayerFragment : BaseFragment() {
createExoPlayer()
initializeTransitionLayout()
initializeOnClickActions()
initializeOnClickActions(requireContext())
playVideo()
showBottomBar()
@ -443,10 +444,7 @@ class PlayerFragment : BaseFragment() {
// select the new caption preference
trackSelector.buildUponParameters()
.setPreferredTextLanguages(
captionLanguage,
captionLanguageCode
)
.setPreferredTextLanguage(captionLanguageCode)
.setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION)
} else {
// none selected
@ -551,7 +549,7 @@ class PlayerFragment : BaseFragment() {
}
// actions that don't depend on video information
private fun initializeOnClickActions() {
private fun initializeOnClickActions(context: Context) {
binding.closeImageView.setOnClickListener {
Globals.MINI_PLAYER_VISIBLE = false
binding.playerMotionLayout.transitionToEnd()
@ -570,8 +568,38 @@ class PlayerFragment : BaseFragment() {
}
// show the advanced player options
playerBinding.toggleOptions.setOnClickListener {
val bottomSheetFragment = BottomSheetFragment().apply {
val bottomSheetFragment = PlayerOptionsBottomSheet().apply {
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)
}

View File

@ -4,19 +4,47 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.github.libretube.R
import com.github.libretube.databinding.BottomSheetBinding
import com.github.libretube.interfaces.PlayerOptionsInterface
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class BottomSheetFragment : BottomSheetDialogFragment() {
private lateinit var binding: BottomSheetBinding
/**
* Bottom Sheet including all the player options
*/
class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
private val TAG = this::class.java.name.toString()
lateinit var binding: BottomSheetBinding
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(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// expand the bottom sheet on creation
dialog!!.setOnShowListener { dialog ->
val d = dialog as BottomSheetDialog
val bottomSheetInternal =
d.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)!!
BottomSheetBehavior.from(bottomSheetInternal).state =
BottomSheetBehavior.STATE_EXPANDED
}
binding = BottomSheetBinding.inflate(layoutInflater, container, false)
return binding.root
}
@ -28,6 +56,22 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
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 {
playerOptionsInterface.onAspectRatioClicked()
this.dismiss()
@ -58,4 +102,9 @@ class BottomSheetFragment : BottomSheetDialogFragment() {
this.dismiss()
}
}
private fun TextView.updateText(currentValue: String?) {
if (currentValue == null) return
this.text = "${this.text} ($currentValue)"
}
}

View File

@ -105,7 +105,8 @@
<TextView
android:id="@id/exo_position"
style="@style/TimeString"
tools:text="05:20" />
android:text="00:00"
tools:ignore="HardcodedText" />
<TextView
style="@style/TimeString"
@ -115,7 +116,8 @@
<TextView
android:id="@id/exo_duration"
style="@style/TimeString"
tools:text="12:15" />
android:text="00:00"
tools:ignore="HardcodedText" />
</LinearLayout>

View File

@ -656,12 +656,12 @@
<item>0.25</item>
<item>0.5</item>
<item>0.75</item>
<item>1</item>
<item>1.0</item>
<item>1.25</item>
<item>1.5</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>2.0</item>
<item>3.0</item>
<item>4.0</item>
</string-array>
<string-array name="downloadLocation">