Browse Source

done

master
Xaver 1 week ago
parent
commit
efc993f46b
  1. 4
      app/src/main/java/at/xaxa/demonstrator2/data/TaskRepository.kt
  2. 5
      app/src/main/java/at/xaxa/demonstrator2/ui/AppViewModelProvider.kt
  3. 16
      app/src/main/java/at/xaxa/demonstrator2/ui/DemoUI.kt
  4. 6
      app/src/main/java/at/xaxa/demonstrator2/ui/DemoViewModel.kt

4
app/src/main/java/at/xaxa/demonstrator2/data/TaskRepository.kt

@ -23,6 +23,10 @@ class TaskRepository(private val taskDao: TaskDao) {
taskDao.addTask(TaskEntity(_id=0, task.name, task.details)) taskDao.addTask(TaskEntity(_id=0, task.name, task.details))
} }
suspend fun deleteTask(task: Task) {
taskDao.deleteTask(TaskEntity(_id=task.id, task.name, task.details))
}
suspend fun updateTask(task: Task) { suspend fun updateTask(task: Task) {
taskDao.updateTask(TaskEntity(task.id, task.name, task.details)) taskDao.updateTask(TaskEntity(task.id, task.name, task.details))
} }

5
app/src/main/java/at/xaxa/demonstrator2/ui/AppViewModelProvider.kt

@ -5,6 +5,7 @@ import androidx.lifecycle.createSavedStateHandle
import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory import androidx.lifecycle.viewmodel.viewModelFactory
import at.xaxa.demonstrator2.TaskApplication import at.xaxa.demonstrator2.TaskApplication
import at.xaxa.demonstrator2.ui.edit.TaskEditViewModel
object AppViewModelProvider { object AppViewModelProvider {
val Factory = viewModelFactory { val Factory = viewModelFactory {
@ -15,5 +16,9 @@ object AppViewModelProvider {
initializer { initializer {
DemoDetailsViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as TaskApplication).taskRepository) DemoDetailsViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as TaskApplication).taskRepository)
} }
initializer {
TaskEditViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as TaskApplication).taskRepository)
}
} }
} }

16
app/src/main/java/at/xaxa/demonstrator2/ui/DemoUI.kt

@ -14,6 +14,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material3.FilledTonalButton import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -127,6 +128,8 @@ fun ListScreen(
onCardClick(task.id) onCardClick(task.id)
}, onEditClick = { }, onEditClick = {
onEditClick(task.id) onEditClick(task.id)
},onDeleteClick = {
demoViewModel.onDeleteButtonClicked(task)
}) })
} }
} }
@ -150,7 +153,7 @@ fun TaskDetails(task: Task, modifier: Modifier = Modifier) {
Column(Modifier.padding(16.dp)) { Column(Modifier.padding(16.dp)) {
Text(task.name, style = Typography.headlineMedium) Text(task.name, style = Typography.headlineMedium)
Row { Row {
Text("Details: ${task.details}", style = Typography.headlineMedium) Text("Details: ${task.details}", style = Typography.bodyLarge)
} }
} }
} }
@ -207,7 +210,7 @@ fun AddScreen(
} }
@Composable @Composable
fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, modifier: Modifier = Modifier) { fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, onDeleteClick: ()->Unit, modifier: Modifier = Modifier) {
OutlinedCard( OutlinedCard(
onClick = { onCardClick() }, modifier = modifier onClick = { onCardClick() }, modifier = modifier
.fillMaxWidth() .fillMaxWidth()
@ -215,8 +218,13 @@ fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, mod
) { ) {
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) { Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
Text(task.name, style = Typography.headlineMedium) Text(task.name, style = Typography.headlineMedium)
Row {
IconButton(onEditClick) { IconButton(onEditClick) {
Icon(Icons.Outlined.Edit, "Edit contact") Icon(Icons.Outlined.Edit, "Edit Task")
}
IconButton(onDeleteClick) {
Icon(Icons.Outlined.Delete, "Delete Task")
}
} }
} }
} }
@ -225,5 +233,5 @@ fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, mod
@Preview @Preview
@Composable @Composable
fun PreviewTaskListItem(){ fun PreviewTaskListItem(){
TaskListItem(Task(0, "Buy Milk", "buy milk"), {}, {}) TaskListItem(Task(0, "Buy Milk", "buy milk"), {}, {}, {})
} }

6
app/src/main/java/at/xaxa/demonstrator2/ui/DemoViewModel.kt

@ -31,4 +31,10 @@ class DemoViewModel(val repository: TaskRepository) : ViewModel() {
repository.addTask(task) repository.addTask(task)
} }
} }
fun onDeleteButtonClicked(task: Task) {
viewModelScope.launch {
repository.deleteTask(task)
}
}
} }

Loading…
Cancel
Save