Fix profile navigation

This commit is contained in:
世界
2026-03-16 19:31:25 +08:00
parent a7caf965a0
commit b3515329c2
4 changed files with 10 additions and 19 deletions

View File

@@ -92,12 +92,11 @@ fun EditProfileContentScreen(
profileId: Long,
onNavigateBack: () -> Unit,
modifier: Modifier = Modifier,
profileName: String = "",
isReadOnly: Boolean = false,
) {
val viewModel: EditProfileContentViewModel =
viewModel(
factory = EditProfileContentViewModel.Factory(profileId, profileName, isReadOnly),
factory = EditProfileContentViewModel.Factory(profileId, isReadOnly),
)
val uiState by viewModel.uiState.collectAsState()
val context = LocalContext.current

View File

@@ -38,11 +38,10 @@ data class EditProfileContentUiState(
val profileName: String = "", // Add profile name
)
class EditProfileContentViewModel(private val profileId: Long, initialProfileName: String = "", initialIsReadOnly: Boolean = false) : ViewModel() {
class EditProfileContentViewModel(private val profileId: Long, initialIsReadOnly: Boolean = false) : ViewModel() {
private val _uiState =
MutableStateFlow(
EditProfileContentUiState(
profileName = initialProfileName,
isReadOnly = initialIsReadOnly,
),
)
@@ -211,7 +210,7 @@ class EditProfileContentViewModel(private val profileId: Long, initialProfileNam
originalContent = content,
hasUnsavedChanges = false,
isLoading = false,
// Keep profileName and isReadOnly from initial state - no need to update
profileName = loadedProfile.name,
)
}
}
@@ -584,13 +583,12 @@ class EditProfileContentViewModel(private val profileId: Long, initialProfileNam
class Factory(
private val profileId: Long,
private val initialProfileName: String = "",
private val initialIsReadOnly: Boolean = false,
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(EditProfileContentViewModel::class.java)) {
return EditProfileContentViewModel(profileId, initialProfileName, initialIsReadOnly) as T
return EditProfileContentViewModel(profileId, initialIsReadOnly) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}

View File

@@ -10,6 +10,7 @@ import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import android.net.Uri
import androidx.navigation.navArgument
@Composable
@@ -64,12 +65,12 @@ fun EditProfileRoute(profileId: Long, onNavigateBack: () -> Unit, modifier: Modi
profileId = profileId,
onNavigateBack = onNavigateBack,
onNavigateToIconSelection = { currentIconId ->
navController.navigate("icon_selection/${currentIconId ?: "null"}") {
navController.navigate("icon_selection/${Uri.encode(currentIconId ?: "null")}") {
launchSingleTop = true
}
},
onNavigateToEditContent = { profileName, isReadOnly ->
navController.navigate("edit_content/$profileName/$isReadOnly") {
onNavigateToEditContent = { isReadOnly ->
navController.navigate("edit_content/$isReadOnly") {
launchSingleTop = true
}
},
@@ -128,13 +129,9 @@ fun EditProfileRoute(profileId: Long, onNavigateBack: () -> Unit, modifier: Modi
}
composable(
route = "edit_content/{profileName}/{isReadOnly}",
route = "edit_content/{isReadOnly}",
arguments =
listOf(
navArgument("profileName") {
type = NavType.StringType
defaultValue = ""
},
navArgument("isReadOnly") {
type = NavType.BoolType
defaultValue = false
@@ -165,7 +162,6 @@ fun EditProfileRoute(profileId: Long, onNavigateBack: () -> Unit, modifier: Modi
)
},
) { backStackEntry ->
val profileName = backStackEntry.arguments?.getString("profileName") ?: ""
val isReadOnly = backStackEntry.arguments?.getBoolean("isReadOnly") ?: false
EditProfileContentScreen(
@@ -173,7 +169,6 @@ fun EditProfileRoute(profileId: Long, onNavigateBack: () -> Unit, modifier: Modi
onNavigateBack = {
navController.popBackStack("edit_profile", inclusive = false)
},
profileName = profileName,
isReadOnly = isReadOnly,
)
}

View File

@@ -79,7 +79,7 @@ fun EditProfileScreen(
profileId: Long,
onNavigateBack: () -> Unit,
onNavigateToIconSelection: (currentIconId: String?) -> Unit = {},
onNavigateToEditContent: (profileName: String, isReadOnly: Boolean) -> Unit = { _, _ -> },
onNavigateToEditContent: (isReadOnly: Boolean) -> Unit = {},
viewModel: EditProfileViewModel = viewModel(),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
@@ -473,7 +473,6 @@ fun EditProfileScreen(
.clip(RoundedCornerShape(12.dp))
.clickable {
onNavigateToEditContent(
uiState.name,
uiState.profileType == TypedProfile.Type.Remote,
)
},