Внесены изменения в архитектуру всплывающей кнопки и диалогового окна

Этот коммит содержится в:
Глеб Иваницкий 2024-08-21 23:03:31 +03:00
родитель 222e8d1e1f
Коммит a8b7685c9f
3 изменённых файлов: 42 добавлений и 26 удалений

Просмотреть файл

@ -48,7 +48,7 @@ sealed class Screen(
title = "Дашборд",
icon = Res.drawable.baseline_dashboard_24,
)
data object Messages : Screen(
data object Scenarios : Screen(
route = "scenarios",
title = "Сценарии",
icon = Res.drawable.baseline_edit_calendar_24,
@ -75,12 +75,18 @@ fun App() {
val snackbarHostState = remember {
SnackbarHostState()
}
val scheduleFloatingActionButtonVisibleState = remember {
val floatingActionButtonVisibleState = remember {
mutableStateOf(false)
}
val floatingActionButtonOnClickState = remember {
mutableStateOf<(() -> Unit)?>(null)
}
val createRuleDialogOpeningState = remember {
mutableStateOf(false)
}
val floatingActionButtonExpandedState = remember {
mutableStateOf(true)
}
Scaffold(
topBar = {
TopAppBar(
@ -96,7 +102,7 @@ fun App() {
val navBackStackEntry = navController.currentBackStackEntryAsState()
val items = listOf(
Screen.Dashboard,
Screen.Messages,
Screen.Scenarios,
Screen.Chats,
Screen.Users,
)
@ -138,7 +144,7 @@ fun App() {
},
floatingActionButton = {
AnimatedVisibility(
visible = scheduleFloatingActionButtonVisibleState.value,
visible = floatingActionButtonVisibleState.value,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally()
) {
@ -154,10 +160,8 @@ fun App() {
contentDescription = null,
)
},
onClick = {
createRuleDialogOpeningState.value = true
},
expanded = true,
onClick = floatingActionButtonOnClickState.value ?: {},
expanded = floatingActionButtonExpandedState.value,
)
}
},
@ -167,27 +171,24 @@ fun App() {
startDestination = Screen.Dashboard.route,
) {
composable(Screen.Dashboard.route) {
scheduleFloatingActionButtonVisibleState.value = false
floatingActionButtonVisibleState.value = false
DashboardScreen(navController, paddingValues)
}
composable(Screen.Messages.route) {
ScenariosScreen(navController, paddingValues)
scheduleFloatingActionButtonVisibleState.value = true
// when {
// createRuleDialogOpeningState.value -> CallProtectionRuleDialog(
// database = database,
// scheduleRule = null,
// state = createRuleDialogOpeningState,
// )
// }
composable(Screen.Scenarios.route) {
floatingActionButtonVisibleState.value = true
ScenariosScreen(
navController,
paddingValues,
floatingActionButtonOnClickState,
floatingActionButtonExpandedState,
)
}
composable(Screen.Chats.route) {
scheduleFloatingActionButtonVisibleState.value = false
floatingActionButtonVisibleState.value = false
ChatsScreen(navController, paddingValues)
}
composable(Screen.Users.route) {
scheduleFloatingActionButtonVisibleState.value = false
floatingActionButtonVisibleState.value = false
UsersScreen(navController, paddingValues)
}
}

Просмотреть файл

@ -51,7 +51,7 @@ fun ScenarioDialog(
TopAppBar(
title = {
Text(
text = scenarioDialogState.value?.let {
text = scenarioDialogState.value?.id?.let {
"Изменить сценарий"
} ?: "Добавить сценарий",
overflow = TextOverflow.Ellipsis,

Просмотреть файл

@ -1,24 +1,28 @@
package ru.csasq.cit_is_bot.ui.screens
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import ru.csasq.cit_is_bot.ui.components.SwitchButton
import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog
data class Scenario(
val id: Int,
val id: Int? = null,
val name: String,
val daysOfWeek: String,
val time: String,
@ -35,6 +39,8 @@ val scenarioList = listOf(
fun ScenariosScreen(
navController: NavController,
paddingValues: PaddingValues,
floatingActionButtonOnClickState: MutableState<(() -> Unit)?>,
floatingActionButtonExpandedState: MutableState<Boolean>,
) {
Column(
modifier = Modifier
@ -49,6 +55,15 @@ fun ScenariosScreen(
val scenarioDialogState = remember {
mutableStateOf<Scenario?>(null)
}
floatingActionButtonOnClickState.value = {
scenarioDialogState.value = Scenario(
name = "",
daysOfWeek = "",
time = "",
messageNumber = "",
isEnabled = true,
)
}
scenarioList.forEach {
val scenarioSwitchState = remember {
mutableStateOf(it.isEnabled)