Add delete operation

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-08-27 21:02:48 +05:30
parent 717eefad97
commit bb80b42426
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 12 additions and 3 deletions

View file

@ -63,7 +63,11 @@ fun TodoApp() {
},
bodyContent = {
LazyColumnFor(items = items, modifier = Modifier.padding(horizontal = 16.dp)) { todoItem ->
TodoRowItem(item = todoItem)
TodoRowItem(item = todoItem) {
coroutineScope.launch {
itemsDao.delete(todoItem)
}
}
}
},
)

View file

@ -15,13 +15,18 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.msfjarvis.todo.data.model.TodoItem
import kotlinx.coroutines.coroutineScope
@Composable
fun LazyItemScope.TodoRowItem(item: TodoItem) {
fun LazyItemScope.TodoRowItem(item: TodoItem, onLongClick: () -> Unit) {
Row(
modifier = Modifier.padding(vertical = 8.dp)
.fillParentMaxWidth()
.clickable(onClick = {}, indication = RippleIndication()),
.clickable(
onClick = {},
onLongClick = onLongClick,
indication = RippleIndication()
),
) {
Card(
shape = RoundedCornerShape(8.dp),