diff --git a/app/src/main/java/com/futo/platformplayer/Settings.kt b/app/src/main/java/com/futo/platformplayer/Settings.kt index 67fa246c..784c2c36 100644 --- a/app/src/main/java/com/futo/platformplayer/Settings.kt +++ b/app/src/main/java/com/futo/platformplayer/Settings.kt @@ -478,18 +478,22 @@ class Settings : FragmentedStorageFileJson() { @DropdownFieldOptionsId(R.array.rotation_zone) var rotationZone: Int = 2; - @FormField(R.string.full_autorotate_lock, FieldForm.TOGGLE, R.string.full_autorotate_lock_description, 16) + @FormField(R.string.stability_threshold_time, FieldForm.DROPDOWN, R.string.stability_threshold_time_description, 16) + @DropdownFieldOptionsId(R.array.rotation_threshold_time) + var stabilityThresholdTime: Int = 1; + + @FormField(R.string.full_autorotate_lock, FieldForm.TOGGLE, R.string.full_autorotate_lock_description, 17) var fullAutorotateLock: Boolean = false; - @FormField(R.string.prefer_webm, FieldForm.TOGGLE, R.string.prefer_webm_description, 17) + @FormField(R.string.prefer_webm, FieldForm.TOGGLE, R.string.prefer_webm_description, 18) var preferWebmVideo: Boolean = false; - @FormField(R.string.prefer_webm_audio, FieldForm.TOGGLE, R.string.prefer_webm_audio_description, 18) + @FormField(R.string.prefer_webm_audio, FieldForm.TOGGLE, R.string.prefer_webm_audio_description, 19) var preferWebmAudio: Boolean = false; - @FormField(R.string.allow_under_cutout, FieldForm.TOGGLE, R.string.allow_under_cutout_description, 19) + @FormField(R.string.allow_under_cutout, FieldForm.TOGGLE, R.string.allow_under_cutout_description, 20) var allowVideoToGoUnderCutout: Boolean = true; - @FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 20) + @FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 21) var autoplay: Boolean = false; } diff --git a/app/src/main/java/com/futo/platformplayer/SimpleOrientationListener.kt b/app/src/main/java/com/futo/platformplayer/SimpleOrientationListener.kt index a289f02b..9fc4367b 100644 --- a/app/src/main/java/com/futo/platformplayer/SimpleOrientationListener.kt +++ b/app/src/main/java/com/futo/platformplayer/SimpleOrientationListener.kt @@ -8,6 +8,7 @@ import com.futo.platformplayer.constructs.Event1 import com.futo.platformplayer.logging.Logger import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -17,13 +18,23 @@ class SimpleOrientationListener( ) { private var lastOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED private var lastStableOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED - private val stabilityThresholdTime = 500L + private var _currentJob: Job? = null val onOrientationChanged = Event1() private val orientationListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_UI) { override fun onOrientationChanged(orientation: Int) { //val rotationZone = 45 + val stabilityThresholdTime = when (Settings.instance.playback.stabilityThresholdTime) { + 0 -> 100L + 1 -> 500L + 2 -> 750L + 3 -> 1000L + 4 -> 1500L + 5 -> 2000L + else -> 500L + } + val rotationZone = when (Settings.instance.playback.rotationZone) { 0 -> 15 1 -> 30 @@ -42,7 +53,8 @@ class SimpleOrientationListener( if (newOrientation != lastStableOrientation) { lastStableOrientation = newOrientation - lifecycleScope.launch(Dispatchers.Main) { + _currentJob?.cancel() + _currentJob = lifecycleScope.launch(Dispatchers.Main) { try { delay(stabilityThresholdTime) if (newOrientation == lastStableOrientation) { @@ -63,6 +75,8 @@ class SimpleOrientationListener( } fun stopListening() { + _currentJob?.cancel() + _currentJob = null orientationListener.disable() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae3e1162..5097d091 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -377,6 +377,8 @@ Allow app to flip into reverse portrait Rotation zone Specify the sensitivity of rotation zones (decrease to make less sensitive) + Stability threshold time + Specify the duration the orientation needs to be the same to trigger a rotation Prefer Webm Video Codecs If player should prefer Webm codecs (vp9/opus) over mp4 codecs (h264/AAC), may result in worse compatibility. Full auto rotate lock @@ -968,4 +970,12 @@ 30 45 + + 100 + 500 + 750 + 1000 + 1500 + 2000 + \ No newline at end of file