From 50f8ae898c11fe49e2f0d2b08da1b6be493a634b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 10 Sep 2022 16:47:45 +0200 Subject: [PATCH] bug fixes --- .../libretube/adapters/BottomSheetAdapter.kt | 2 +- .../fragments/SubscriptionsFragment.kt | 4 +- .../github/libretube/obj/BottomSheetItem.kt | 3 +- .../libretube/views/CustomExoPlayerView.kt | 69 +++++++++++-------- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/BottomSheetAdapter.kt b/app/src/main/java/com/github/libretube/adapters/BottomSheetAdapter.kt index c1592d388..d6da2a235 100644 --- a/app/src/main/java/com/github/libretube/adapters/BottomSheetAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/BottomSheetAdapter.kt @@ -22,7 +22,7 @@ class BottomSheetAdapter( override fun onBindViewHolder(holder: BottomSheetViewHolder, position: Int) { val item = items[position] holder.binding.apply { - title.text = item.title + title.text = if (item.currentValue != null) "${item.title} (${item.currentValue})" else item.title drawable.setImageResource(item.drawable) root.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt index 9a28fab06..b3ede7a94 100644 --- a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt @@ -19,7 +19,6 @@ import com.github.libretube.models.SubscriptionsViewModel import com.github.libretube.obj.BottomSheetItem import com.github.libretube.util.PreferenceHelper import com.github.libretube.views.BottomSheet -import com.google.android.material.dialog.MaterialAlertDialogBuilder class SubscriptionsFragment : BaseFragment() { private lateinit var binding: FragmentSubscriptionsBinding @@ -112,7 +111,8 @@ class SubscriptionsFragment : BaseFragment() { val items = mutableListOf() sortOptions.forEach { items += BottomSheetItem( - it, R.drawable.ic_arrow_down + it, + R.drawable.ic_arrow_down ) } diff --git a/app/src/main/java/com/github/libretube/obj/BottomSheetItem.kt b/app/src/main/java/com/github/libretube/obj/BottomSheetItem.kt index 11a4b010f..ed7d965a5 100644 --- a/app/src/main/java/com/github/libretube/obj/BottomSheetItem.kt +++ b/app/src/main/java/com/github/libretube/obj/BottomSheetItem.kt @@ -2,5 +2,6 @@ package com.github.libretube.obj data class BottomSheetItem( val title: String, - val drawable: Int + val drawable: Int, + val currentValue: String? = null ) diff --git a/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt index fa195337b..aa6f3e4bc 100644 --- a/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt @@ -99,7 +99,7 @@ internal class CustomExoPlayerView( enableDoubleTapToSeek() - initializeAdvancedOptions() + initializeAdvancedOptions(context) // locking the player binding.lockPlayer.setOnClickListener { @@ -139,50 +139,58 @@ internal class CustomExoPlayerView( return false } - private fun initializeAdvancedOptions() { + private fun initializeAdvancedOptions(context: Context) { binding.toggleOptions.setOnClickListener { val bottomSheetFragment = BottomSheet().apply { val items = listOf( BottomSheetItem( - context?.getString(R.string.player_autoplay) + if (autoplayEnabled) { - context?.getString(R.string.enabled) + context.getString(R.string.player_autoplay), + R.drawable.ic_play, + if (autoplayEnabled) { + context.getString(R.string.enabled) } else { - context?.getString(R.string.disabled) - }, - R.drawable.ic_play + context.getString(R.string.disabled) + } ), BottomSheetItem( - context?.getString(R.string.playback_speed) + "${ - player?.playbackParameters?.speed.toString() + context.getString(R.string.playback_speed), + R.drawable.ic_speed, + "${player?.playbackParameters?.speed + .toString() .replace(".0", "") - }x", - R.drawable.ic_speed + }x" ), BottomSheetItem( - context?.getString(R.string.repeat_mode) + if (player?.repeatMode == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) { - context?.getString(R.string.repeat_mode_none) + 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) - }, - R.drawable.ic_repeat + context.getString(R.string.repeat_mode_current) + } ), BottomSheetItem( - context?.getString(R.string.player_resize_mode) + 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) - }, - R.drawable.ic_aspect_ratio + 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.quality) + "${player?.videoSize?.height}p", - R.drawable.ic_hd + context.getString(R.string.quality), + R.drawable.ic_hd, + "${player?.videoSize?.height}p" ), 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] - } else context?.getString(R.string.none), - R.drawable.ic_caption + } else { + context.getString(R.string.none) + } ) ) setItems(items) { index -> @@ -192,7 +200,7 @@ internal class CustomExoPlayerView( 2 -> onRepeatModeClicked() 3 -> onResizeModeClicked() 4 -> playerOptionsInterface?.onQualityClicked() - 5 -> playerOptionsInterface?.onQualityClicked() + 5 -> playerOptionsInterface?.onCaptionClicked() } } } @@ -359,8 +367,9 @@ internal class CustomExoPlayerView( ) 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 MaterialAlertDialogBuilder(context)