界面逻辑优化

This commit is contained in:
2025-09-25 18:32:34 +08:00
parent dedd356896
commit b96ae94bdb
7 changed files with 116 additions and 81 deletions

View File

@@ -78,6 +78,7 @@ import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.text.TextStyle
/**
* 添加智能体界面
@@ -109,14 +110,14 @@ fun AddAgentScreen() {
fun onDescChange(value: String) {
model.desc = value.trim()
agnetDescError = when {
value.length > 100 -> "简介长度不能大于100"
value.length > 512 -> "简介长度不能大于512"
else -> null
}
}
fun onTempDescChange(value: String) {
tempDesc = value.trim()
agnetDescError = when {
value.length > 100 -> "简介长度不能大于100"
value.length > 512 -> "简介长度不能大于512"
else -> null
}
}
@@ -247,6 +248,7 @@ fun AddAgentScreen() {
Spacer(modifier = Modifier.height(24.dp))
if (!showManualCreation) {
//自动创造AI界面
Column(
modifier = Modifier
.padding(horizontal = 20.dp)
@@ -341,7 +343,10 @@ fun AddAgentScreen() {
e.printStackTrace()
} finally {
isProcessing = false
showWaveAnimation = false // 隐藏构思动画
showWaveAnimation = false
isCreatingAgent = true
showManualCreationForm = true
onDescChange(tempDesc)
}
}
}
@@ -488,13 +493,25 @@ fun AddAgentScreen() {
navController.navigate(NavigationRoute.AgentImageCrop.route)
},
contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(id = R.mipmap.icons_infor_edit),
contentDescription = "Edit",
tint = Color.White,
modifier = Modifier.size(20.dp),
)
){
// 如果已有裁剪后的头像,则显示头像,否则显示编辑图标
if (model.croppedBitmap != null) {
Image(
bitmap = model.croppedBitmap!!.asImageBitmap(),
contentDescription = "Avatar",
modifier = Modifier
.size(72.dp)
.clip(CircleShape),
contentScale = ContentScale.Crop
)
} else {
Icon(
painter = painterResource(id = R.mipmap.icons_infor_edit),
contentDescription = "Edit",
tint = Color.White,
modifier = Modifier.size(20.dp),
)
}
}
Spacer(modifier = Modifier.height(18.dp))
// 原版两个输入框
@@ -545,6 +562,8 @@ fun AddAgentScreen() {
)
.noRippleClickable {
showManualCreation = true
tempDesc = ""
agnetDescError = null
}
) {
Row(
@@ -569,6 +588,7 @@ fun AddAgentScreen() {
}
}
}else {
//手动创造AI界面
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
@@ -602,6 +622,13 @@ fun AddAgentScreen() {
)
.noRippleClickable {
showManualCreation = false
model.name = ""
model.desc = ""
model.croppedBitmap = null
isCreatingAgent = false
showManualCreationForm = false
showWaveAnimation = false
isProcessing = false
}
) {
Row(
@@ -654,12 +681,24 @@ fun AddAgentScreen() {
},
contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(id = R.mipmap.icons_infor_edit),
contentDescription = "Edit",
tint = Color.White,
modifier = Modifier.size(20.dp),
)
// 如果已有裁剪后的头像,则显示头像,否则显示编辑图标
if (model.croppedBitmap != null) {
Image(
bitmap = model.croppedBitmap!!.asImageBitmap(),
contentDescription = "Avatar",
modifier = Modifier
.size(72.dp)
.clip(CircleShape),
contentScale = ContentScale.Crop
)
} else {
Icon(
painter = painterResource(id = R.mipmap.icons_infor_edit),
contentDescription = "Edit",
tint = Color.White,
modifier = Modifier.size(20.dp),
)
}
}
}
Spacer(modifier = Modifier.height(18.dp))
@@ -697,6 +736,7 @@ fun AddAgentScreen() {
onDescChange(value)
}
}
//手动创造AI界面
}
// 错误信息显示
@@ -730,67 +770,41 @@ fun AddAgentScreen() {
),
color = Color.White,
backgroundColor = Color.Transparent,
text = if (isCreatingAgent && showManualCreationForm) stringResource(R.string.create_confirm) else stringResource(R.string.create_confirm),
text = stringResource(R.string.create_confirm),
isLoading = model.isUpdating,
enabled = !model.isUpdating && validate()
) {
// 如果处于构思完成状态且已显示手动创建表单,则执行创建操作
if (isCreatingAgent && showManualCreationForm) {
// 验证输入
val validationError = model.validate()
if (validationError != null) {
// 显示验证错误
errorMessage = validationError
model.viewModelScope.launch {
kotlinx.coroutines.delay(3000)
errorMessage = null
}
return@ActionButton
}
// 清除之前的错误信息
errorMessage = null
// 调用创建智能体API
// 验证输入
val validationError = model.validate()
if (validationError != null) {
// 显示验证错误
errorMessage = validationError
model.viewModelScope.launch {
try {
val result = model.createAgent(context)
if (result != null) {
// 创建成功,清空数据并关闭页面
model.clearData()
navController.popBackStack()
}
} catch (e: Exception) {
// 显示错误信息
errorMessage = "创建智能体失败: ${e.message}"
e.printStackTrace()
}
kotlinx.coroutines.delay(3000)
errorMessage = null
}
} else if (isCreatingAgent && showWaveAnimation) {
return@ActionButton
} else {
if (tempDesc.isEmpty()) {
errorMessage = "智能体描述不能为空"
model.viewModelScope.launch {
kotlinx.coroutines.delay(3000)
errorMessage = null
}
return@ActionButton
}
// 清除之前的错误信息
errorMessage = null
// 调用创建智能体API
model.viewModelScope.launch {
try {
val result = model.createAgent(context)
if (result != null) {
// 创建成功,清空数据并关闭页面
model.clearData()
navController.popBackStack()
}
// 清除之前的错误信息
errorMessage = null
// 开始构思过程
isCreatingAgent = true
showWaveAnimation = true
// 添加延时
model.viewModelScope.launch {
kotlinx.coroutines.delay(2000)
showWaveAnimation = false
showManualCreationForm = true
onDescChange(tempDesc)
} catch (e: Exception) {
// 显示错误信息
errorMessage = "创建智能体失败: ${e.message}"
e.printStackTrace()
// 3秒后清除错误信息
kotlinx.coroutines.delay(3000)
errorMessage = null
}
}
}

View File

@@ -70,7 +70,7 @@ object AddAgentViewModel : ViewModel() {
name.length < 2 -> "智能体名称长度不能少于2个字符"
name.length > 20 -> "智能体名称长度不能超过20个字符"
desc.isEmpty() -> "智能体描述不能为空"
desc.length > 100 -> "智能体描述长度不能超过100个字符"
desc.length > 512 -> "智能体描述长度不能超过512个字符"
else -> null
}
}

View File

@@ -22,11 +22,15 @@ import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
@@ -34,6 +38,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
/**
* 水平布局的输入框
@@ -49,6 +54,9 @@ fun FormTextInput(
onValueChange: (String) -> Unit
) {
val AppColors = LocalAppTheme.current
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
Column(
modifier = modifier
) {
@@ -63,7 +71,11 @@ fun FormTextInput(
it
}
}
.padding(17.dp),
.padding(17.dp)
.noRippleClickable {
focusRequester.requestFocus()
keyboardController?.show()
},
verticalAlignment = Alignment.CenterVertically
) {
label?.let {
@@ -114,6 +126,8 @@ fun FormTextInput(
onValueChange = {
onValueChange(it)
},
modifier = Modifier
.focusRequester(focusRequester),
singleLine = true,
textStyle = TextStyle(
fontSize = 14.sp,
@@ -156,4 +170,4 @@ fun FormTextInput(
}
}
}
}

View File

@@ -22,6 +22,7 @@ import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -29,6 +30,7 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
@@ -36,6 +38,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
/**
* 垂直布局的输入框
@@ -52,6 +55,9 @@ fun FormTextInput2(
onValueChange: (String) -> Unit
) {
val AppColors = LocalAppTheme.current
val localFocusRequester = focusRequester ?: remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
Column(
modifier = modifier.height(150.dp)
) {
@@ -66,7 +72,11 @@ fun FormTextInput2(
it
}
}
.padding(17.dp),
.padding(17.dp)
.noRippleClickable {
localFocusRequester.requestFocus()
keyboardController?.show()
},
) {
label?.let {
@@ -118,13 +128,7 @@ fun FormTextInput2(
onValueChange(it)
},
modifier = Modifier
.let {
if (focusRequester != null) {
it.focusRequester(focusRequester)
} else {
it
}
},
.focusRequester(localFocusRequester),
textStyle = TextStyle(
fontSize = 14.sp,
fontWeight = FontWeight.Normal,

View File

@@ -17,4 +17,5 @@
<string name="create_agent_hand">手動でAIを作成</string>
<string name="create_agent_auto">一言でAIを作成</string>
<string name="agent_name_hint_1">名前を付けて、あなただけの特別な存在にしましょう</string>
<string name="create_success">スマートボディの作成が完了しました!</string>
</resources>

View File

@@ -209,4 +209,5 @@
<string name="create_agent_hand">手动创造Ai</string>
<string name="create_agent_auto">一句话创造Ai</string>
<string name="agent_name_hint_1">给它取个名字,让它成为独一无二的你</string>
<string name="create_success">智能体创建完成!</string>
</resources>

View File

@@ -205,4 +205,5 @@
<string name="create_agent_hand">Create AI Manually</string>
<string name="create_agent_auto">Create AI with One Sentence</string>
<string name="agent_name_hint_1">Give it a name to make it uniquely yours</string>
<string name="create_success">Agent creation completed!</string>
</resources>