Merge pull request #1122 from KotlinGeekDev/conditional-rotation
Re-enable tap to fullscreen behaviour with stricter orientation checks.
This commit is contained in:
+5
-4
@@ -126,6 +126,7 @@ fun ZoomableContentView(
|
|||||||
|
|
||||||
val isLandscapeMode = DeviceUtils.isLandscapeMetric(LocalContext.current)
|
val isLandscapeMode = DeviceUtils.isLandscapeMetric(LocalContext.current)
|
||||||
val isFoldableOrLarge = DeviceUtils.windowIsLarge(windowSize = currentWindowSize, isInLandscapeMode = isLandscapeMode)
|
val isFoldableOrLarge = DeviceUtils.windowIsLarge(windowSize = currentWindowSize, isInLandscapeMode = isLandscapeMode)
|
||||||
|
val isOrientationLocked = DeviceUtils.screenOrientationIsLocked(LocalContext.current)
|
||||||
|
|
||||||
val contentScale =
|
val contentScale =
|
||||||
if (isFiniteHeight) {
|
if (isFiniteHeight) {
|
||||||
@@ -160,9 +161,9 @@ fun ZoomableContentView(
|
|||||||
nostrUriCallback = content.uri,
|
nostrUriCallback = content.uri,
|
||||||
onDialog = {
|
onDialog = {
|
||||||
dialogOpen = true
|
dialogOpen = true
|
||||||
// if (!isFoldableOrLarge) {
|
if (!isFoldableOrLarge && !isOrientationLocked) {
|
||||||
// DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||||
// }
|
}
|
||||||
},
|
},
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
@@ -200,7 +201,7 @@ fun ZoomableContentView(
|
|||||||
images,
|
images,
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
dialogOpen = false
|
dialogOpen = false
|
||||||
// if (!isFoldableOrLarge) DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
if (!isFoldableOrLarge && !isOrientationLocked) DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||||
},
|
},
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ package com.vitorpamplona.amethyst.ui.components.util
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.provider.Settings
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.window.core.layout.WindowHeightSizeClass
|
import androidx.window.core.layout.WindowHeightSizeClass
|
||||||
@@ -38,6 +40,31 @@ object DeviceUtils {
|
|||||||
*/
|
*/
|
||||||
fun isLandscapeMetric(context: Context): Boolean = context.resources.displayMetrics.heightPixels < context.resources.displayMetrics.widthPixels
|
fun isLandscapeMetric(context: Context): Boolean = context.resources.displayMetrics.heightPixels < context.resources.displayMetrics.widthPixels
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the device's orientation is set to locked.
|
||||||
|
*
|
||||||
|
* Credits: NewPipe devs
|
||||||
|
*/
|
||||||
|
fun screenOrientationIsLocked(context: Context): Boolean {
|
||||||
|
// 1: Screen orientation changes using accelerometer
|
||||||
|
// 0: Screen orientation is locked
|
||||||
|
// if the accelerometer sensor is missing completely, assume locked orientation
|
||||||
|
return (
|
||||||
|
Settings.System.getInt(
|
||||||
|
context.contentResolver,
|
||||||
|
Settings.System.ACCELEROMETER_ROTATION,
|
||||||
|
0,
|
||||||
|
) == 0 ||
|
||||||
|
!context.packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the device's orientation. This works even if the device's orientation
|
||||||
|
* is set to locked.
|
||||||
|
* Thus, to prevent unwanted behaviour,
|
||||||
|
* it's use can be guarded by conditions such as [screenOrientationIsLocked].
|
||||||
|
*/
|
||||||
fun changeDeviceOrientation(
|
fun changeDeviceOrientation(
|
||||||
isInLandscape: Boolean,
|
isInLandscape: Boolean,
|
||||||
currentActivity: Activity,
|
currentActivity: Activity,
|
||||||
|
|||||||
Reference in New Issue
Block a user