Сценарии адаптированы под новую схему 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,354 +393,360 @@ fun ScenarioDialog(
modifier = Modifier modifier = Modifier
.height(16.dp), .height(16.dp),
) )
Card(
colors = CardDefaults.cardColors( }
containerColor = MaterialTheme.colorScheme.surfaceContainer, }
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MessageCard() {
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,
), ),
) { ) {
val dropdownMenuState = remember { OutlinedTextField(
mutableStateOf(false) value = messageTypeState.value.displayName,
} onValueChange = {},
val messageTypeState = remember { modifier = Modifier
mutableStateOf(MessageType.TEXT) .fillMaxWidth()
} .menuAnchor(),
Column( label = {
modifier = Modifier
.padding(16.dp),
) {
Text( Text(
text = "Общее", text = "Тип",
style = MaterialTheme.typography.titleMedium,
) )
Spacer( },
modifier = Modifier readOnly = true,
.height(8.dp), leadingIcon = {
Icon(
painter = painterResource(messageTypeState.value.icon),
contentDescription = null,
) )
OutlinedTextField( },
value = "", trailingIcon = {
onValueChange = {}, ExposedDropdownMenuDefaults.TrailingIcon(
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, expanded = dropdownMenuState.value,
onExpandedChange = { value -> )
dropdownMenuState.value = value },
isError = false,
singleLine = true,
)
ExposedDropdownMenu(
expanded = dropdownMenuState.value,
onDismissRequest = {
dropdownMenuState.value = false
},
) {
MessageType.entries.forEach {
DropdownMenuItem(
text = {
Text(
text = it.displayName,
)
}, },
modifier = Modifier onClick = {
.pointerHoverIcon( messageTypeState.value = it
icon = PointerIcon.Default, dropdownMenuState.value = false
overrideDescendants = true, },
), leadingIcon = {
) { Icon(
OutlinedTextField( painter = painterResource(it.icon),
value = messageTypeState.value.displayName, contentDescription = null,
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),
) )
Text( },
text = messageTypeState.value.displayName, )
style = MaterialTheme.typography.titleMedium,
)
Spacer(
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 -> {}
}
} }
} }
} }
when {
messageTypeState.value != MessageType.DICE -> {
Spacer(
modifier = Modifier
.height(16.dp),
)
Text(
text = messageTypeState.value.displayName,
style = MaterialTheme.typography.titleMedium,
)
Spacer(
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,