mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 00:57:02 +05:30
Tweak item addition dialog layout
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
8df3db3607
commit
34ce5e9448
1 changed files with 15 additions and 31 deletions
|
@ -3,10 +3,10 @@ package dev.msfjarvis.todo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.foundation.Text
|
import androidx.compose.foundation.Text
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumnFor
|
import androidx.compose.foundation.lazy.LazyColumnFor
|
||||||
import androidx.compose.material.AlertDialog
|
import androidx.compose.material.AlertDialog
|
||||||
|
import androidx.compose.material.Button
|
||||||
import androidx.compose.material.FloatingActionButton
|
import androidx.compose.material.FloatingActionButton
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.OutlinedTextField
|
import androidx.compose.material.OutlinedTextField
|
||||||
|
@ -24,12 +24,8 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.setContent
|
import androidx.compose.ui.platform.setContent
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.semantics.testTag
|
import androidx.compose.ui.semantics.testTag
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.ui.tooling.preview.Preview
|
import androidx.ui.tooling.preview.Preview
|
||||||
import dev.msfjarvis.todo.compose.utils.IconResource
|
import dev.msfjarvis.todo.compose.utils.IconResource
|
||||||
import dev.msfjarvis.todo.data.model.TodoItem
|
import dev.msfjarvis.todo.data.model.TodoItem
|
||||||
|
@ -102,41 +98,29 @@ fun ItemAddDialog(
|
||||||
onAdd: (item: TodoItem) -> Unit,
|
onAdd: (item: TodoItem) -> Unit,
|
||||||
) {
|
) {
|
||||||
var newItemName by mutableStateOf(TextFieldValue(""))
|
var newItemName by mutableStateOf(TextFieldValue(""))
|
||||||
|
val hideDialog = { showingDialog.value = false }
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = {
|
onDismissRequest = hideDialog,
|
||||||
showingDialog.value = false
|
|
||||||
},
|
|
||||||
text = {
|
text = {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
activeColor = MaterialTheme.colors.secondary,
|
activeColor = MaterialTheme.colors.secondary,
|
||||||
value = newItemName,
|
value = newItemName,
|
||||||
onValueChange = { newItemName = it },
|
onValueChange = { newItemName = it },
|
||||||
label = {
|
label = { Text(text = "Name") },
|
||||||
Text(
|
|
||||||
text = "Name",
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
},
|
|
||||||
title = {
|
|
||||||
Text(
|
|
||||||
text = "Create new item",
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Text(
|
Button(
|
||||||
text = "Add",
|
onClick = {
|
||||||
modifier = Modifier.padding(16.dp).clickable(onClick = {
|
if (newItemName.text.isNotEmpty()) {
|
||||||
onAdd.invoke(TodoItem(newItemName.text))
|
onAdd.invoke(TodoItem(newItemName.text))
|
||||||
newItemName = TextFieldValue("")
|
newItemName = TextFieldValue("")
|
||||||
showingDialog.value = false
|
hideDialog.invoke()
|
||||||
}),
|
}
|
||||||
style = TextStyle(
|
}
|
||||||
fontSize = 18.sp,
|
) {
|
||||||
textAlign = TextAlign.End,
|
Text(text = "Add")
|
||||||
fontStyle = FontStyle.Normal,
|
}
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue