fix: исправил лейаут и немного другого

This commit is contained in:
nm17 2023-06-03 18:51:32 +04:00
parent 270f934798
commit e1bb9de063
Signed by: nm17
GPG key ID: 3303B70C59145CD4
4 changed files with 68 additions and 34 deletions

View file

@ -77,6 +77,7 @@ import ru.nm17.narodmon.db.AppDatabase
import ru.nm17.narodmon.db.entities.KVSetting import ru.nm17.narodmon.db.entities.KVSetting
import ru.nm17.narodmon.ui.elements.AgreementDialog import ru.nm17.narodmon.ui.elements.AgreementDialog
import ru.nm17.narodmon.ui.elements.GenericNavScaffold import ru.nm17.narodmon.ui.elements.GenericNavScaffold
import ru.nm17.narodmon.ui.pages.SensorsPage
import ru.nm17.narodmon.ui.theme.NarodMonTheme import ru.nm17.narodmon.ui.theme.NarodMonTheme
@Composable @Composable
@ -125,7 +126,7 @@ class MainActivity : ComponentActivity() {
NarodMonTheme { NarodMonTheme {
var agreed by remember { mutableStateOf(true) } var agreed by remember { mutableStateOf(true) }
LaunchedEffect(key1 = "first_agreement_check", block = { LaunchedEffect(key1 = Unit, block = {
coScope.launch(Dispatchers.IO) { coScope.launch(Dispatchers.IO) {
if (db.kvDao().getByKey("agreement_accepted")?.value != "true") { if (db.kvDao().getByKey("agreement_accepted")?.value != "true") {
agreed = false agreed = false
@ -134,23 +135,20 @@ class MainActivity : ComponentActivity() {
}) })
if (!agreed) { if (!agreed) {
Scaffold {
AgreementDialog { AgreementDialog {
coScope.launch(Dispatchers.IO) { coScope.launch(Dispatchers.IO) {
db.kvDao().setAll(KVSetting("agreement_accepted", "true")) db.kvDao().setAll(KVSetting("agreement_accepted", "true"))
agreed = true agreed = true
} }
} }
}
if (!agreed) {
Surface {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize().padding(it)
) { ) {
CircularProgressIndicator() CircularProgressIndicator()
Text(text = "вы не должны видеть этот текст") Text(text = stringResource(R.string.waiting_for_user_agreement))
} }
} }
@ -170,21 +168,7 @@ class MainActivity : ComponentActivity() {
} }
} }
@Composable
fun SensorsPage(navController: NavController) {
GenericNavScaffold(navDrawerSheet = {ModalDrawerSheet {
Text("Drawer title", modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.titleLarge)
Divider()
NavigationDrawerItem(
label = { Text(text = "Drawer Item") },
selected = true,
onClick = { /*TODO*/ }
)
// ...other drawer items
}}) {
Greeting(name = "Hello world", modifier = Modifier.padding(it))
}
}
@Composable @Composable
fun Greeting(name: String, modifier: Modifier = Modifier) { fun Greeting(name: String, modifier: Modifier = Modifier) {

View file

@ -3,9 +3,11 @@
package ru.nm17.narodmon.ui.elements package ru.nm17.narodmon.ui.elements
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.Divider
import androidx.compose.material3.DrawerValue import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FabPosition import androidx.compose.material3.FabPosition
@ -13,7 +15,9 @@ import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
@ -21,6 +25,9 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberDrawerState import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
@ -29,15 +36,26 @@ import kotlinx.coroutines.launch
* TODO: Использовать для датчиков * TODO: Использовать для датчиков
*/ */
@Composable @Composable
fun GenericNavScaffold(navDrawerSheet: @Composable () -> Unit, content: @Composable (PaddingValues) -> Unit) { fun GenericNavScaffold(title: @Composable () -> Unit, content: @Composable (PaddingValues) -> Unit) {
var expanded = rememberDrawerState(initialValue = DrawerValue.Closed) val expanded = rememberDrawerState(initialValue = DrawerValue.Closed)
var coScope = rememberCoroutineScope(); val coScope = rememberCoroutineScope();
val navController = rememberNavController() // TODO: Используй меня
ModalNavigationDrawer(drawerState = expanded, drawerContent = navDrawerSheet) { ModalNavigationDrawer(drawerState = expanded, drawerContent = {
ModalDrawerSheet {
Text("Drawer title", modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.titleLarge)
Divider()
NavigationDrawerItem(
label = { Text(text = "Drawer Item") },
selected = true,
onClick = { /*TODO*/ }
)
}
}) {
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { Text("Top App Bar") }, title = title,
colors = TopAppBarDefaults.largeTopAppBarColors( colors = TopAppBarDefaults.largeTopAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer containerColor = MaterialTheme.colorScheme.primaryContainer
), ),

View file

@ -0,0 +1,28 @@
package ru.nm17.narodmon.ui.pages
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import ru.nm17.narodmon.Greeting
import ru.nm17.narodmon.R
import ru.nm17.narodmon.ui.elements.GenericNavScaffold
@ExperimentalMaterial3Api
@Composable
fun SensorsPage(navController: NavController) {
GenericNavScaffold(
title = { Text(text = stringResource(R.string.sensors_page_title))}
) {
Greeting(name = "world", modifier = Modifier.padding(it))
}
}

View file

@ -5,10 +5,14 @@
<string name="accept_agreements">Я принимаю соглашения</string> <string name="accept_agreements">Я принимаю соглашения</string>
<string name="exit">Выйти</string> <string name="exit">Выйти</string>
<string name="agreement_dialog_text"> <string name="agreement_dialog_text">
Для продолжения использования вы должны принять ниже перечисленные соглашения от проекта Народный Мониторинг. Для продолжения использования вы должны принять ниже перечисленные соглашения от
\nГоворя про наше приложение под андройд, то можете не беспокоится: его исходный код на все 100% является открытым. проекта Народный Мониторинг.
\nГоворя про наше приложение под андройд, то можете не беспокоится: его исходный
код на все 100% является открытым.
</string> </string>
<string name="privacy_policy">Политика конфиденциальности</string> <string name="privacy_policy">Политика конфиденциальности</string>
<string name="user_agreement">Пользовательское соглашение</string> <string name="user_agreement">Пользовательское соглашение</string>
<string name="agreement_dialog_title">Примите необходимые соглашения</string> <string name="agreement_dialog_title">Примите необходимые соглашения</string>
<string name="sensors_page_title">Сенсоры</string>
<string name="waiting_for_user_agreement">Ожидаю соглашение пользователя</string>
</resources> </resources>