ADD: Adding Notes to Collections
This commit is contained in:
parent
caece7bfea
commit
6df3f756ec
@ -49,6 +49,8 @@ import come.stormborntales.notevault.ui.screens.MainScreen
|
||||
import come.stormborntales.notevault.ui.screens.NotesScreen
|
||||
import come.stormborntales.notevault.ui.screens.SettingsScreen
|
||||
import come.stormborntales.notevault.ui.theme.NoteVaultTheme
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteBrowserViewModel
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteBrowserViewModelFactory
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteViewModel
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteViewModelFactory
|
||||
import kotlinx.coroutines.launch
|
||||
@ -63,12 +65,13 @@ class MainActivity : ComponentActivity() {
|
||||
val noteRepository = NoteRepository(database.noteDao())
|
||||
val collectionRepository = CollectionRepository(database.collectionDao())
|
||||
val viewModelFactory = NoteViewModelFactory(noteRepository)
|
||||
val noteBrowserViewModelFactory = NoteBrowserViewModelFactory(noteRepository, collectionRepository)
|
||||
|
||||
setContent {
|
||||
NoteVaultTheme {
|
||||
val navController = rememberNavController()
|
||||
val viewModel: NoteViewModel = viewModel(factory = viewModelFactory)
|
||||
|
||||
val noteBrowserViewModelFactory: NoteBrowserViewModel = viewModel(factory = noteBrowserViewModelFactory)
|
||||
var selectedUris by remember { mutableStateOf<List<Uri>>(emptyList()) }
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
var noteToEdit by remember { mutableStateOf<NoteEntity?>(null) }
|
||||
@ -208,7 +211,9 @@ class MainActivity : ComponentActivity() {
|
||||
SettingsScreen()
|
||||
}
|
||||
composable("notes") {
|
||||
NotesScreen(collectionRepository, noteRepository)
|
||||
NotesScreen(collectionRepository, noteRepository, onImportNotes = {
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
}, noteBrowserViewModelFactory)
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,6 +231,7 @@ class MainActivity : ComponentActivity() {
|
||||
genre = genre,
|
||||
description = description,
|
||||
selectedUris = selectedUris,
|
||||
collectionID = noteBrowserViewModelFactory.currentParentId.value,
|
||||
onDone = { showDialog = false }
|
||||
)
|
||||
} else {
|
||||
|
@ -19,7 +19,8 @@ fun AddNoteDialog(
|
||||
initialComposer: String? = null,
|
||||
initialYear: Int? = null,
|
||||
initialGenre: String? = null,
|
||||
initialDescription: String? = null
|
||||
initialDescription: String? = null,
|
||||
collectionId: Int? = null
|
||||
) {
|
||||
var title by remember { mutableStateOf(initialTitle) }
|
||||
var composer by remember { mutableStateOf(initialComposer ?: "") }
|
||||
|
@ -237,15 +237,12 @@ fun NoteGrid(
|
||||
fun NotesScreen(
|
||||
collectionRepository: CollectionRepository,
|
||||
noteRepository: NoteRepository,
|
||||
|
||||
onImportNotes: (Int?) -> Unit,
|
||||
viewModel: NoteBrowserViewModel
|
||||
) {
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current)
|
||||
val viewModel: NoteBrowserViewModel = viewModel(
|
||||
viewModelStoreOwner,
|
||||
factory = NoteBrowserViewModelFactory(noteRepository, collectionRepository)
|
||||
)
|
||||
|
||||
|
||||
val collections by viewModel.currentCollections.collectAsState()
|
||||
val notes by viewModel.currentNotes.collectAsState()
|
||||
@ -274,7 +271,7 @@ fun NotesScreen(
|
||||
text = { Text("Noten importieren") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
// Handle action
|
||||
onImportNotes(viewModel.currentParentId.value)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class NoteViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun addNote(context: Context, title: String, composer: String?, year: Int?, genre: String?, description: String?, selectedUris: List<Uri>, onDone:() -> Unit) {
|
||||
fun addNote(context: Context, title: String, composer: String?, year: Int?, genre: String?, description: String?, selectedUris: List<Uri>, collectionID: Int?, onDone:() -> Unit) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val copiedUris = selectedUris.mapNotNull { uri ->
|
||||
try {
|
||||
@ -94,7 +94,7 @@ class NoteViewModel(
|
||||
genre = genre,
|
||||
description = description,
|
||||
imagePreview = preview_image_path.toString(),
|
||||
collectionId = null
|
||||
collectionId = collectionID
|
||||
)
|
||||
|
||||
repository.insert(note)
|
||||
|
Loading…
Reference in New Issue
Block a user