bug fixes

This commit is contained in:
Bnyro 2022-09-10 16:47:45 +02:00
parent 1d5d254457
commit 50f8ae898c
4 changed files with 44 additions and 34 deletions

View File

@ -22,7 +22,7 @@ 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 {
title.text = item.title title.text = if (item.currentValue != null) "${item.title} (${item.currentValue})" else item.title
drawable.setImageResource(item.drawable) drawable.setImageResource(item.drawable)
root.setOnClickListener { root.setOnClickListener {

View File

@ -19,7 +19,6 @@ import com.github.libretube.models.SubscriptionsViewModel
import com.github.libretube.obj.BottomSheetItem import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.github.libretube.views.BottomSheet import com.github.libretube.views.BottomSheet
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class SubscriptionsFragment : BaseFragment() { class SubscriptionsFragment : BaseFragment() {
private lateinit var binding: FragmentSubscriptionsBinding private lateinit var binding: FragmentSubscriptionsBinding
@ -112,7 +111,8 @@ class SubscriptionsFragment : BaseFragment() {
val items = mutableListOf<BottomSheetItem>() val items = mutableListOf<BottomSheetItem>()
sortOptions.forEach { sortOptions.forEach {
items += BottomSheetItem( items += BottomSheetItem(
it, R.drawable.ic_arrow_down it,
R.drawable.ic_arrow_down
) )
} }

View File

@ -2,5 +2,6 @@ package com.github.libretube.obj
data class BottomSheetItem( data class BottomSheetItem(
val title: String, val title: String,
val drawable: Int val drawable: Int,
val currentValue: String? = null
) )

View File

@ -99,7 +99,7 @@ internal class CustomExoPlayerView(
enableDoubleTapToSeek() enableDoubleTapToSeek()
initializeAdvancedOptions() initializeAdvancedOptions(context)
// locking the player // locking the player
binding.lockPlayer.setOnClickListener { binding.lockPlayer.setOnClickListener {
@ -139,50 +139,58 @@ internal class CustomExoPlayerView(
return false return false
} }
private fun initializeAdvancedOptions() { private fun initializeAdvancedOptions(context: Context) {
binding.toggleOptions.setOnClickListener { binding.toggleOptions.setOnClickListener {
val bottomSheetFragment = BottomSheet().apply { val bottomSheetFragment = BottomSheet().apply {
val items = listOf( val items = listOf(
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.player_autoplay) + if (autoplayEnabled) { context.getString(R.string.player_autoplay),
context?.getString(R.string.enabled) R.drawable.ic_play,
if (autoplayEnabled) {
context.getString(R.string.enabled)
} else { } else {
context?.getString(R.string.disabled) context.getString(R.string.disabled)
}, }
R.drawable.ic_play
), ),
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.playback_speed) + "${ context.getString(R.string.playback_speed),
player?.playbackParameters?.speed.toString() R.drawable.ic_speed,
"${player?.playbackParameters?.speed
.toString()
.replace(".0", "") .replace(".0", "")
}x", }x"
R.drawable.ic_speed
), ),
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.repeat_mode) + if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) { context.getString(R.string.repeat_mode),
context?.getString(R.string.repeat_mode_none) R.drawable.ic_repeat,
if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_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)
}, }
R.drawable.ic_repeat
), ),
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.player_resize_mode) + when (resizeMode) { context.getString(R.string.player_resize_mode),
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context?.getString(R.string.resize_mode_fit) R.drawable.ic_aspect_ratio,
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context?.getString(R.string.resize_mode_fill) when (resizeMode) {
else -> context?.getString(R.string.resize_mode_zoom) AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
}, AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
R.drawable.ic_aspect_ratio else -> context.getString(R.string.resize_mode_zoom)
}
), ),
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.quality) + "${player?.videoSize?.height}p", context.getString(R.string.quality),
R.drawable.ic_hd R.drawable.ic_hd,
"${player?.videoSize?.height}p"
), ),
BottomSheetItem( BottomSheetItem(
context?.getString(R.string.captions) + if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) { context.getString(R.string.captions),
R.drawable.ic_caption,
if (trackSelector != null && trackSelector!!.parameters.preferredTextLanguages.isNotEmpty()) {
trackSelector!!.parameters.preferredTextLanguages[0] trackSelector!!.parameters.preferredTextLanguages[0]
} else context?.getString(R.string.none), } else {
R.drawable.ic_caption context.getString(R.string.none)
}
) )
) )
setItems(items) { index -> setItems(items) { index ->
@ -192,7 +200,7 @@ internal class CustomExoPlayerView(
2 -> onRepeatModeClicked() 2 -> onRepeatModeClicked()
3 -> onResizeModeClicked() 3 -> onResizeModeClicked()
4 -> playerOptionsInterface?.onQualityClicked() 4 -> playerOptionsInterface?.onQualityClicked()
5 -> playerOptionsInterface?.onQualityClicked() 5 -> playerOptionsInterface?.onCaptionClicked()
} }
} }
} }
@ -359,8 +367,9 @@ internal class CustomExoPlayerView(
) )
val repeatModes = arrayOf( val repeatModes = arrayOf(
RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL, RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE,
RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL
) )
// repeat mode options dialog // repeat mode options dialog
MaterialAlertDialogBuilder(context) MaterialAlertDialogBuilder(context)