diff --git a/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgent.kt b/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgent.kt index 0e36956..63b1cb8 100644 --- a/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgent.kt +++ b/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgent.kt @@ -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 } } } diff --git a/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgentViewModel.kt b/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgentViewModel.kt index 2c9d144..9def645 100644 --- a/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgentViewModel.kt +++ b/app/src/main/java/com/aiosman/ravenow/ui/agent/AddAgentViewModel.kt @@ -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 } } diff --git a/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput.kt b/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput.kt index f56a96d..3fb8fcf 100644 --- a/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput.kt +++ b/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput.kt @@ -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( } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput2.kt b/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput2.kt index 20ee7a6..46c4193 100644 --- a/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput2.kt +++ b/app/src/main/java/com/aiosman/ravenow/ui/composables/form/FormTextInput2.kt @@ -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, diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index c4c6e39..aa1193f 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -17,4 +17,5 @@ 手動でAIを作成 一言でAIを作成 名前を付けて、あなただけの特別な存在にしましょう + スマートボディの作成が完了しました! diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index eb4139e..5a04c50 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -209,4 +209,5 @@ 手动创造Ai 一句话创造Ai 给它取个名字,让它成为独一无二的你 + 智能体创建完成! \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6350b4a..238b6e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -205,4 +205,5 @@ Create AI Manually Create AI with One Sentence Give it a name to make it uniquely yours + Agent creation completed! \ No newline at end of file