Сценарии адаптированы под новую схему API

Этот коммит содержится в:
Глеб Иваницкий 2024-09-01 23:49:45 +03:00
родитель 829d41a70a
Коммит 6f1ac6f912
2 изменённых файлов: 377 добавлений и 345 удалений

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

@ -102,7 +102,7 @@ fun ScenarioDialog(
mutableStateOf(scenarioDialogState.value?.name) mutableStateOf(scenarioDialogState.value?.name)
} }
val timeState = remember { val timeState = remember {
mutableStateOf(scenarioDialogState.value?.time) mutableStateOf(scenarioDialogState.value?.startTime)
} }
Dialog( Dialog(
@ -393,353 +393,359 @@ fun ScenarioDialog(
modifier = Modifier modifier = Modifier
.height(16.dp), .height(16.dp),
) )
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainer,
),
) {
val dropdownMenuState = remember {
mutableStateOf(false)
}
val messageTypeState = remember {
mutableStateOf(MessageType.TEXT)
}
Column(
modifier = Modifier
.padding(16.dp),
) {
Text(
text = "Общее",
style = MaterialTheme.typography.titleMedium,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
OutlinedTextField(
value = "",
onValueChange = {},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Название",
)
},
leadingIcon = {
Icon(
painter = painterResource(Res.drawable.baseline_title_24),
contentDescription = null,
)
},
supportingText = {
Text(
text = "Отображается в списке переходов",
)
},
isError = false,
singleLine = true,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
OutlinedTextField(
value = "",
onValueChange = {},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Время окончания",
)
},
leadingIcon = {
Icon(
painter = painterResource(Res.drawable.outline_time_auto_24),
contentDescription = null,
)
},
supportingText = {
Text(
text = "Время прекращения обработки событий",
)
},
isError = false,
singleLine = true,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
val disableNotificationCheckboxState = remember {
mutableStateOf(false)
}
TextCheckbox(
text = "Не отправлять уведомление",
checkboxState = disableNotificationCheckboxState,
)
val deleteAfterEndCheckboxState = remember {
mutableStateOf(false)
}
TextCheckbox(
text = "Удалить после окончания",
checkboxState = deleteAfterEndCheckboxState,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
ExposedDropdownMenuBox(
expanded = dropdownMenuState.value,
onExpandedChange = { value ->
dropdownMenuState.value = value
},
modifier = Modifier
.pointerHoverIcon(
icon = PointerIcon.Default,
overrideDescendants = true,
),
) {
OutlinedTextField(
value = messageTypeState.value.displayName,
onValueChange = {},
modifier = Modifier
.fillMaxWidth()
.menuAnchor(),
label = {
Text(
text = "Тип",
)
},
readOnly = true,
leadingIcon = {
Icon(
painter = painterResource(messageTypeState.value.icon),
contentDescription = null,
)
},
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(
expanded = dropdownMenuState.value,
)
},
isError = false,
singleLine = true,
)
ExposedDropdownMenu(
expanded = dropdownMenuState.value,
onDismissRequest = {
dropdownMenuState.value = false
},
) {
MessageType.entries.forEach {
DropdownMenuItem(
text = {
Text(
text = it.displayName,
)
},
onClick = {
messageTypeState.value = it
dropdownMenuState.value = false
},
leadingIcon = {
Icon(
painter = painterResource(it.icon),
contentDescription = null,
)
},
)
}
}
}
when { }
messageTypeState.value != MessageType.DICE -> { }
Spacer( }
modifier = Modifier }
.height(16.dp),
) @OptIn(ExperimentalMaterial3Api::class)
Text( @Composable
text = messageTypeState.value.displayName, fun MessageCard() {
style = MaterialTheme.typography.titleMedium, Card(
) colors = CardDefaults.cardColors(
Spacer( containerColor = MaterialTheme.colorScheme.surfaceContainer,
modifier = Modifier ),
.height(8.dp), ) {
) val dropdownMenuState = remember {
} mutableStateOf(false)
} }
val messageTypeState = remember {
when (messageTypeState.value) { mutableStateOf(MessageType.TEXT)
MessageType.TEXT -> { }
val textState = remember { Column(
mutableStateOf("") modifier = Modifier
} .padding(16.dp),
OutlinedTextField( ) {
value = textState.value, Text(
onValueChange = { value -> text = "Общее",
textState.value = value style = MaterialTheme.typography.titleMedium,
}, )
modifier = Modifier Spacer(
.fillMaxWidth(), modifier = Modifier
label = { .height(8.dp),
Text( )
text = "Текст сообщения", OutlinedTextField(
) value = "",
}, onValueChange = {},
isError = false, modifier = Modifier
maxLines = 6, .fillMaxWidth(),
) label = {
} Text(
MessageType.POLL -> { text = "Название",
val questionState = remember { )
mutableStateOf("") },
} leadingIcon = {
OutlinedTextField( Icon(
value = questionState.value, painter = painterResource(Res.drawable.baseline_title_24),
onValueChange = { value -> contentDescription = null,
questionState.value = value )
}, },
modifier = Modifier supportingText = {
.fillMaxWidth(), Text(
label = { text = "Отображается в списке переходов",
Text( )
text = "Вопрос", },
) isError = false,
}, singleLine = true,
isError = false, )
singleLine = true, Spacer(
) modifier = Modifier
Spacer( .height(8.dp),
modifier = Modifier )
.height(16.dp), OutlinedTextField(
) value = "",
Text( onValueChange = {},
text = "Варианты ответа", modifier = Modifier
style = MaterialTheme.typography.titleMedium, .fillMaxWidth(),
) label = {
Spacer( Text(
modifier = Modifier text = "Время окончания",
.height(8.dp), )
) },
val optionState = remember { leadingIcon = {
mutableStateOf("") Icon(
} painter = painterResource(Res.drawable.outline_time_auto_24),
Row( contentDescription = null,
verticalAlignment = Alignment.CenterVertically, )
) { },
OutlinedTextField( supportingText = {
value = optionState.value, Text(
onValueChange = { value -> text = "Время прекращения обработки событий",
optionState.value = value )
}, },
modifier = Modifier isError = false,
.weight(1f), singleLine = true,
label = {}, )
isError = false, Spacer(
singleLine = true, modifier = Modifier
) .height(8.dp),
Spacer( )
modifier = Modifier val disableNotificationCheckboxState = remember {
.width(8.dp), mutableStateOf(false)
) }
IconButton( TextCheckbox(
onClick = {}, text = "Не отправлять уведомление",
) { checkboxState = disableNotificationCheckboxState,
Icon( )
painter = painterResource(Res.drawable.outline_adjust_24), val deleteAfterEndCheckboxState = remember {
contentDescription = null, mutableStateOf(false)
) }
} TextCheckbox(
} text = "Удалить после окончания",
Spacer( checkboxState = deleteAfterEndCheckboxState,
modifier = Modifier )
.height(16.dp), Spacer(
) modifier = Modifier
Text( .height(8.dp),
text = "Настройки", )
style = MaterialTheme.typography.titleMedium, ExposedDropdownMenuBox(
) expanded = dropdownMenuState.value,
Spacer( onExpandedChange = { value ->
modifier = Modifier dropdownMenuState.value = value
.height(8.dp), },
) modifier = Modifier
val anonymousPollCheckboxState = remember { .pointerHoverIcon(
mutableStateOf(false) icon = PointerIcon.Default,
} overrideDescendants = true,
TextCheckbox( ),
text = "Анонимное голосование", ) {
checkboxState = anonymousPollCheckboxState, OutlinedTextField(
) value = messageTypeState.value.displayName,
val multiselectPollCheckboxState = remember { onValueChange = {},
mutableStateOf(false) modifier = Modifier
} .fillMaxWidth()
TextCheckbox( .menuAnchor(),
text = "Выбор нескольких ответов", label = {
checkboxState = multiselectPollCheckboxState, Text(
) text = "Тип",
} )
MessageType.MEDIA -> { },
OutlinedButton( readOnly = true,
onClick = {}, leadingIcon = {
) { Icon(
Icon( painter = painterResource(messageTypeState.value.icon),
painter = painterResource(Res.drawable.baseline_attach_file_24), contentDescription = null,
contentDescription = null, )
) },
Text( trailingIcon = {
text = "Прикрепить файл", ExposedDropdownMenuDefaults.TrailingIcon(
) expanded = dropdownMenuState.value,
} )
} },
MessageType.CONTACT -> { isError = false,
val contactPhoneNumberState = remember { singleLine = true,
mutableStateOf("") )
} ExposedDropdownMenu(
OutlinedTextField( expanded = dropdownMenuState.value,
value = contactPhoneNumberState.value, onDismissRequest = {
onValueChange = { value -> dropdownMenuState.value = false
contactPhoneNumberState.value = value },
}, ) {
modifier = Modifier MessageType.entries.forEach {
.fillMaxWidth(), DropdownMenuItem(
label = { text = {
Text( Text(
text = "Номер телефона", text = it.displayName,
) )
}, },
isError = false, onClick = {
singleLine = true, messageTypeState.value = it
) dropdownMenuState.value = false
Spacer( },
modifier = Modifier leadingIcon = {
.height(8.dp), Icon(
) painter = painterResource(it.icon),
val contactNameState = remember { contentDescription = null,
mutableStateOf("") )
} },
OutlinedTextField( )
value = contactNameState.value, }
onValueChange = { value -> }
contactNameState.value = value }
},
modifier = Modifier when {
.fillMaxWidth(), messageTypeState.value != MessageType.DICE -> {
label = { Spacer(
Text( modifier = Modifier
text = "Имя", .height(16.dp),
) )
}, Text(
isError = false, text = messageTypeState.value.displayName,
singleLine = true, style = MaterialTheme.typography.titleMedium,
) )
} Spacer(
MessageType.DICE -> {} modifier = Modifier
} .height(8.dp),
} )
} }
}
when (messageTypeState.value) {
MessageType.TEXT -> {
val textState = remember {
mutableStateOf("")
}
OutlinedTextField(
value = textState.value,
onValueChange = { value ->
textState.value = value
},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Текст сообщения",
)
},
isError = false,
maxLines = 6,
)
}
MessageType.POLL -> {
val questionState = remember {
mutableStateOf("")
}
OutlinedTextField(
value = questionState.value,
onValueChange = { value ->
questionState.value = value
},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Вопрос",
)
},
isError = false,
singleLine = true,
)
Spacer(
modifier = Modifier
.height(16.dp),
)
Text(
text = "Варианты ответа",
style = MaterialTheme.typography.titleMedium,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
val optionState = remember {
mutableStateOf("")
}
Row(
verticalAlignment = Alignment.CenterVertically,
) {
OutlinedTextField(
value = optionState.value,
onValueChange = { value ->
optionState.value = value
},
modifier = Modifier
.weight(1f),
label = {},
isError = false,
singleLine = true,
)
Spacer(
modifier = Modifier
.width(8.dp),
)
IconButton(
onClick = {},
) {
Icon(
painter = painterResource(Res.drawable.outline_adjust_24),
contentDescription = null,
)
}
}
Spacer(
modifier = Modifier
.height(16.dp),
)
Text(
text = "Настройки",
style = MaterialTheme.typography.titleMedium,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
val anonymousPollCheckboxState = remember {
mutableStateOf(false)
}
TextCheckbox(
text = "Анонимное голосование",
checkboxState = anonymousPollCheckboxState,
)
val multiselectPollCheckboxState = remember {
mutableStateOf(false)
}
TextCheckbox(
text = "Выбор нескольких ответов",
checkboxState = multiselectPollCheckboxState,
)
}
MessageType.MEDIA -> {
OutlinedButton(
onClick = {},
) {
Icon(
painter = painterResource(Res.drawable.baseline_attach_file_24),
contentDescription = null,
)
Text(
text = "Прикрепить файл",
)
}
}
MessageType.CONTACT -> {
val contactPhoneNumberState = remember {
mutableStateOf("")
}
OutlinedTextField(
value = contactPhoneNumberState.value,
onValueChange = { value ->
contactPhoneNumberState.value = value
},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Номер телефона",
)
},
isError = false,
singleLine = true,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
val contactNameState = remember {
mutableStateOf("")
}
OutlinedTextField(
value = contactNameState.value,
onValueChange = { value ->
contactNameState.value = value
},
modifier = Modifier
.fillMaxWidth(),
label = {
Text(
text = "Имя",
)
},
isError = false,
singleLine = true,
)
}
MessageType.DICE -> {}
} }
} }
} }

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

