Refactor: 优化关注列表和代码逻辑

本次提交主要包含以下更改:

- **关注/粉丝列表逻辑修正**:修复了在 `FollowerListViewModel` 和 `FollowingListViewModel` 中 `followerId` 和 `followingId` 属性赋值错误的问题,确保正确加载关注和粉丝列表。
- **分页大小调整**:将 `BaseFollowModel` 中分页加载的 `pageSize` 从 5 调整为 20,以提高用户体验。
- **个人资料页智能体展示**:
    - 在 `AccountProfileV2` 和 `AccountProfileViewModel` 中增加了对用户智能体列表的加载和展示逻辑。
    - 修复了 `MyProfileViewModel` 中加载当前用户智能体时 `authorId` 传递错误的问题。
    - 优化了 `UserAgentsRow` 和 `UserAgentsViewModel` 的逻辑,确保正确加载和显示用户智能体,并在用户切换时清理旧数据。
- **代码清理**:移除了部分冗余的 `println` 调试信息。
- **Agent创建流程优化**:在 `AddAgentViewModel` 和 `AgentImageCropScreen` 中,确保在已有裁剪图片时直接使用,避免重复裁剪。
This commit is contained in:
2025-08-31 23:50:52 +08:00
parent 281169cfcb
commit 2907e7f9a6
15 changed files with 35 additions and 47 deletions

View File

@@ -138,10 +138,7 @@ fun AddAgentScreen() {
contentScale = ContentScale.Crop,
placeholderRes = R.mipmap.rider_pro_agent_avatar
)
// 调试信息
LaunchedEffect(model.croppedBitmap) {
println("AddAgent: croppedBitmap changed: ${model.croppedBitmap != null}")
}
Box(
modifier = Modifier
.size(32.dp)
@@ -149,7 +146,6 @@ fun AddAgentScreen() {
.background(appColors.main)
.align(Alignment.BottomEnd)
.noRippleClickable {
println("AddAgent: Navigating to AgentImageCrop")
navController.navigate(NavigationRoute.AgentImageCrop.route)
},
contentAlignment = Alignment.Center
@@ -226,7 +222,6 @@ fun AddAgentScreen() {
if (validationError != null) {
// 显示验证错误
errorMessage = validationError
println("AddAgent: Validation error: $validationError")
return@ActionButton
}
@@ -236,16 +231,13 @@ fun AddAgentScreen() {
// 调用创建智能体API
model.viewModelScope.launch {
try {
println("AddAgent: Starting to create agent...")
val result = model.createAgent(context)
if (result != null) {
println("AddAgent: Agent created successfully, closing page")
// 创建成功,清空数据并关闭页面
model.clearData()
navController.popBackStack()
}
} catch (e: Exception) {
println("AddAgent: Error creating agent: ${e.message}")
// 显示错误信息
errorMessage = "创建智能体失败: ${e.message}"
e.printStackTrace()

View File

@@ -26,11 +26,9 @@ object AddAgentViewModel : ViewModel() {
var isFromAddAgent by mutableStateOf(false)
suspend fun updateAgentAvatar(context: Context) {
println("AddAgentViewModel: updateAgentAvatar called, croppedBitmap: ${croppedBitmap != null}")
croppedBitmap?.let {
val file = File(context.cacheDir, "agent_avatar.jpg")
it.compress(Bitmap.CompressFormat.JPEG, 100, file.outputStream())
println("AddAgentViewModel: Avatar saved to ${file.absolutePath}")
// 这里可以上传图片到服务器,暂时先保存到本地
// UploadImage(file, "agent_avatar.jpg", "", "jpg")
}
@@ -39,7 +37,6 @@ object AddAgentViewModel : ViewModel() {
suspend fun createAgent(context: Context): AgentEntity? {
try {
isUpdating = true
println("AddAgentViewModel: Creating agent with name: $name, desc: $desc")
// 准备头像文件
val avatarFile = if (croppedBitmap != null) {
@@ -57,12 +54,8 @@ object AddAgentViewModel : ViewModel() {
avatar = avatarFile
)
println("AddAgentViewModel: Agent created successfully with ID: ${result.id}")
return result
} catch (e: Exception) {
println("AddAgentViewModel: Error creating agent: ${e.message}")
} catch (e: Exception)
throw e
} finally {
isUpdating = false

View File

@@ -128,7 +128,6 @@ fun AgentImageCropScreen() {
modifier = Modifier.clickable {
if (croppedBitmap != null) {
// 如果已经有裁剪结果,直接返回
println("AgentImageCrop: Using existing cropped bitmap")
AddAgentViewModel.croppedBitmap = croppedBitmap
AddAgentViewModel.viewModelScope.launch {
AddAgentViewModel.updateAgentAvatar(context)
@@ -139,7 +138,6 @@ fun AgentImageCropScreen() {
imageCrop?.let {
val bitmap = it.onCrop()
croppedBitmap = bitmap
println("AgentImageCrop: Cropped bitmap created: ${bitmap != null}")
}
}
}