界面逻辑优化
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,13 +493,25 @@ fun AddAgentScreen() {
|
|||||||
navController.navigate(NavigationRoute.AgentImageCrop.route)
|
navController.navigate(NavigationRoute.AgentImageCrop.route)
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
){
|
||||||
Icon(
|
// 如果已有裁剪后的头像,则显示头像,否则显示编辑图标
|
||||||
painter = painterResource(id = R.mipmap.icons_infor_edit),
|
if (model.croppedBitmap != null) {
|
||||||
contentDescription = "Edit",
|
Image(
|
||||||
tint = Color.White,
|
bitmap = model.croppedBitmap!!.asImageBitmap(),
|
||||||
modifier = Modifier.size(20.dp),
|
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))
|
Spacer(modifier = Modifier.height(18.dp))
|
||||||
// 原版两个输入框
|
// 原版两个输入框
|
||||||
@@ -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,12 +681,24 @@ fun AddAgentScreen() {
|
|||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Icon(
|
// 如果已有裁剪后的头像,则显示头像,否则显示编辑图标
|
||||||
painter = painterResource(id = R.mipmap.icons_infor_edit),
|
if (model.croppedBitmap != null) {
|
||||||
contentDescription = "Edit",
|
Image(
|
||||||
tint = Color.White,
|
bitmap = model.croppedBitmap!!.asImageBitmap(),
|
||||||
modifier = Modifier.size(20.dp),
|
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))
|
Spacer(modifier = Modifier.height(18.dp))
|
||||||
@@ -697,6 +736,7 @@ fun AddAgentScreen() {
|
|||||||
onDescChange(value)
|
onDescChange(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//手动创造AI界面
|
||||||
}
|
}
|
||||||
|
|
||||||
// 错误信息显示
|
// 错误信息显示
|
||||||
@@ -730,67 +770,41 @@ 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()
|
||||||
// 验证输入
|
if (validationError != null) {
|
||||||
val validationError = model.validate()
|
// 显示验证错误
|
||||||
if (validationError != null) {
|
errorMessage = validationError
|
||||||
// 显示验证错误
|
|
||||||
errorMessage = validationError
|
|
||||||
model.viewModelScope.launch {
|
|
||||||
kotlinx.coroutines.delay(3000)
|
|
||||||
errorMessage = null
|
|
||||||
}
|
|
||||||
return@ActionButton
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清除之前的错误信息
|
|
||||||
errorMessage = null
|
|
||||||
|
|
||||||
// 调用创建智能体API
|
|
||||||
model.viewModelScope.launch {
|
model.viewModelScope.launch {
|
||||||
try {
|
kotlinx.coroutines.delay(3000)
|
||||||
val result = model.createAgent(context)
|
errorMessage = null
|
||||||
if (result != null) {
|
|
||||||
// 创建成功,清空数据并关闭页面
|
|
||||||
model.clearData()
|
|
||||||
navController.popBackStack()
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// 显示错误信息
|
|
||||||
errorMessage = "创建智能体失败: ${e.message}"
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (isCreatingAgent && showWaveAnimation) {
|
|
||||||
return@ActionButton
|
return@ActionButton
|
||||||
} else {
|
}
|
||||||
if (tempDesc.isEmpty()) {
|
|
||||||
errorMessage = "智能体描述不能为空"
|
// 清除之前的错误信息
|
||||||
model.viewModelScope.launch {
|
errorMessage = null
|
||||||
kotlinx.coroutines.delay(3000)
|
|
||||||
errorMessage = null
|
// 调用创建智能体API
|
||||||
}
|
model.viewModelScope.launch {
|
||||||
return@ActionButton
|
try {
|
||||||
|
val result = model.createAgent(context)
|
||||||
|
if (result != null) {
|
||||||
|
// 创建成功,清空数据并关闭页面
|
||||||
|
model.clearData()
|
||||||
|
navController.popBackStack()
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
// 清除之前的错误信息
|
// 显示错误信息
|
||||||
errorMessage = null
|
errorMessage = "创建智能体失败: ${e.message}"
|
||||||
|
e.printStackTrace()
|
||||||
// 开始构思过程
|
// 3秒后清除错误信息
|
||||||
isCreatingAgent = true
|
kotlinx.coroutines.delay(3000)
|
||||||
showWaveAnimation = true
|
errorMessage = null
|
||||||
|
|
||||||
// 添加延时
|
|
||||||
model.viewModelScope.launch {
|
|
||||||
kotlinx.coroutines.delay(2000)
|
|
||||||
showWaveAnimation = false
|
|
||||||
showManualCreationForm = true
|
|
||||||
onDescChange(tempDesc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user