ADD: Rename Collections
This commit is contained in:
parent
71d56519b2
commit
8e8eecf367
@ -44,6 +44,7 @@ import come.stormborntales.notevault.data.local.entity.NoteEntity
|
|||||||
fun CollectionItem(
|
fun CollectionItem(
|
||||||
collection: NoteCollection,
|
collection: NoteCollection,
|
||||||
onDeleteCollection: (NoteCollection) -> Unit,
|
onDeleteCollection: (NoteCollection) -> Unit,
|
||||||
|
onEditCollection: (NoteCollection) -> Unit,
|
||||||
) {
|
) {
|
||||||
var showMenu by remember { mutableStateOf(false) }
|
var showMenu by remember { mutableStateOf(false) }
|
||||||
Box(
|
Box(
|
||||||
@ -103,7 +104,7 @@ fun CollectionItem(
|
|||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = {
|
onClick = {
|
||||||
showMenu = false
|
showMenu = false
|
||||||
|
onEditCollection(collection)
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
Row(
|
Row(
|
||||||
|
@ -62,10 +62,11 @@ import come.stormborntales.notevault.ui.viewmodel.NoteBrowserViewModel
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CreateCollectionDialog(
|
fun CreateCollectionDialog(
|
||||||
|
editedCollection: NoteCollection?,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onCreate: (String) -> Unit
|
onCreate: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
var collectionName by remember { mutableStateOf("") }
|
var collectionName by remember { mutableStateOf(editedCollection?.name ?: "") }
|
||||||
var isError by remember { mutableStateOf(false) }
|
var isError by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
@ -165,7 +166,8 @@ fun NoteGrid(
|
|||||||
onNoteClick: (NoteEntity) -> Unit,
|
onNoteClick: (NoteEntity) -> Unit,
|
||||||
onDeleteNote: (NoteEntity) -> Unit,
|
onDeleteNote: (NoteEntity) -> Unit,
|
||||||
onEditNote: (NoteEntity) ->Unit,
|
onEditNote: (NoteEntity) ->Unit,
|
||||||
onDeleteCollection: (NoteCollection) -> Unit
|
onDeleteCollection: (NoteCollection) -> Unit,
|
||||||
|
onEditCollection: (NoteCollection) -> Unit,
|
||||||
) {
|
) {
|
||||||
var showCollectionConfirmationDialog by remember { mutableStateOf(false) }
|
var showCollectionConfirmationDialog by remember { mutableStateOf(false) }
|
||||||
var deletedCollection: NoteCollection? by remember { mutableStateOf(null) }
|
var deletedCollection: NoteCollection? by remember { mutableStateOf(null) }
|
||||||
@ -180,7 +182,7 @@ fun NoteGrid(
|
|||||||
CollectionItem(collection, onDeleteCollection = {
|
CollectionItem(collection, onDeleteCollection = {
|
||||||
showCollectionConfirmationDialog = true
|
showCollectionConfirmationDialog = true
|
||||||
deletedCollection = collection
|
deletedCollection = collection
|
||||||
})
|
}, onEditCollection = onEditCollection)
|
||||||
}
|
}
|
||||||
|
|
||||||
items(notes) { note ->
|
items(notes) { note ->
|
||||||
@ -204,7 +206,7 @@ fun NotesScreen(
|
|||||||
) {
|
) {
|
||||||
var menuExpanded by remember { mutableStateOf(false) }
|
var menuExpanded by remember { mutableStateOf(false) }
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
var collectionToEdit by remember { mutableStateOf<NoteCollection?>(null) }
|
||||||
|
|
||||||
val collections by viewModel.currentCollections.collectAsState()
|
val collections by viewModel.currentCollections.collectAsState()
|
||||||
val notes by viewModel.currentNotes.collectAsState()
|
val notes by viewModel.currentNotes.collectAsState()
|
||||||
@ -273,6 +275,10 @@ fun NotesScreen(
|
|||||||
onEditNote = onEditNote,
|
onEditNote = onEditNote,
|
||||||
onDeleteCollection = {
|
onDeleteCollection = {
|
||||||
viewModel.removeCollection(noteCollection = it)
|
viewModel.removeCollection(noteCollection = it)
|
||||||
|
},
|
||||||
|
onEditCollection = {
|
||||||
|
collectionToEdit = it
|
||||||
|
showDialog = true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -284,9 +290,14 @@ fun NotesScreen(
|
|||||||
CreateCollectionDialog(
|
CreateCollectionDialog(
|
||||||
onDismiss = { showDialog = false },
|
onDismiss = { showDialog = false },
|
||||||
onCreate = { name ->
|
onCreate = { name ->
|
||||||
|
if(collectionToEdit != null) {
|
||||||
|
viewModel.updateCollection(collectionToEdit!!, name)
|
||||||
|
} else {
|
||||||
// Handle the new collection name
|
// Handle the new collection name
|
||||||
viewModel.createCollection(name)
|
viewModel.createCollection(name)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
editedCollection = collectionToEdit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,5 +89,15 @@ class NoteBrowserViewModel (
|
|||||||
loadContentForParent(newParentId)
|
loadContentForParent(newParentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateCollection(collectionToEdit: NoteCollection, name: String) {
|
||||||
|
if(name.isNotEmpty()) {
|
||||||
|
collectionToEdit.name = name
|
||||||
|
viewModelScope.launch {
|
||||||
|
collectionRepository.updateCollection(collectionToEdit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user