diff --git a/app/src/main/java/org/jellyfin/mobile/MainActivity.kt b/app/src/main/java/org/jellyfin/mobile/MainActivity.kt index 3a3febf5..c1f3bd99 100644 --- a/app/src/main/java/org/jellyfin/mobile/MainActivity.kt +++ b/app/src/main/java/org/jellyfin/mobile/MainActivity.kt @@ -8,7 +8,6 @@ import android.graphics.Color import android.os.Bundle import android.os.IBinder import android.provider.Settings -import android.view.OrientationEventListener import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.activity.SystemBarStyle @@ -32,7 +31,6 @@ import org.jellyfin.mobile.utils.BackPressInterceptor import org.jellyfin.mobile.utils.BluetoothPermissionHelper import org.jellyfin.mobile.utils.Constants import org.jellyfin.mobile.utils.PermissionRequestHelper -import org.jellyfin.mobile.utils.SmartOrientationListener import org.jellyfin.mobile.utils.extensions.replaceFragment import org.jellyfin.mobile.utils.isWebViewSupported import org.jellyfin.mobile.webapp.RemotePlayerService @@ -61,8 +59,6 @@ class MainActivity : AppCompatActivity() { } } - private val orientationListener: OrientationEventListener by lazy { SmartOrientationListener(this) } - /** * Passes back press events onto the currently visible [Fragment] if it implements the [BackPressInterceptor] interface. * @@ -145,11 +141,6 @@ class MainActivity : AppCompatActivity() { chromecast.initializePlugin(this) } - override fun onStart() { - super.onStart() - orientationListener.enable() - } - private fun handleServerState(state: ServerState) { with(supportFragmentManager) { val currentFragment = findFragmentById(R.id.fragment_container) @@ -199,11 +190,6 @@ class MainActivity : AppCompatActivity() { } } - override fun onStop() { - super.onStop() - orientationListener.disable() - } - override fun onDestroy() { unbindService(serviceConnection) chromecast.destroy() diff --git a/app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt b/app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt index 0f33bc11..cbba99ad 100644 --- a/app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt +++ b/app/src/main/java/org/jellyfin/mobile/app/AppPreferences.kt @@ -96,9 +96,6 @@ class AppPreferences(context: Context) { val videoPlayerType: String get() = sharedPreferences.getString(Constants.PREF_VIDEO_PLAYER_TYPE, VideoPlayerType.EXO_PLAYER)!! - val exoPlayerStartLandscapeVideoInLandscape: Boolean - get() = sharedPreferences.getBoolean(Constants.PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE, false) - val exoPlayerAllowSwipeGestures: Boolean get() = sharedPreferences.getBoolean(Constants.PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES, true) diff --git a/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt b/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt index f26ee625..284b2ef7 100644 --- a/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt +++ b/app/src/main/java/org/jellyfin/mobile/events/ActivityEventHandler.kt @@ -2,7 +2,6 @@ package org.jellyfin.mobile.events import android.content.ActivityNotFoundException import android.content.Intent -import android.content.pm.ActivityInfo import android.os.Bundle import androidx.core.net.toUri import androidx.lifecycle.Lifecycle @@ -48,12 +47,9 @@ class ActivityEventHandler( is ActivityEvent.ChangeFullscreen -> { val fullscreenHelper = PlayerFullscreenHelper(window) if (event.isFullscreen) { - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE fullscreenHelper.enableFullscreen() window.setBackgroundDrawable(null) } else { - // Reset screen orientation - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED fullscreenHelper.disableFullscreen() // Reset window background color window.setBackgroundDrawableResource(R.color.theme_background) diff --git a/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerFragment.kt b/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerFragment.kt index 3d5487cc..e5acafd9 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerFragment.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerFragment.kt @@ -2,7 +2,6 @@ package org.jellyfin.mobile.player.ui import android.app.Activity import android.app.PictureInPictureParams -import android.content.pm.ActivityInfo import android.content.res.Configuration import android.graphics.Rect import android.os.Build @@ -10,7 +9,6 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.LayoutInflater -import android.view.OrientationEventListener import android.view.View import android.view.ViewGroup import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE @@ -43,7 +41,6 @@ import org.jellyfin.mobile.utils.Constants import org.jellyfin.mobile.utils.Constants.DEFAULT_CONTROLS_TIMEOUT_MS import org.jellyfin.mobile.utils.Constants.PIP_MAX_RATIONAL import org.jellyfin.mobile.utils.Constants.PIP_MIN_RATIONAL -import org.jellyfin.mobile.utils.SmartOrientationListener import org.jellyfin.mobile.utils.brightness import org.jellyfin.mobile.utils.extensions.aspectRational import org.jellyfin.mobile.utils.extensions.getParcelableCompat @@ -79,16 +76,6 @@ class PlayerFragment : Fragment(), BackPressInterceptor { private val currentVideoStream: MediaStream? get() = viewModel.mediaSourceOrNull?.selectedVideoStream - /** - * Listener that watches the current device orientation. - * It makes sure that the orientation sensor can still be used (if enabled) - * after toggling the orientation through the fullscreen button. - * - * If the requestedOrientation was reset directly after setting it in the fullscreenSwitcher click handler, - * the orientation would get reverted before the user had any chance to rotate the device to the desired position. - */ - private val orientationListener: OrientationEventListener by lazy { SmartOrientationListener(requireActivity()) } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -119,9 +106,6 @@ class PlayerFragment : Fragment(), BackPressInterceptor { if (mediaSource.selectedVideoStream?.isLandscape == false) { // For portrait videos, immediately enable fullscreen playerFullscreenHelper.enableFullscreen() - } else if (appPreferences.exoPlayerStartLandscapeVideoInLandscape) { - // Auto-switch to landscape for landscape videos if enabled - requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE } // Update title and player menus @@ -209,7 +193,7 @@ class PlayerFragment : Fragment(), BackPressInterceptor { // Disable controller animations playerView.setControllerAnimationEnabled(false) - playerLockScreenHelper = PlayerLockScreenHelper(this, playerBinding, orientationListener) + playerLockScreenHelper = PlayerLockScreenHelper(this, playerBinding) playerGestureHelper = PlayerGestureHelper(this, playerBinding, playerLockScreenHelper) // Handle fullscreen switcher @@ -218,11 +202,6 @@ class PlayerFragment : Fragment(), BackPressInterceptor { } } - override fun onStart() { - super.onStart() - orientationListener.enable() - } - override fun onResume() { super.onResume() @@ -259,25 +238,10 @@ class PlayerFragment : Fragment(), BackPressInterceptor { } /** - * Toggle fullscreen. - * - * If playing a portrait video, this just hides the status and navigation bars. - * For landscape videos, additionally the screen gets rotated. + * Toggle fullscreen */ private fun toggleFullscreen() { - val videoTrack = currentVideoStream - if (videoTrack == null || videoTrack.isLandscape) { - val current = resources.configuration.orientation - requireActivity().requestedOrientation = when (current) { - Configuration.ORIENTATION_PORTRAIT -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - else -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - } - // No need to call playerFullscreenHelper in this case, - // since the configuration change triggers updateFullscreenState, - // which does it for us. - } else { - playerFullscreenHelper.toggleFullscreen() - } + playerFullscreenHelper.toggleFullscreen() } /** @@ -413,11 +377,6 @@ class PlayerFragment : Fragment(), BackPressInterceptor { } } - override fun onStop() { - super.onStop() - orientationListener.disable() - } - override fun onDestroyView() { super.onDestroyView() // Detach player from PlayerView @@ -432,8 +391,6 @@ class PlayerFragment : Fragment(), BackPressInterceptor { override fun onDestroy() { super.onDestroy() with(requireActivity()) { - // Reset screen orientation - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED playerFullscreenHelper.disableFullscreen() // Reset screen brightness window.brightness = BRIGHTNESS_OVERRIDE_NONE diff --git a/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerLockScreenHelper.kt b/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerLockScreenHelper.kt index f10b061f..c3aa1631 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerLockScreenHelper.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/ui/PlayerLockScreenHelper.kt @@ -1,20 +1,15 @@ package org.jellyfin.mobile.player.ui -import android.content.pm.ActivityInfo -import android.view.OrientationEventListener import android.widget.ImageButton import androidx.core.view.isVisible import androidx.media3.ui.PlayerView import org.jellyfin.mobile.databinding.FragmentPlayerBinding import org.jellyfin.mobile.utils.AndroidVersion import org.jellyfin.mobile.utils.Constants -import org.jellyfin.mobile.utils.extensions.lockOrientation -import org.jellyfin.mobile.utils.isAutoRotateOn class PlayerLockScreenHelper( private val playerFragment: PlayerFragment, private val playerBinding: FragmentPlayerBinding, - private val orientationListener: OrientationEventListener, ) { private val playerView: PlayerView by playerBinding::playerView private val unlockScreenButton: ImageButton by playerBinding::unlockScreenButton @@ -35,18 +30,12 @@ class PlayerLockScreenHelper( fun lockScreen() { playerView.useController = false - orientationListener.disable() - playerFragment.requireActivity().lockOrientation() peekUnlockButton() } private fun unlockScreen() { hideUnlockButton() val activity = playerFragment.requireActivity() - if (activity.isAutoRotateOn()) { - activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED - } - orientationListener.enable() if (!AndroidVersion.isAtLeastN || !activity.isInPictureInPictureMode) { playerView.useController = true playerView.apply { diff --git a/app/src/main/java/org/jellyfin/mobile/settings/SettingsFragment.kt b/app/src/main/java/org/jellyfin/mobile/settings/SettingsFragment.kt index 12753cc4..bd4e7402 100644 --- a/app/src/main/java/org/jellyfin/mobile/settings/SettingsFragment.kt +++ b/app/src/main/java/org/jellyfin/mobile/settings/SettingsFragment.kt @@ -132,10 +132,6 @@ class SettingsFragment : Fragment(), BackPressInterceptor { externalPlayerChoicePreference.enabled = selection == VideoPlayerType.EXTERNAL_PLAYER } } - startLandscapeVideoInLandscapePreference = checkBox(Constants.PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE) { - titleRes = R.string.pref_exoplayer_start_landscape_video_in_landscape - enabled = appPreferences.videoPlayerType == VideoPlayerType.EXO_PLAYER - } swipeGesturesPreference = checkBox(Constants.PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES) { titleRes = R.string.pref_exoplayer_allow_brightness_volume_gesture enabled = appPreferences.videoPlayerType == VideoPlayerType.EXO_PLAYER diff --git a/app/src/main/java/org/jellyfin/mobile/utils/Constants.kt b/app/src/main/java/org/jellyfin/mobile/utils/Constants.kt index 315e63a4..8a59a440 100644 --- a/app/src/main/java/org/jellyfin/mobile/utils/Constants.kt +++ b/app/src/main/java/org/jellyfin/mobile/utils/Constants.kt @@ -32,7 +32,6 @@ object Constants { const val PREF_DOWNLOAD_METHOD = "pref_download_method" const val PREF_MUSIC_NOTIFICATION_ALWAYS_DISMISSIBLE = "pref_music_notification_always_dismissible" const val PREF_VIDEO_PLAYER_TYPE = "pref_video_player_type" - const val PREF_EXOPLAYER_START_LANDSCAPE_VIDEO_IN_LANDSCAPE = "pref_exoplayer_start_landscape_video_in_landscape" const val PREF_EXOPLAYER_ALLOW_SWIPE_GESTURES = "pref_exoplayer_allow_swipe_gestures" const val PREF_EXOPLAYER_ALLOW_PRESS_SPEED_UP = "pref_exoplayer_allow_press_speed_up" const val PREF_EXOPLAYER_REMEMBER_BRIGHTNESS = "pref_exoplayer_remember_brightness" diff --git a/app/src/main/java/org/jellyfin/mobile/utils/SmartOrientationListener.kt b/app/src/main/java/org/jellyfin/mobile/utils/SmartOrientationListener.kt deleted file mode 100644 index ff679a9e..00000000 --- a/app/src/main/java/org/jellyfin/mobile/utils/SmartOrientationListener.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.jellyfin.mobile.utils - -import android.app.Activity -import android.content.pm.ActivityInfo -import android.view.OrientationEventListener - -/** - * Listener that watches the current device orientation. - * It makes sure that the orientation sensor can still be used (if enabled) - * after toggling the orientation manually. - */ -class SmartOrientationListener(private val activity: Activity) : OrientationEventListener(activity) { - override fun onOrientationChanged(orientation: Int) { - if (!activity.isAutoRotateOn()) return - - val isAtTarget = when (activity.requestedOrientation) { - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> orientation in Constants.ORIENTATION_PORTRAIT_RANGE - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE -> orientation in Constants.ORIENTATION_LANDSCAPE_RANGE - else -> false - } - if (isAtTarget) { - // Reset to unspecified orientation - activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED - } - } -} diff --git a/app/src/main/java/org/jellyfin/mobile/utils/extensions/Activity.kt b/app/src/main/java/org/jellyfin/mobile/utils/extensions/Activity.kt deleted file mode 100644 index f7833fa0..00000000 --- a/app/src/main/java/org/jellyfin/mobile/utils/extensions/Activity.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.jellyfin.mobile.utils.extensions - -import android.app.Activity -import android.content.pm.ActivityInfo -import android.graphics.Point -import android.view.Surface - -@Suppress("DEPRECATION") -fun Activity.lockOrientation() { - val display = windowManager.defaultDisplay - val size = Point().also(display::getSize) - val height = size.y - val width = size.x - requestedOrientation = when (display.rotation) { - Surface.ROTATION_90 -> if (width > height) ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE else ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT - Surface.ROTATION_180 -> if (height > width) ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE - Surface.ROTATION_270 -> if (width > height) ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE else ActivityInfo.SCREEN_ORIENTATION_PORTRAIT - else -> if (height > width) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE - } -} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5c150722..02fc0efa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,7 +101,6 @@ The default HTML video player from the Web UI Based on ExoPlayer, supports more video formats and codecs, and is more integrated into the OS External video playback apps like MX Player and VLC - Start landscape mode videos in landscape orientation Brightness and volume gestures Remember display brightness Hold to speed up