mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-26 17:52:29 +01:00
Rotation:actually rotate if the device orientation is not locked.
This commit is contained in:
parent
38a9030963
commit
7326d6be93
@ -126,6 +126,7 @@ fun ZoomableContentView(
|
||||
|
||||
val isLandscapeMode = DeviceUtils.isLandscapeMetric(LocalContext.current)
|
||||
val isFoldableOrLarge = DeviceUtils.windowIsLarge(windowSize = currentWindowSize, isInLandscapeMode = isLandscapeMode)
|
||||
val isOrientationLocked = DeviceUtils.screenOrientationIsLocked(LocalContext.current)
|
||||
|
||||
val contentScale =
|
||||
if (isFiniteHeight) {
|
||||
@ -160,9 +161,9 @@ fun ZoomableContentView(
|
||||
nostrUriCallback = content.uri,
|
||||
onDialog = {
|
||||
dialogOpen = true
|
||||
// if (!isFoldableOrLarge) {
|
||||
// DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||
// }
|
||||
if (!isFoldableOrLarge && !isOrientationLocked) {
|
||||
DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||
}
|
||||
},
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
@ -200,7 +201,7 @@ fun ZoomableContentView(
|
||||
images,
|
||||
onDismiss = {
|
||||
dialogOpen = false
|
||||
// if (!isFoldableOrLarge) DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||
if (!isFoldableOrLarge && !isOrientationLocked) DeviceUtils.changeDeviceOrientation(isLandscapeMode, activity)
|
||||
},
|
||||
accountViewModel,
|
||||
)
|
||||
|
@ -23,6 +23,8 @@ package com.vitorpamplona.amethyst.ui.components.util
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.provider.Settings
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
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
|
||||
|
||||
/**
|
||||
* 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(
|
||||
isInLandscape: Boolean,
|
||||
currentActivity: Activity,
|
||||
|
Loading…
x
Reference in New Issue
Block a user