Fixed crash on Android 10 related to showing and hiding system UI when entering fullscreen. Made Platform comments the default.

This commit is contained in:
Koen J 2024-09-03 19:59:27 +02:00
parent e8a79c87ab
commit c4ce671a87
6 changed files with 62 additions and 22 deletions

View File

@ -77,10 +77,14 @@ class AdvancedOrientationListener(private val activity: Activity, private val li
lastStableOrientation = newOrientation lastStableOrientation = newOrientation
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
delay(stabilityThresholdTime) try {
if (newOrientation == lastStableOrientation) { delay(stabilityThresholdTime)
lastOrientation = newOrientation if (newOrientation == lastStableOrientation) {
onOrientationChanged.emit(newOrientation) lastOrientation = newOrientation
onOrientationChanged.emit(newOrientation)
}
} catch (e: Throwable) {
Logger.i(TAG, "Failed to trigger onOrientationChanged", e)
} }
} }
} }
@ -111,4 +115,8 @@ class AdvancedOrientationListener(private val activity: Activity, private val li
fun stopListening() { fun stopListening() {
sensorManager.unregisterListener(sensorListener) sensorManager.unregisterListener(sensorListener)
} }
companion object {
private val TAG = "AdvancedOrientationListener"
}
} }

View File

@ -487,7 +487,7 @@ class Settings : FragmentedStorageFileJson() {
class CommentSettings { class CommentSettings {
@FormField(R.string.default_comment_section, FieldForm.DROPDOWN, -1, 0) @FormField(R.string.default_comment_section, FieldForm.DROPDOWN, -1, 0)
@DropdownFieldOptionsId(R.array.comment_sections) @DropdownFieldOptionsId(R.array.comment_sections)
var defaultCommentSection: Int = 0; var defaultCommentSection: Int = 1;
@FormField(R.string.bad_reputation_comments_fading, FieldForm.TOGGLE, R.string.bad_reputation_comments_fading_description, 0) @FormField(R.string.bad_reputation_comments_fading, FieldForm.TOGGLE, R.string.bad_reputation_comments_fading_description, 0)
var badReputationCommentsFading: Boolean = true; var badReputationCommentsFading: Boolean = true;

View File

@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo
import android.hardware.SensorManager import android.hardware.SensorManager
import android.view.OrientationEventListener import android.view.OrientationEventListener
import com.futo.platformplayer.constructs.Event1 import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.logging.Logger
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -34,10 +35,14 @@ class SimpleOrientationListener(
lastStableOrientation = newOrientation lastStableOrientation = newOrientation
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
delay(stabilityThresholdTime) try {
if (newOrientation == lastStableOrientation) { delay(stabilityThresholdTime)
lastOrientation = newOrientation if (newOrientation == lastStableOrientation) {
onOrientationChanged.emit(newOrientation) lastOrientation = newOrientation
onOrientationChanged.emit(newOrientation)
}
} catch (e: Throwable) {
Logger.i(TAG, "Failed to trigger onOrientationChanged", e)
} }
} }
} }
@ -52,4 +57,8 @@ class SimpleOrientationListener(
fun stopListening() { fun stopListening() {
orientationListener.disable() orientationListener.disable()
} }
companion object {
private val TAG = "SimpleOrientationListener"
}
} }

View File

@ -147,8 +147,6 @@ fun InputStream.copyToOutputStream(inputStreamLength: Long, outputStream: Output
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun Activity.setNavigationBarColorAndIcons() { fun Activity.setNavigationBarColorAndIcons() {
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.black); window.navigationBarColor = ContextCompat.getColor(this, android.R.color.black);
if (Settings.instance.playback.allowVideoToGoUnderCutout)
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS); window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);

View File

@ -14,6 +14,7 @@ import android.os.StrictMode.VmPolicy
import android.util.Log import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.view.View import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResult
@ -253,6 +254,8 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
setNavigationBarColorAndIcons(); setNavigationBarColorAndIcons();
if (Settings.instance.playback.allowVideoToGoUnderCutout)
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
runBlocking { runBlocking {
StatePlatform.instance.updateAvailableClients(this@MainActivity); StatePlatform.instance.updateAvailableClients(this@MainActivity);

View File

@ -2,6 +2,7 @@ package com.futo.platformplayer.fragment.mainactivity.main
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.Log import android.util.Log
@ -10,6 +11,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowInsets import android.view.WindowInsets
import android.view.WindowInsetsController import android.view.WindowInsetsController
import android.view.WindowManager
import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@ -426,22 +428,42 @@ class VideoDetailFragment : MainFragment {
onMaximized.clear(); onMaximized.clear();
} }
private fun hideSystemUI() { private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(requireActivity().window, false) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity?.window?.insetsController?.let { controller -> WindowCompat.setDecorFitsSystemWindows(requireActivity().window, false)
controller.hide(WindowInsets.Type.statusBars()) activity?.window?.insetsController?.let { controller ->
controller.hide(WindowInsets.Type.systemBars()) controller.hide(WindowInsets.Type.statusBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE controller.hide(WindowInsets.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
@Suppress("DEPRECATION")
activity?.window?.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
@Suppress("DEPRECATION")
activity?.window?.decorView?.systemUiVisibility = (
View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
)
} }
} }
private fun showSystemUI() { private fun showSystemUI() {
WindowCompat.setDecorFitsSystemWindows(requireActivity().window, true) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity?.window?.insetsController?.let { controller -> WindowCompat.setDecorFitsSystemWindows(requireActivity().window, true)
controller.show(WindowInsets.Type.statusBars()) activity?.window?.insetsController?.let { controller ->
controller.show(WindowInsets.Type.systemBars()) controller.show(WindowInsets.Type.statusBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT controller.show(WindowInsets.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
}
} else {
@Suppress("DEPRECATION")
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
@Suppress("DEPRECATION")
activity?.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
} }
} }