mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-17 22:14:13 +02:00
feat(connector): move actions to separate screen
This commit is contained in:
parent
931e65c35e
commit
d8efe32b87
@ -1 +1 @@
|
||||
Subproject commit cfed89f7d5435027e9046987416d22bdaf174c85
|
||||
Subproject commit 9018e2898f075dd6ec3922cbc15919b0e4740784
|
@ -3,6 +3,8 @@ import org.koin.core.component.KoinComponent
|
||||
class InterfaceState : KoinComponent {
|
||||
var simConnection: Boolean = false
|
||||
var projectId: Int? = null
|
||||
var procedureId: Int? = null
|
||||
|
||||
val projectSelected: Boolean
|
||||
get() = projectId != null
|
||||
|
||||
|
@ -0,0 +1,81 @@
|
||||
package tab.procedure
|
||||
|
||||
import InterfaceState
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import org.koin.compose.koinInject
|
||||
|
||||
class Actions : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
val viewModel = koinInject<InterfaceState>()
|
||||
val columnPadding = 24.dp
|
||||
|
||||
// Checks if a project has been selected before viewing contents
|
||||
if (viewModel.procedureId == null) {
|
||||
navigator.pop()
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
navigator.pop()
|
||||
viewModel.procedureId = null
|
||||
}
|
||||
) {
|
||||
Icon(Icons.AutoMirrored.Outlined.ArrowBack, "Back Arrow")
|
||||
}
|
||||
},
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(top = columnPadding, bottom = columnPadding),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth(0.7F),
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Edit Actions",
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
|
||||
Button(
|
||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
||||
onClick = {
|
||||
// TODO make checks
|
||||
navigator.pop()
|
||||
viewModel.procedureId = null
|
||||
}
|
||||
) {
|
||||
Icon(Icons.Outlined.Add, "Create Procedure", modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||
Text(
|
||||
"Create",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -32,11 +32,6 @@ class CreateProcedure : Screen {
|
||||
var procedureName by remember { mutableStateOf("") }
|
||||
var procedureDescription by remember { mutableStateOf("") }
|
||||
|
||||
// Actions
|
||||
val actionTypeOptions = listOf("Switch", "Button", "Lever")
|
||||
var actionType by remember { mutableStateOf(procedureTypeOptions[0]) }
|
||||
var actionTypeExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@ -114,44 +109,6 @@ class CreateProcedure : Screen {
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
Text(
|
||||
text = "Actions",
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = actionTypeExpanded,
|
||||
onExpandedChange = { actionTypeExpanded = it }
|
||||
) {
|
||||
TextField(
|
||||
modifier = Modifier.menuAnchor(),
|
||||
value = actionType,
|
||||
onValueChange = {},
|
||||
readOnly = true,
|
||||
singleLine = true,
|
||||
label = { Text("Type") },
|
||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = actionTypeExpanded) },
|
||||
colors = ExposedDropdownMenuDefaults.textFieldColors()
|
||||
)
|
||||
ExposedDropdownMenu(
|
||||
expanded = actionTypeExpanded,
|
||||
onDismissRequest = { actionTypeExpanded = false },
|
||||
) {
|
||||
actionTypeOptions.forEach { option ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(option, style = MaterialTheme.typography.bodyLarge) },
|
||||
onClick = {
|
||||
actionType = option
|
||||
actionTypeExpanded = false
|
||||
},
|
||||
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
||||
onClick = {
|
||||
@ -159,7 +116,6 @@ class CreateProcedure : Screen {
|
||||
procedureName.isNotBlank() and
|
||||
procedureType.isNotBlank() and
|
||||
procedureDescription.isNotBlank()
|
||||
// TODO add checks for actions
|
||||
) {
|
||||
screenModel.createProcedure(
|
||||
procedureName = procedureName,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package tab.procedure
|
||||
|
||||
import InterfaceState
|
||||
import androidx.compose.foundation.VerticalScrollbar
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@ -19,8 +20,10 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import io.anthonyberg.connector.shared.entity.Procedure
|
||||
import org.koin.compose.koinInject
|
||||
|
||||
class ListProcedures (
|
||||
private val procedures: List<Procedure>
|
||||
@ -28,6 +31,8 @@ class ListProcedures (
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
val viewModel = koinInject<InterfaceState>()
|
||||
|
||||
val state = rememberLazyListState(0)
|
||||
|
||||
Scaffold (
|
||||
@ -50,7 +55,7 @@ class ListProcedures (
|
||||
) {
|
||||
LazyColumn(state = state) {
|
||||
items(procedures) { procedure ->
|
||||
procedureItem(procedure)
|
||||
procedureItem(procedure, viewModel, navigator)
|
||||
}
|
||||
}
|
||||
VerticalScrollbar(
|
||||
@ -67,13 +72,15 @@ class ListProcedures (
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun procedureItem(procedure: Procedure) {
|
||||
private fun procedureItem(procedure: Procedure, viewModel: InterfaceState, navigator: Navigator) {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
enabled = true,
|
||||
onClick = {
|
||||
// TODO add procedure editor
|
||||
viewModel.procedureId = procedure.id
|
||||
|
||||
navigator.push(Actions())
|
||||
}
|
||||
),
|
||||
overlineContent = { Text(procedure.type) },
|
||||
|
Loading…
x
Reference in New Issue
Block a user