add profile fix
This commit is contained in:
parent
2b8aadfc73
commit
a5b5c296c3
|
|
@ -1,5 +1,6 @@
|
||||||
package com.example.livingai.pages.addprofile
|
package com.example.livingai.pages.addprofile
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.mutableStateMapOf
|
import androidx.compose.runtime.mutableStateMapOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
|
@ -107,10 +108,10 @@ class AddProfileViewModel(
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveAnimalDetails(): Boolean {
|
fun saveAnimalDetails(currentId: String): Boolean {
|
||||||
if (!validateInputs()) return false
|
if (!validateInputs()) return false
|
||||||
|
|
||||||
val id = _currentAnimalId.value ?: return false
|
val id = currentId
|
||||||
|
|
||||||
val details = AnimalDetails(
|
val details = AnimalDetails(
|
||||||
animalId = id,
|
animalId = id,
|
||||||
|
|
@ -121,9 +122,9 @@ class AddProfileViewModel(
|
||||||
calvingNumber = calvingNumber.value.toIntOrNull() ?: 0,
|
calvingNumber = calvingNumber.value.toIntOrNull() ?: 0,
|
||||||
reproductiveStatus = reproductiveStatus.value ?: "",
|
reproductiveStatus = reproductiveStatus.value ?: "",
|
||||||
description = description.value,
|
description = description.value,
|
||||||
images = photos,
|
images = photos.toMap(),
|
||||||
video = _videoUri.value ?: "",
|
video = _videoUri.value ?: "",
|
||||||
segmentedImages = segmentedImages,
|
segmentedImages = segmentedImages.toMap(),
|
||||||
name = "",
|
name = "",
|
||||||
sex = "",
|
sex = "",
|
||||||
weight = 0
|
weight = 0
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.example.livingai.pages.navigation
|
package com.example.livingai.pages.navigation
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
|
@ -62,6 +63,14 @@ fun NavGraph(
|
||||||
val currentId by viewModel.currentAnimalId
|
val currentId by viewModel.currentAnimalId
|
||||||
val videoUri by viewModel.videoUri
|
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<String>("newImageUri")
|
val newImageUri = backStackEntry.savedStateHandle.get<String>("newImageUri")
|
||||||
val newImageOrientation = backStackEntry.savedStateHandle.get<String>("newImageOrientation")
|
val newImageOrientation = backStackEntry.savedStateHandle.get<String>("newImageOrientation")
|
||||||
val newVideoUri = backStackEntry.savedStateHandle.get<String>("newVideoUri")
|
val newVideoUri = backStackEntry.savedStateHandle.get<String>("newVideoUri")
|
||||||
|
|
@ -94,10 +103,11 @@ fun NavGraph(
|
||||||
AddProfileScreen(
|
AddProfileScreen(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
animalId = route.animalId,
|
|
||||||
loadEntry = route.loadEntry,
|
|
||||||
onSave = {
|
onSave = {
|
||||||
val isSaved = viewModel.saveAnimalDetails()
|
|
||||||
|
Log.d("AddProfileViewModel", "Current Id: $currentId")
|
||||||
|
if (currentId == null) return@AddProfileScreen
|
||||||
|
val isSaved = viewModel.saveAnimalDetails(currentId!!)
|
||||||
if (isSaved)
|
if (isSaved)
|
||||||
navController.popBackStack(Route.HomeScreen, inclusive = false)
|
navController.popBackStack(Route.HomeScreen, inclusive = false)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue