From 5144947a4a129feaaae79d6531baa914b988acd8 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sat, 7 May 2022 14:51:20 +0200 Subject: [PATCH] Media player fixes: better handling of RTL & orientation --- .../droidfs/file_viewers/VideoPlayer.kt | 17 +++++++------- .../droidfs/widgets/DoubleTapPlayerView.kt | 23 +++++++++++-------- .../audio_exo_styled_player_control_view.xml | 1 + .../main/res/layout/exo_center_controls.xml | 1 + 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt index ca3de08..3d93acd 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt @@ -1,6 +1,7 @@ package sushi.hardcore.droidfs.file_viewers import android.content.pm.ActivityInfo +import android.content.res.Configuration import com.google.android.exoplayer2.ExoPlayer import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding @@ -14,23 +15,23 @@ class VideoPlayer: MediaPlayer() { override fun viewFile() { binding = ActivityVideoPlayerBinding.inflate(layoutInflater) setContentView(binding.root) - super.viewFile() - } - - override fun bindPlayer(player: ExoPlayer) { - binding.videoPlayer.player = player binding.videoPlayer.doubleTapOverlay = binding.doubleTapOverlay binding.videoPlayer.setControllerVisibilityListener { visibility -> binding.topBar.visibility = visibility } binding.rotateButton.setOnClickListener { requestedOrientation = - if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE) - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - else + if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { + ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT + } else { ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + } } + super.viewFile() + } + override fun bindPlayer(player: ExoPlayer) { + binding.videoPlayer.player = player } override fun onNewFileName(fileName: String) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt index 921d3ac..cf66aa2 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt @@ -88,7 +88,7 @@ class DoubleTapPlayerView @JvmOverloads constructor( init { if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - updateButtonSize(Configuration.ORIENTATION_LANDSCAPE) + handleOrientationChange(Configuration.ORIENTATION_LANDSCAPE) } } @@ -151,16 +151,19 @@ class DoubleTapPlayerView @JvmOverloads constructor( } } - override fun onConfigurationChanged(newConfig: Configuration) { - super.onConfigurationChanged(newConfig) + private fun handleOrientationChange(orientation: Int) { val centerControls = findViewById(R.id.exo_center_controls) (centerControls.parent as ViewGroup).removeView(centerControls) - findViewById( - if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) - R.id.center_controls_bar - else - R.id.center_controls_external - ).addView(centerControls) - updateButtonSize(newConfig.orientation) + findViewById(if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + R.id.center_controls_bar + } else { + R.id.center_controls_external + }).addView(centerControls) + updateButtonSize(orientation) + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + handleOrientationChange(newConfig.orientation) } } \ No newline at end of file diff --git a/app/src/main/res/layout/audio_exo_styled_player_control_view.xml b/app/src/main/res/layout/audio_exo_styled_player_control_view.xml index eb40f9a..7fdd111 100644 --- a/app/src/main/res/layout/audio_exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/audio_exo_styled_player_control_view.xml @@ -26,6 +26,7 @@ android:layout_gravity="center_horizontal" android:background="@android:color/transparent" android:gravity="center" + android:layoutDirection="ltr" android:padding="@dimen/exo_styled_controls_padding" android:layout_marginBottom="-40dp" android:clipToPadding="false"> diff --git a/app/src/main/res/layout/exo_center_controls.xml b/app/src/main/res/layout/exo_center_controls.xml index f4edaa5..b61b0b4 100644 --- a/app/src/main/res/layout/exo_center_controls.xml +++ b/app/src/main/res/layout/exo_center_controls.xml @@ -8,6 +8,7 @@ android:layout_gravity="center" android:background="@android:color/transparent" android:gravity="center" + android:layoutDirection="ltr" android:padding="@dimen/exo_styled_controls_padding" android:clipToPadding="false">