WIP: UUID при запуске дебаг версии #11

Draft
nm17 wants to merge 2 commits from dc09-uuid into master
4 changed files with 89 additions and 4 deletions

View file

@ -5,6 +5,7 @@
package ru.nm17.narodmon package ru.nm17.narodmon
import android.content.pm.ApplicationInfo
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@ -47,6 +48,7 @@ import kotlinx.coroutines.launch
import ru.nm17.narodmon.db.AppDatabase 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.dialogs.AgreementDialog import ru.nm17.narodmon.ui.dialogs.AgreementDialog
import ru.nm17.narodmon.ui.dialogs.UuidDialog
import ru.nm17.narodmon.ui.sensorsScreen.SensorsScreen import ru.nm17.narodmon.ui.sensorsScreen.SensorsScreen
import ru.nm17.narodmon.ui.theme.NarodMonTheme import ru.nm17.narodmon.ui.theme.NarodMonTheme
@ -123,6 +125,10 @@ class MainActivity : ComponentActivity() {
NarodMonTheme { NarodMonTheme {
var agreed by remember { mutableStateOf(true) } var agreed by remember { mutableStateOf(true) }
var uuid: String? by remember { mutableStateOf(null) }
val debug = remember {
0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
}
LaunchedEffect(key1 = Unit, block = { LaunchedEffect(key1 = Unit, block = {
coScope.launch(Dispatchers.IO) { coScope.launch(Dispatchers.IO) {
@ -132,7 +138,7 @@ class MainActivity : ComponentActivity() {
} }
}) })
if (!agreed) { if (!agreed && !debug) {
Scaffold { Scaffold {
AgreementDialog { AgreementDialog {
coScope.launch(Dispatchers.IO) { coScope.launch(Dispatchers.IO) {
@ -151,9 +157,26 @@ class MainActivity : ComponentActivity() {
Text(text = stringResource(R.string.waiting_for_user_agreement)) Text(text = stringResource(R.string.waiting_for_user_agreement))
} }
} }
} else { }
else if (debug && uuid == null) {
Scaffold {
UuidDialog { uuidNew ->
uuid = uuidNew
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
CircularProgressIndicator()
Text(text = "")
}
}
}
else {
AppNavHost() AppNavHost()
} }
// A surface container using the 'background' color from the theme // A surface container using the 'background' color from the theme

View file

@ -0,0 +1,59 @@
package ru.nm17.narodmon.ui.dialogs
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import ru.nm17.narodmon.R
import kotlin.system.exitProcess
@ExperimentalMaterial3Api
@Composable
fun UuidDialog(modifier: Modifier = Modifier, onUuidInput: (uuid: String) -> Unit) {
var uuid by remember { mutableStateOf("") }
AlertDialog(
onDismissRequest = { },
title = { Text(text = stringResource(id = R.string.uuid_dialog_title)) },
text = {
TextField(
value = uuid,
onValueChange = { uuid = it },
placeholder = { Text(text = "UUID") }
)
},
confirmButton = {
TextButton(
onClick = { onUuidInput(uuid) }
) {
Text(text = stringResource(id = R.string.uuid_confirm))
}
},
dismissButton = {
TextButton(
onClick = { onUuidInput("") }) {
Text(text = stringResource(id = R.string.uuid_generate))
}
},
modifier = modifier
)
}

View file

@ -52,4 +52,7 @@
<string name="apply">Применить</string> <string name="apply">Применить</string>
<string name="sort_by_distance_desc">От дальних к ближним</string> <string name="sort_by_distance_desc">От дальних к ближним</string>
<string name="cancel1">Отменить</string> <string name="cancel1">Отменить</string>
<string name="uuid_dialog_title">Введите UUID приложения</string>
<string name="uuid_confirm">Сохранить</string>
<string name="uuid_generate">Сгенерировать</string>
</resources> </resources>

View file

@ -1,5 +1,5 @@
[versions] [versions]
agp = "8.2.0-alpha07" agp = "8.2.0-alpha08"
kotlin = "1.8.10" kotlin = "1.8.10"
core-ktx = "1.9.0" core-ktx = "1.9.0"
junit = "4.13.2" junit = "4.13.2"