add isWear shortcut

This commit is contained in:
2026-09-15 14:45:23 +03:00
parent 4fa297ac6c
commit dbbfc6984c
8 changed files with 49 additions and 11 deletions
@@ -1,8 +1,11 @@
package ru.shadowsparky.gigawear.presentation
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.runtime.CompositionLocalProvider
import com.arkivanov.decompose.retainedComponent
import org.koin.android.ext.android.inject
import ru.shadowsparky.gigawear.presentation.auth.AuthScreen
@@ -10,6 +13,8 @@ import ru.shadowsparky.gigawear.presentation.chat.ChatScreen
import ru.shadowsparky.gigawear.presentation.nav.Child
import ru.shadowsparky.gigawear.presentation.routing.RoutingScreen
import ru.shadowsparky.ui.nav.Nav
import ru.shadowsparky.ui.theme.LocalColorSchemeProvider
import ru.shadowsparky.ui.theme.darkScheme
class MainActivity : ComponentActivity() {
private val rootFactory by inject<RootComponentFactory>()
@@ -18,11 +23,18 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
val root = retainedComponent { rootFactory.create(it) }
setContent {
Nav(root) { child, _ ->
when (child) {
is Child.MainChild -> ChatScreen(child.component)
is Child.AuthChild -> AuthScreen(child.component)
is Child.RoutingChild -> RoutingScreen(child.component)
val scheme = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
dynamicDarkColorScheme(this)
} else {
darkScheme
}
CompositionLocalProvider(LocalColorSchemeProvider provides scheme) {
Nav(root) { child, _ ->
when (child) {
is Child.MainChild -> ChatScreen(child.component)
is Child.AuthChild -> AuthScreen(child.component)
is Child.RoutingChild -> RoutingScreen(child.component)
}
}
}
}
@@ -1,4 +1,4 @@
package ru.shadowsparky.ui.components
package ru.shadowsparky.ui.util
import android.app.UiModeManager
import android.content.Context
@@ -15,3 +15,12 @@ actual fun isTv(): Boolean {
uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
}
}
@Composable
actual fun isWear(): Boolean {
val context = LocalContext.current
return remember(context) {
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_WATCH
}
}
@@ -12,11 +12,12 @@ import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
import dev.chrisbanes.haze.materials.HazeMaterials
import dev.chrisbanes.haze.rememberHazeState
import ru.shadowsparky.ui.components.isTv
import ru.shadowsparky.ui.util.isWear
internal val LocalBlurState = compositionLocalOf<BlurState?> { null }
@Composable
internal fun isBlurEnabled(): Boolean = !isTv()
internal fun isBlurEnabled(): Boolean = !isTv() && !isWear()
@Composable
internal fun rememberBlurState(): BlurState? {
@@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import ru.shadowsparky.ui.theme.getColorScheme
import ru.shadowsparky.ui.util.isWear
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
@@ -44,7 +45,7 @@ fun AlertContent(
}
}
MaterialExpressiveTheme(getColorScheme()) {
if (isTv()) {
if (isTv() || isWear()) {
BasicAlertDialog(
onDismissRequest = onDismissRequest,
modifier = modifier,
@@ -17,7 +17,7 @@ import androidx.compose.ui.unit.dp
import ru.shadowsparky.ui.blurSource
@Composable
expect fun isTv(): Boolean
fun isTv(): Boolean = ru.shadowsparky.ui.util.isTv()
/**
* LazyColumn — обходной путь для бага LazyColumn + contentPadding на Android TV.
@@ -0,0 +1,9 @@
package ru.shadowsparky.ui.util
import androidx.compose.runtime.Composable
@Composable
expect fun isTv(): Boolean
@Composable
expect fun isWear(): Boolean
@@ -1,6 +1,9 @@
package ru.shadowsparky.ui.components
package ru.shadowsparky.ui.util
import androidx.compose.runtime.Composable
@Composable
actual fun isTv(): Boolean = false
@Composable
actual fun isWear(): Boolean = false
@@ -1,6 +1,9 @@
package ru.shadowsparky.ui.components
package ru.shadowsparky.ui.util
import androidx.compose.runtime.Composable
@Composable
actual fun isTv(): Boolean = false
@Composable
actual fun isWear(): Boolean = false