mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-05-01 07:04:35 +02:00
Merge branch 'force-leave-landscape-tweak' into 'master'
Force leave landscape tweak See merge request videostreaming/grayjay!59
This commit is contained in:
commit
ab360ed6f6
@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.fragment.mainactivity.main
|
package com.futo.platformplayer.fragment.mainactivity.main
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
@ -84,8 +85,6 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
|
|
||||||
private var _landscapeOrientationListener: LandscapeOrientationListener? = null
|
private var _landscapeOrientationListener: LandscapeOrientationListener? = null
|
||||||
private var _portraitOrientationListener: PortraitOrientationListener? = null
|
private var _portraitOrientationListener: PortraitOrientationListener? = null
|
||||||
private var _lastSetOrientation: Int = Configuration.ORIENTATION_UNDEFINED
|
|
||||||
private var _ignoreNextNewOrientation = false
|
|
||||||
|
|
||||||
fun nextVideo() {
|
fun nextVideo() {
|
||||||
_viewDetail?.nextVideo(true, true, true);
|
_viewDetail?.nextVideo(true, true, true);
|
||||||
@ -102,22 +101,19 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
) < resources.getInteger(R.integer.column_width_dp) * 2
|
) < resources.getInteger(R.integer.column_width_dp) * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isAutoRotateEnabled(): Boolean {
|
||||||
|
return android.provider.Settings.System.getInt(
|
||||||
|
context?.contentResolver,
|
||||||
|
android.provider.Settings.System.ACCELEROMETER_ROTATION, 0
|
||||||
|
) == 1
|
||||||
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
val isLandscapeVideo: Boolean = _viewDetail?.isLandscapeVideo() ?: false
|
val isLandscapeVideo: Boolean = _viewDetail?.isLandscapeVideo() ?: false
|
||||||
|
|
||||||
val isSmallWindow = isSmallWindow()
|
val isSmallWindow = isSmallWindow()
|
||||||
|
|
||||||
val temp = _lastSetOrientation
|
|
||||||
|
|
||||||
if (_ignoreNextNewOrientation) {
|
|
||||||
_ignoreNextNewOrientation = false
|
|
||||||
} else {
|
|
||||||
// the device has rotated so update our state tracking what the physical orientation of the device is
|
|
||||||
_lastSetOrientation = newConfig.orientation
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isSmallWindow
|
isSmallWindow
|
||||||
&& newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
|
&& newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
@ -130,7 +126,6 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
&& isFullscreen
|
&& isFullscreen
|
||||||
&& !Settings.instance.playback.fullscreenPortrait
|
&& !Settings.instance.playback.fullscreenPortrait
|
||||||
&& newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
|
&& newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||||
&& temp == Configuration.ORIENTATION_LANDSCAPE
|
|
||||||
&& isLandscapeVideo
|
&& isLandscapeVideo
|
||||||
) {
|
) {
|
||||||
_viewDetail?.setFullscreen(false)
|
_viewDetail?.setFullscreen(false)
|
||||||
@ -170,21 +165,15 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
val isLandscapeVideo: Boolean = _viewDetail?.isLandscapeVideo() ?: false
|
val isLandscapeVideo: Boolean = _viewDetail?.isLandscapeVideo() ?: false
|
||||||
|
|
||||||
val isSmallWindow = isSmallWindow()
|
val isSmallWindow = isSmallWindow()
|
||||||
|
val autoRotateEnabled = isAutoRotateEnabled()
|
||||||
val autoRotateEnabled = android.provider.Settings.System.getInt(
|
|
||||||
context?.contentResolver,
|
|
||||||
android.provider.Settings.System.ACCELEROMETER_ROTATION, 0
|
|
||||||
) == 1
|
|
||||||
|
|
||||||
// For small windows if the device isn't landscape right now and full screen portrait isn't allowed then we should force landscape
|
// For small windows if the device isn't landscape right now and full screen portrait isn't allowed then we should force landscape
|
||||||
if (isSmallWindow && isFullscreen && !isFullScreenPortraitAllowed && _lastSetOrientation != Configuration.ORIENTATION_LANDSCAPE && !rotationLock && isLandscapeVideo) {
|
if (isSmallWindow && isFullscreen && !isFullScreenPortraitAllowed && resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT && !rotationLock && isLandscapeVideo) {
|
||||||
if (Settings.instance.playback.forceAllowFullScreenRotation) {
|
if (Settings.instance.playback.forceAllowFullScreenRotation) {
|
||||||
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||||
} else {
|
} else {
|
||||||
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
}
|
}
|
||||||
// the next orientation change will not reflect the device because we are manually setting the orientation to landscape
|
|
||||||
_ignoreNextNewOrientation = true
|
|
||||||
if (autoRotateEnabled
|
if (autoRotateEnabled
|
||||||
) {
|
) {
|
||||||
// start listening for the device to rotate to landscape
|
// start listening for the device to rotate to landscape
|
||||||
@ -193,19 +182,13 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For small windows if the device isn't in a portrait orientation and we're in the maximized state then we should force portrait
|
// For small windows if the device isn't in a portrait orientation and we're in the maximized state then we should force portrait
|
||||||
else if (isSmallWindow && !isMinimizingFromFullScreen && !isFullscreen && state == State.MAXIMIZED && _lastSetOrientation == Configuration.ORIENTATION_LANDSCAPE) {
|
// only do this if auto-rotate is on portrait is forced when leaving full screen for autorotate off
|
||||||
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
else if (isSmallWindow && !isMinimizingFromFullScreen && !isFullscreen && state == State.MAXIMIZED && resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && autoRotateEnabled) {
|
||||||
// the next orientation change will not reflect the device because we are manually setting the orientation to portrait
|
|
||||||
_ignoreNextNewOrientation = true
|
|
||||||
if (autoRotateEnabled
|
|
||||||
) {
|
|
||||||
// start listening for the device to rotate to portrait
|
// start listening for the device to rotate to portrait
|
||||||
// at which point we'll be able to set requestedOrientation to back to UNSPECIFIED
|
// at which point we'll be able to set requestedOrientation to back to UNSPECIFIED
|
||||||
_portraitOrientationListener?.enableListener()
|
_portraitOrientationListener?.enableListener()
|
||||||
} else {
|
a.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||||
// the rotation state resets to portrait when changing requestedOrientation
|
|
||||||
_lastSetOrientation = Configuration.ORIENTATION_PORTRAIT
|
|
||||||
}
|
|
||||||
} else if (rotationLock) {
|
} else if (rotationLock) {
|
||||||
_portraitOrientationListener?.disableListener()
|
_portraitOrientationListener?.disableListener()
|
||||||
_landscapeOrientationListener?.disableListener()
|
_landscapeOrientationListener?.disableListener()
|
||||||
@ -395,7 +378,6 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
// delay to make sure that the system auto rotate updates
|
// delay to make sure that the system auto rotate updates
|
||||||
delay(delayBeforeRemoveRotationLock)
|
delay(delayBeforeRemoveRotationLock)
|
||||||
_lastSetOrientation = Configuration.ORIENTATION_LANDSCAPE
|
|
||||||
updateOrientation()
|
updateOrientation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +386,6 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
// delay to make sure that the system auto rotate updates
|
// delay to make sure that the system auto rotate updates
|
||||||
delay(delayBeforeRemoveRotationLock)
|
delay(delayBeforeRemoveRotationLock)
|
||||||
_lastSetOrientation = Configuration.ORIENTATION_PORTRAIT
|
|
||||||
updateOrientation()
|
updateOrientation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -584,6 +565,11 @@ class VideoDetailFragment() : MainFragment() {
|
|||||||
showSystemUI()
|
showSystemUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// temporarily force the device to portrait if auto-rotate is disabled to prevent landscape when exiting full screen on a small device
|
||||||
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
|
if (!isFullscreen && isSmallWindow() && !isAutoRotateEnabled() && !isMinimizingFromFullScreen) {
|
||||||
|
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||||
|
}
|
||||||
updateOrientation();
|
updateOrientation();
|
||||||
_view?.allowMotion = !fullscreen;
|
_view?.allowMotion = !fullscreen;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user