界面逻辑优化

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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