ADD: Delete Notes from Grid
This commit is contained in:
parent
6df3f756ec
commit
8989dcd21d
@ -5,6 +5,7 @@ import androidx.activity.compose.BackHandler
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -16,6 +17,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
@ -25,6 +27,8 @@ import androidx.compose.foundation.lazy.items
|
|||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material.icons.filled.Folder
|
import androidx.compose.material.icons.filled.Folder
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
@ -158,6 +162,106 @@ private fun BreadcrumbItem(label: String, onClick: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NoteItem(
|
||||||
|
note: NoteEntity,
|
||||||
|
onNoteClick: (NoteEntity) -> Unit,
|
||||||
|
onEditTitle: () -> Unit,
|
||||||
|
onDeleteNote: () -> Unit
|
||||||
|
) {
|
||||||
|
var showMenu by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.height(120.dp)
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant)
|
||||||
|
.clickable { onNoteClick(note) }
|
||||||
|
.padding(12.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
AsyncImage(
|
||||||
|
model = note.imagePreview,
|
||||||
|
contentDescription = "Noten-Vorschau",
|
||||||
|
modifier = Modifier
|
||||||
|
.size(64.dp)
|
||||||
|
.clip(RoundedCornerShape(8.dp)),
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
|
||||||
|
Box {
|
||||||
|
Text(
|
||||||
|
text = note.title,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
maxLines = 2,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(top = 8.dp)
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
showMenu = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = showMenu,
|
||||||
|
onDismissRequest = { showMenu = false },
|
||||||
|
modifier = Modifier
|
||||||
|
.width(240.dp)
|
||||||
|
.background(MaterialTheme.colorScheme.background)
|
||||||
|
) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = {
|
||||||
|
showMenu = false
|
||||||
|
onEditTitle()
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Edit,
|
||||||
|
contentDescription = "Bearbeiten",
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("Bearbeiten", color = MaterialTheme.colorScheme.primary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = {
|
||||||
|
showMenu = false
|
||||||
|
onDeleteNote()
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Delete,
|
||||||
|
contentDescription = "Löschen",
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("Löschen", color = MaterialTheme.colorScheme.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun NoteGrid(
|
fun NoteGrid(
|
||||||
@ -165,7 +269,8 @@ fun NoteGrid(
|
|||||||
collections: List<NoteCollection>,
|
collections: List<NoteCollection>,
|
||||||
notes: List<NoteEntity>,
|
notes: List<NoteEntity>,
|
||||||
onCollectionClick: (NoteCollection) -> Unit,
|
onCollectionClick: (NoteCollection) -> Unit,
|
||||||
onNoteClick: (NoteEntity) -> Unit
|
onNoteClick: (NoteEntity) -> Unit,
|
||||||
|
onDeleteNote: (NoteEntity) -> Unit
|
||||||
) {
|
) {
|
||||||
val columns = 2 // Anzahl Spalten, ggf. responsiv machen
|
val columns = 2 // Anzahl Spalten, ggf. responsiv machen
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
@ -204,32 +309,7 @@ fun NoteGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
items(notes) { note ->
|
items(notes) { note ->
|
||||||
Column(
|
NoteItem(note, onNoteClick = {}, onEditTitle = {}, onDeleteNote = {onDeleteNote(note)})
|
||||||
modifier = Modifier
|
|
||||||
.height(120.dp)
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(MaterialTheme.colorScheme.surfaceVariant)
|
|
||||||
.clickable { onNoteClick(note) }
|
|
||||||
.padding(12.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
AsyncImage(
|
|
||||||
model = note.imagePreview,
|
|
||||||
contentDescription = "Noten-Vorschau",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(64.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp)),
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = note.title,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
modifier = Modifier.padding(top = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,7 +384,10 @@ fun NotesScreen(
|
|||||||
collections = collections,
|
collections = collections,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
onCollectionClick = { viewModel.loadContentForParent(it.id, it) },
|
onCollectionClick = { viewModel.loadContentForParent(it.id, it) },
|
||||||
onNoteClick = { /* TODO: Öffnen oder Bearbeiten */ }
|
onNoteClick = { /* TODO: Öffnen oder Bearbeiten */ },
|
||||||
|
onDeleteNote = {
|
||||||
|
viewModel.removeNote(noteEntity = it)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,12 @@ class NoteBrowserViewModel (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeNote(noteEntity: NoteEntity) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
noteRepository.delete(noteEntity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun navigateToLevel(index: Int) {
|
fun navigateToLevel(index: Int) {
|
||||||
val newStack = _pathStack.value.take(index + 1)
|
val newStack = _pathStack.value.take(index + 1)
|
||||||
_pathStack.value = newStack
|
_pathStack.value = newStack
|
||||||
|
Loading…
Reference in New Issue
Block a user