diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 8d3f43cdd..bcee38708 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -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) } diff --git a/app/src/main/java/com/github/libretube/views/BottomSheetFragment.kt b/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt similarity index 51% rename from app/src/main/java/com/github/libretube/views/BottomSheetFragment.kt rename to app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt index 48de8f0ef..4a766b272 100644 --- a/app/src/main/java/com/github/libretube/views/BottomSheetFragment.kt +++ b/app/src/main/java/com/github/libretube/views/PlayerOptionsBottomSheet.kt @@ -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(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)" + } } diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 9741d8d52..395516bad 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -105,7 +105,8 @@ + android:text="00:00" + tools:ignore="HardcodedText" /> + android:text="00:00" + tools:ignore="HardcodedText" /> diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 33a47a5c5..7aaf15a4b 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -656,12 +656,12 @@ 0.25 0.5 0.75 - 1 + 1.0 1.25 1.5 - 2 - 3 - 4 + 2.0 + 3.0 + 4.0