@ -43,12 +43,31 @@ import org.jetbrains.compose.resources.painterResource
import ru.csasq.cit_is_bot.ui.components.SwitchButton import ru.csasq.cit_is_bot.ui.components.SwitchButton
import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog
@Serializable
enum class UserRole(
val displayName: String,
) {
User("Пользователь"),
Moderator("Модератор"),
Admin("Администратор"),
}
@Serializable
data class User(
val id: Int,
val firstName: String,
val lastName: String?,
val username: String?,
val role: UserRole,
)
@Serializable @Serializable
data class Scenario( data class Scenario(
val id: Int? = null, val id: Int? = null,
val owner: User,
var name: String, var name: String,
var time: String, var startTime: String,
var messageNumber: String, var messages: List<String>,
var isEnabled: Boolean, var isEnabled: Boolean,
) )
@ -160,8 +179,15 @@ fun ScenariosScreen(
onClick = { onClick = {
scenarioDialogState.value = Scenario( scenarioDialogState.value = Scenario(
name = "", name = "",
time = "", owner = User(
messageNumber = "", id = 1,
firstName = "Глеб",
lastName = "Иваницкий",
username = "csasq",
role = UserRole.Admin,
),
startTime = "",
messages = listOf(),
isEnabled = true, isEnabled = true,
) )
}, },
@ -174,9 +200,9 @@ fun ScenariosScreen(
mutableStateOf(it.isEnabled) mutableStateOf(it.isEnabled)
} }
val captionAnnotatedString = buildAnnotatedString { val captionAnnotatedString = buildAnnotatedString {
append(it.time) append(it.startTime)
append(" \u2022 ") append(" \u2022 ")
append(it.messageNumber) append(it.messages.size.toString())
} }
SwitchButton( SwitchButton(
title = it.name, title = it.name,