mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-02 08:58:23 +02:00
Remove the external config method and use the built-in Compose API.
Add some documentation.
This commit is contained in:
parent
23da02f932
commit
26a12f2dbe
@ -45,12 +45,10 @@ import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@ -129,8 +127,7 @@ fun ZoomableContentView(
|
||||
|
||||
val activity = LocalView.current.context.getActivity()
|
||||
|
||||
val orientation by snapshotFlow { DeviceUtils.getDeviceOrientation() }
|
||||
.collectAsState(initial = LocalConfiguration.current.orientation)
|
||||
val orientation = LocalConfiguration.current.orientation
|
||||
val currentWindowSize = currentWindowAdaptiveInfo().windowSizeClass
|
||||
|
||||
val detectedWindowSize =
|
||||
|
@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.ui.components.util
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.Resources
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.window.core.layout.WindowHeightSizeClass
|
||||
@ -31,18 +30,11 @@ import androidx.window.core.layout.WindowSizeClass
|
||||
import androidx.window.core.layout.WindowWidthSizeClass
|
||||
|
||||
object DeviceUtils {
|
||||
fun getDeviceOrientation(): Int {
|
||||
val config = Resources.getSystem().configuration
|
||||
return config.orientation
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative for determining if the device is
|
||||
* in landscape mode.
|
||||
* The [getDeviceOrientation] method could be used as well
|
||||
* to achieve the same purpose.
|
||||
* Credits: Newpipe devs
|
||||
* Tries to determine if the device is
|
||||
* in landscape mode, by using the [android.util.DisplayMetrics] API.
|
||||
*
|
||||
* Credits: NewPipe devs
|
||||
*/
|
||||
fun isLandscapeMetric(context: Context): Boolean = context.resources.displayMetrics.heightPixels < context.resources.displayMetrics.widthPixels
|
||||
|
||||
@ -59,6 +51,16 @@ object DeviceUtils {
|
||||
currentActivity.requestedOrientation = newOrientation
|
||||
}
|
||||
|
||||
/**
|
||||
* This method looks at the window in which the app resides,
|
||||
* and determines if it is large, while making sure not to be affected
|
||||
* by configuration changes(such as screen rotation),
|
||||
* as the device display metrics can be affected as well.
|
||||
*
|
||||
* It could be used as an approximation of the type of device(as is the case here),
|
||||
* though one ought to be careful about multi-window situations.
|
||||
*/
|
||||
|
||||
@Composable
|
||||
fun windowIsLarge(
|
||||
isInLandscapeMode: Boolean,
|
||||
|
Loading…
x
Reference in New Issue
Block a user