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. 18
      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) { @@ -23,6 +23,10 @@ class TaskRepository(private val taskDao: TaskDao) {
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) {
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 @@ -5,6 +5,7 @@ import androidx.lifecycle.createSavedStateHandle
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import at.xaxa.demonstrator2.TaskApplication
import at.xaxa.demonstrator2.ui.edit.TaskEditViewModel
object AppViewModelProvider {
val Factory = viewModelFactory {
@ -15,5 +16,9 @@ object AppViewModelProvider { @@ -15,5 +16,9 @@ object AppViewModelProvider {
initializer {
DemoDetailsViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as TaskApplication).taskRepository)
}
initializer {
TaskEditViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as TaskApplication).taskRepository)
}
}
}

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

@ -14,6 +14,7 @@ import androidx.compose.foundation.lazy.itemsIndexed @@ -14,6 +14,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
@ -127,6 +128,8 @@ fun ListScreen( @@ -127,6 +128,8 @@ fun ListScreen(
onCardClick(task.id)
}, onEditClick = {
onEditClick(task.id)
},onDeleteClick = {
demoViewModel.onDeleteButtonClicked(task)
})
}
}
@ -150,7 +153,7 @@ fun TaskDetails(task: Task, modifier: Modifier = Modifier) { @@ -150,7 +153,7 @@ fun TaskDetails(task: Task, modifier: Modifier = Modifier) {
Column(Modifier.padding(16.dp)) {
Text(task.name, style = Typography.headlineMedium)
Row {
Text("Details: ${task.details}", style = Typography.headlineMedium)
Text("Details: ${task.details}", style = Typography.bodyLarge)
}
}
}
@ -207,7 +210,7 @@ fun AddScreen( @@ -207,7 +210,7 @@ fun AddScreen(
}
@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(
onClick = { onCardClick() }, modifier = modifier
.fillMaxWidth()
@ -215,8 +218,13 @@ fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, mod @@ -215,8 +218,13 @@ fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, mod
) {
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
Text(task.name, style = Typography.headlineMedium)
IconButton(onEditClick) {
Icon(Icons.Outlined.Edit, "Edit contact")
Row {
IconButton(onEditClick) {
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 @@ -225,5 +233,5 @@ fun TaskListItem(task: Task, onCardClick: () -> Unit, onEditClick: ()->Unit, mod
@Preview
@Composable
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() { @@ -31,4 +31,10 @@ class DemoViewModel(val repository: TaskRepository) : ViewModel() {
repository.addTask(task)
}
}
fun onDeleteButtonClicked(task: Task) {
viewModelScope.launch {
repository.deleteTask(task)
}
}
}

Loading…
Cancel
Save