From a5b5c296c30b7347071afff0b13fa9523b36259b Mon Sep 17 00:00:00 2001 From: SaiD Date: Sat, 20 Dec 2025 21:31:04 +0530 Subject: [PATCH] add profile fix --- ...kotlin-compiler-14616891166351098783.salive | 0 .../pages/addprofile/AddProfileViewModel.kt | 9 +++++---- .../livingai/pages/navigation/NavGraph.kt | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .kotlin/sessions/kotlin-compiler-14616891166351098783.salive diff --git a/.kotlin/sessions/kotlin-compiler-14616891166351098783.salive b/.kotlin/sessions/kotlin-compiler-14616891166351098783.salive new file mode 100644 index 0000000..e69de29 diff --git a/app/src/main/java/com/example/livingai/pages/addprofile/AddProfileViewModel.kt b/app/src/main/java/com/example/livingai/pages/addprofile/AddProfileViewModel.kt index 9c11aca..c0df818 100644 --- a/app/src/main/java/com/example/livingai/pages/addprofile/AddProfileViewModel.kt +++ b/app/src/main/java/com/example/livingai/pages/addprofile/AddProfileViewModel.kt @@ -1,5 +1,6 @@ package com.example.livingai.pages.addprofile +import android.util.Log import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf @@ -107,10 +108,10 @@ class AddProfileViewModel( .launchIn(viewModelScope) } - fun saveAnimalDetails(): Boolean { + fun saveAnimalDetails(currentId: String): Boolean { if (!validateInputs()) return false - val id = _currentAnimalId.value ?: return false + val id = currentId val details = AnimalDetails( animalId = id, @@ -121,9 +122,9 @@ class AddProfileViewModel( calvingNumber = calvingNumber.value.toIntOrNull() ?: 0, reproductiveStatus = reproductiveStatus.value ?: "", description = description.value, - images = photos, + images = photos.toMap(), video = _videoUri.value ?: "", - segmentedImages = segmentedImages, + segmentedImages = segmentedImages.toMap(), name = "", sex = "", weight = 0 diff --git a/app/src/main/java/com/example/livingai/pages/navigation/NavGraph.kt b/app/src/main/java/com/example/livingai/pages/navigation/NavGraph.kt index d2d4bbb..adcf39e 100644 --- a/app/src/main/java/com/example/livingai/pages/navigation/NavGraph.kt +++ b/app/src/main/java/com/example/livingai/pages/navigation/NavGraph.kt @@ -1,5 +1,6 @@ package com.example.livingai.pages.navigation +import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -62,6 +63,14 @@ fun NavGraph( val currentId by viewModel.currentAnimalId val videoUri by viewModel.videoUri + LaunchedEffect(currentId) { + when { + route.loadEntry && route.animalId != null -> viewModel.loadAnimal(route.animalId) + currentId != null -> viewModel.loadAnimal(currentId!!) + else -> viewModel.initializeNewProfileIfNeeded() + } + } + val newImageUri = backStackEntry.savedStateHandle.get("newImageUri") val newImageOrientation = backStackEntry.savedStateHandle.get("newImageOrientation") val newVideoUri = backStackEntry.savedStateHandle.get("newVideoUri") @@ -94,10 +103,11 @@ fun NavGraph( AddProfileScreen( navController = navController, viewModel = viewModel, - animalId = route.animalId, - loadEntry = route.loadEntry, - onSave = { - val isSaved = viewModel.saveAnimalDetails() + onSave = { + + Log.d("AddProfileViewModel", "Current Id: $currentId") + if (currentId == null) return@AddProfileScreen + val isSaved = viewModel.saveAnimalDetails(currentId!!) if (isSaved) navController.popBackStack(Route.HomeScreen, inclusive = false) },