Merge pull request #1801 from Bnyro/master

fix auto fullscreen
This commit is contained in:
Bnyro 2022-11-11 17:43:25 +01:00 committed by GitHub
commit 7bc6215cb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 26 deletions

View File

@ -59,11 +59,7 @@ class MainActivity : BaseActivity() {
autoRotationEnabled = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_ROTATION, false)
// enable auto rotation if turned on
requestedOrientation = if (autoRotationEnabled) {
ActivityInfo.SCREEN_ORIENTATION_USER
} else {
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
}
requestOrientationChange()
// start service that gets called on closure
try {
@ -160,6 +156,17 @@ class MainActivity : BaseActivity() {
loadIntentData()
}
/**
* Rotate according to the preference
*/
fun requestOrientationChange() {
requestedOrientation = if (autoRotationEnabled) {
ActivityInfo.SCREEN_ORIENTATION_USER
} else {
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
}
}
/**
* Show a break reminder when watched too long
*/

View File

@ -154,7 +154,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
/**
* user preferences
*/
private var token = PreferenceHelper.getToken()
private val token = PreferenceHelper.getToken()
private var videoShownInExternalPlayer = false
/**
@ -186,7 +186,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
return binding.root
}
@SuppressLint("SourceLockedOrientationActivity")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
context?.hideKeyboard(view)
@ -194,17 +193,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
// clear the playing queue
PlayingQueue.clear()
setUserPrefs()
val mainActivity = activity as MainActivity
if (PlayerHelper.autoRotationEnabled) {
// enable auto rotation
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
onConfigurationChanged(resources.configuration)
} else {
// go to portrait mode
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
}
changeOrientationMode()
createExoPlayer()
initializeTransitionLayout()
@ -224,14 +213,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
Handler(Looper.getMainLooper()).postDelayed(this::showBottomBar, 100)
}
private fun setUserPrefs() {
token = PreferenceHelper.getToken()
// save whether auto rotation is enabled
// save whether related streams are enabled
}
@SuppressLint("ClickableViewAccessibility")
private fun initializeTransitionLayout() {
val mainActivity = activity as MainActivity
@ -268,10 +249,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
viewModel.isMiniPlayerVisible.value = true
exoPlayerView.useController = false
mainMotionLayout.progress = 1F
(activity as MainActivity).requestOrientationChange()
} else if (currentId == sId) {
viewModel.isMiniPlayerVisible.value = false
exoPlayerView.useController = true
mainMotionLayout.progress = 0F
changeOrientationMode()
}
}
@ -1303,6 +1286,22 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
}
}
/**
* Use the sensor mode if auto fullscreen is enabled
*/
@SuppressLint("SourceLockedOrientationActivity")
private fun changeOrientationMode() {
val mainActivity = activity as MainActivity
if (PlayerHelper.autoRotationEnabled) {
// enable auto rotation
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
onConfigurationChanged(resources.configuration)
} else {
// go to portrait mode
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
}
}
override fun onCaptionsClicked() {
if (!this@PlayerFragment::streams.isInitialized ||
streams.subtitles == null ||