В SettingsScreen добавлены кнопки "О приложении" и "Дебаг меню"

This commit is contained in:
mezhendosina 2023-06-21 15:30:05 +05:00
parent 3c03aed629
commit c774b8a402
3 changed files with 78 additions and 5 deletions

View file

@ -0,0 +1,50 @@
package ru.nm17.narodmon.ui.elements
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.Switch
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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import ru.nm17.narodmon.R
/**
* Кнопка, которая нужна для настроек.
* @param titleId Id заголовка кнопки
* @param leadingItem Заполнить, когда нужно вставить Composable перед заголовком(например [Icon], [FilterCheckbox] или [Switch]
*/
@Composable
fun SettingsItem(
@StringRes titleId: Int,
leadingItem: @Composable (() -> Unit)? = null,
onClick: () -> Unit = {}
) {
Row(modifier = Modifier.padding(16.dp)) {
if (leadingItem != null) {
leadingItem.invoke()
Spacer(modifier = Modifier.size(16.dp))
}
Column(modifier = Modifier
.fillMaxWidth()
.clickable { onClick.invoke() }) {
Text(text = stringResource(id = titleId))
}
}
}
@Preview(showBackground = true)
@Composable
fun PreviewSettingsItem() {
SettingsItem(R.string.about_app) {}
}

View file

@ -1,16 +1,37 @@
package ru.nm17.narodmon.ui.settings
import androidx.compose.material3.Text
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import ru.nm17.narodmon.R
import ru.nm17.narodmon.ui.elements.SettingsItem
import ru.nm17.narodmon.ui.theme.NarodMonTheme
@Composable
fun SettingsScreen() {
Text(text = "todo")
fun SettingsScreen(navController: NavController) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
item {
SettingsItem(titleId = R.string.debug_menu) {
navController.navigate(Settings.Debug.route)
}
}
item {
SettingsItem(R.string.about_app) {
navController.navigate(Settings.AboutApp.route)
}
}
}
}
@Preview
@Preview(showBackground = true, showSystemUi = false)
@Composable
fun PreviewSettingsScreen() {
SettingsScreen()
NarodMonTheme {
SettingsScreen(rememberNavController())
}
}

View file

@ -56,4 +56,6 @@
<string name="messages">Сообщения</string>
<string name="settings">Настройки</string>
<string name="search_sensors">Поиск датчиков</string>
<string name="about_app">О приложении</string>
<string name="debug_menu">Debug-меню</string>
</resources>