nextNoteVault #23
@ -60,6 +60,7 @@ dependencies {
 | 
			
		||||
    implementation(libs.androidx.room.runtime)
 | 
			
		||||
    implementation(libs.androidx.room.ktx)
 | 
			
		||||
    implementation(libs.lifecycle.livedata.ktx)
 | 
			
		||||
    implementation(libs.compose.runtime.livedata)
 | 
			
		||||
 | 
			
		||||
    ksp(libs.androidx.room.compiler)
 | 
			
		||||
}
 | 
			
		||||
@ -57,7 +57,7 @@ class MainActivity : ComponentActivity() {
 | 
			
		||||
 | 
			
		||||
                // UI anzeigen
 | 
			
		||||
                MainScreen(
 | 
			
		||||
                    notes = notes,
 | 
			
		||||
                    viewModel = viewModel,
 | 
			
		||||
                    onAddNoteClicked = {
 | 
			
		||||
                        imagePickerLauncher.launch(
 | 
			
		||||
                            arrayOf("image/*")
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ fun FullscreenImageViewer(
 | 
			
		||||
        HorizontalPager(state = pagerState) { page ->
 | 
			
		||||
            val context = LocalContext.current
 | 
			
		||||
            val imageBitmap = remember(images[page]) {
 | 
			
		||||
                loadImageBitmap(context, images[page])
 | 
			
		||||
                loadImageBitmap(context, images[page].toString())
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            imageBitmap?.let {
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@ import androidx.compose.material.icons.Icons
 | 
			
		||||
import androidx.compose.material.icons.filled.Add
 | 
			
		||||
import androidx.compose.material3.*
 | 
			
		||||
import androidx.compose.runtime.*
 | 
			
		||||
import androidx.compose.runtime.livedata.observeAsState
 | 
			
		||||
import androidx.compose.ui.Alignment
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.draw.clip
 | 
			
		||||
@ -23,11 +24,15 @@ import androidx.compose.ui.graphics.asImageBitmap
 | 
			
		||||
import androidx.compose.ui.platform.LocalContext
 | 
			
		||||
import androidx.compose.ui.unit.dp
 | 
			
		||||
import come.stormborntales.notevault.FullscreenImageViewerActivity
 | 
			
		||||
import come.stormborntales.notevault.data.local.entity.NoteEntity
 | 
			
		||||
import come.stormborntales.notevault.data.model.NoteEntry
 | 
			
		||||
import come.stormborntales.notevault.ui.viewmodel.NoteViewModel
 | 
			
		||||
import java.io.InputStream
 | 
			
		||||
import androidx.core.net.toUri
 | 
			
		||||
 | 
			
		||||
fun loadImageBitmap(context: Context, uri: Uri): ImageBitmap? {
 | 
			
		||||
fun loadImageBitmap(context: Context, uriString: String): ImageBitmap? {
 | 
			
		||||
    return try {
 | 
			
		||||
        val uri = uriString.toUri()
 | 
			
		||||
        val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
 | 
			
		||||
        val bitmap = BitmapFactory.decodeStream(inputStream)
 | 
			
		||||
        bitmap?.asImageBitmap()
 | 
			
		||||
@ -38,7 +43,7 @@ fun loadImageBitmap(context: Context, uri: Uri): ImageBitmap? {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun NoteCard(note: NoteEntry) {
 | 
			
		||||
fun NoteCard(note: NoteEntity) {
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val imageBitmap = remember(note.images) {
 | 
			
		||||
        note.images.firstOrNull()?.let { loadImageBitmap(context, it) }
 | 
			
		||||
@ -100,8 +105,11 @@ fun NoteCard(note: NoteEntry) {
 | 
			
		||||
                ) {
 | 
			
		||||
                    OutlinedButton(
 | 
			
		||||
                        onClick = {
 | 
			
		||||
                            val uris = ArrayList<Uri>();
 | 
			
		||||
                            note.images.forEach { uris.add(it.toUri()) }
 | 
			
		||||
 | 
			
		||||
                            val intent = Intent(context, FullscreenImageViewerActivity::class.java).apply {
 | 
			
		||||
                                putParcelableArrayListExtra("imageUris", ArrayList(note.images))
 | 
			
		||||
                                putParcelableArrayListExtra("imageUris", ArrayList(uris))
 | 
			
		||||
                            }
 | 
			
		||||
                            context.startActivity(intent)
 | 
			
		||||
                        },
 | 
			
		||||
@ -135,12 +143,9 @@ fun NoteCard(note: NoteEntry) {
 | 
			
		||||
@Composable
 | 
			
		||||
fun MainScreen(
 | 
			
		||||
    onAddNoteClicked: () -> Unit, // Übergib hier deine Logik für den Import
 | 
			
		||||
    notes: MutableList<NoteEntry>, // Liste der Notenbilder (hier als URI),
 | 
			
		||||
    viewModel: NoteViewModel
 | 
			
		||||
) {
 | 
			
		||||
    val dummyNotes = notes
 | 
			
		||||
    var noteToShow by remember { mutableStateOf<NoteEntry?>(null) }
 | 
			
		||||
    // Hole den aktuellen Context
 | 
			
		||||
    val context = LocalContext.current
 | 
			
		||||
    val notes by viewModel.notes.observeAsState(emptyList())
 | 
			
		||||
    Scaffold(
 | 
			
		||||
        topBar = {
 | 
			
		||||
            TopAppBar(
 | 
			
		||||
@ -162,7 +167,7 @@ fun MainScreen(
 | 
			
		||||
                .fillMaxSize()
 | 
			
		||||
                .padding(16.dp)
 | 
			
		||||
        ) {
 | 
			
		||||
            items(dummyNotes) { note ->
 | 
			
		||||
            items(notes) { note ->
 | 
			
		||||
                NoteCard(note = note)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,10 @@ composeBom = "2024.04.01"
 | 
			
		||||
navigationCompose = "2.8.9"
 | 
			
		||||
room = "2.7.1"
 | 
			
		||||
ksp="2.1.21-RC-2.0.0"
 | 
			
		||||
compose = "1.6.0" # oder was immer deine aktuelle Compose-Version ist
 | 
			
		||||
 | 
			
		||||
[libraries]
 | 
			
		||||
compose-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "compose" }
 | 
			
		||||
lifecycle-livedata-ktx = "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7"
 | 
			
		||||
androidx-compose-bom-v20240100 = { module = "androidx.compose:compose-bom", version.ref = "composeBomVersion" }
 | 
			
		||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user