发布动态提示词
逻辑:添加图片可发布,只有文字不可发布
This commit is contained in:
@@ -39,6 +39,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.aiosman.ravenow.AppState
|
||||||
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
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
@@ -59,17 +60,21 @@ fun TextInputField(
|
|||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
customBackgroundColor: Color? = null,
|
customBackgroundColor: Color? = null,
|
||||||
|
customHintColor: Color? = null,
|
||||||
|
customLabelColor: Color? = null,
|
||||||
customCornerRadius: Float = 24f
|
customCornerRadius: Float = 24f
|
||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
var showPassword by remember { mutableStateOf(!password) }
|
var showPassword by remember { mutableStateOf(!password) }
|
||||||
var isFocused by remember { mutableStateOf(false) }
|
var isFocused by remember { mutableStateOf(false) }
|
||||||
val backgroundColor = customBackgroundColor ?: AppColors.inputBackground
|
val backgroundColor = customBackgroundColor ?: AppColors.inputBackground
|
||||||
|
val hintColor = customHintColor ?: HintTextColor
|
||||||
|
val labelColor = customLabelColor ?: LabelTextColor
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
label?.let {
|
label?.let {
|
||||||
Text(
|
Text(
|
||||||
text = it,
|
text = it,
|
||||||
color = LabelTextColor,
|
color = labelColor,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
modifier = Modifier.padding(start = 8.dp, top = 8.dp, bottom = 8.dp)
|
modifier = Modifier.padding(start = 8.dp, top = 8.dp, bottom = 8.dp)
|
||||||
)
|
)
|
||||||
@@ -121,13 +126,19 @@ fun TextInputField(
|
|||||||
if (text.isEmpty() && hint != null) {
|
if (text.isEmpty() && hint != null) {
|
||||||
Text(
|
Text(
|
||||||
text = hint,
|
text = hint,
|
||||||
color = HintTextColor,
|
color = hintColor,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W400
|
fontWeight = FontWeight.W400
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (password) {
|
if (password) {
|
||||||
|
// 暗色模式下图标为白色,否则使用默认颜色
|
||||||
|
val iconColor = if (AppState.darkMode) {
|
||||||
|
Color.White
|
||||||
|
} else {
|
||||||
|
PasswordIconColor
|
||||||
|
}
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if (showPassword) {
|
id = if (showPassword) {
|
||||||
@@ -142,7 +153,7 @@ fun TextInputField(
|
|||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
showPassword = !showPassword
|
showPassword = !showPassword
|
||||||
},
|
},
|
||||||
colorFilter = ColorFilter.tint(PasswordIconColor)
|
colorFilter = ColorFilter.tint(iconColor)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,17 +72,8 @@ fun UserAuthScreen() {
|
|||||||
var passwordError by remember { mutableStateOf<String?>(null) }
|
var passwordError by remember { mutableStateOf<String?>(null) }
|
||||||
var captchaInfo by remember { mutableStateOf<CaptchaInfo?>(null) }
|
var captchaInfo by remember { mutableStateOf<CaptchaInfo?>(null) }
|
||||||
fun validateForm(): Boolean {
|
fun validateForm(): Boolean {
|
||||||
// 如果密码为空,先检查邮箱格式
|
emailError =
|
||||||
if (password.isEmpty()) {
|
if (email.isEmpty()) context.getString(R.string.text_error_email_required) else null
|
||||||
emailError = when {
|
|
||||||
email.isEmpty() -> context.getString(R.string.text_error_email_required)
|
|
||||||
!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() ->
|
|
||||||
context.getString(R.string.text_error_email_format)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
emailError = if (email.isEmpty()) context.getString(R.string.text_error_email_required) else null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用通用密码校验器
|
// 使用通用密码校验器
|
||||||
val passwordValidation = PasswordValidator.validateCurrentPassword(password, context)
|
val passwordValidation = PasswordValidator.validateCurrentPassword(password, context)
|
||||||
@@ -250,6 +241,19 @@ fun UserAuthScreen() {
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
StatusBarSpacer()
|
StatusBarSpacer()
|
||||||
|
// 暗色模式下的输入框颜色配置
|
||||||
|
val isDarkMode = AppState.darkMode
|
||||||
|
val inputBackgroundColor = if (isDarkMode) {
|
||||||
|
Color(0xFF1C1C1C) // 深灰色背景
|
||||||
|
} else {
|
||||||
|
null // 使用默认背景
|
||||||
|
}
|
||||||
|
val hintTextColor = if (isDarkMode) {
|
||||||
|
Color(0xFFFFFFFF).copy(alpha = 0.7f) // 更明显的白色 hint 文本,透明度 0.7
|
||||||
|
} else {
|
||||||
|
null // 使用默认 hint 颜色
|
||||||
|
}
|
||||||
|
|
||||||
TextInputField(
|
TextInputField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
@@ -258,7 +262,9 @@ fun UserAuthScreen() {
|
|||||||
email = it
|
email = it
|
||||||
},
|
},
|
||||||
hint = stringResource(R.string.text_hint_email),
|
hint = stringResource(R.string.text_hint_email),
|
||||||
error = emailError
|
error = emailError,
|
||||||
|
customBackgroundColor = inputBackgroundColor,
|
||||||
|
customHintColor = hintTextColor
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.padding(4.dp))
|
Spacer(modifier = Modifier.padding(4.dp))
|
||||||
TextInputField(
|
TextInputField(
|
||||||
@@ -270,7 +276,9 @@ fun UserAuthScreen() {
|
|||||||
},
|
},
|
||||||
password = true,
|
password = true,
|
||||||
hint = stringResource(R.string.text_hint_password),
|
hint = stringResource(R.string.text_hint_password),
|
||||||
error = passwordError
|
error = passwordError,
|
||||||
|
customBackgroundColor = inputBackgroundColor,
|
||||||
|
customHintColor = hintTextColor
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(32.dp))
|
Spacer(modifier = Modifier.height(32.dp))
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
|||||||
.size(24.dp)
|
.size(24.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
// 检查输入
|
// 检查输入
|
||||||
val errorMessage = model.validateMoment()
|
val errorMessage = model.validateMoment(context)
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show()
|
||||||
return@noRippleClickable
|
return@noRippleClickable
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.aiosman.ravenow.entity.MomentServiceImpl
|
|||||||
import com.aiosman.ravenow.entity.createMultipartBody
|
import com.aiosman.ravenow.entity.createMultipartBody
|
||||||
import com.aiosman.ravenow.event.MomentAddEvent
|
import com.aiosman.ravenow.event.MomentAddEvent
|
||||||
import com.aiosman.ravenow.exp.rotate
|
import com.aiosman.ravenow.exp.rotate
|
||||||
|
import com.aiosman.ravenow.R
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
|
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
|
||||||
import com.aiosman.ravenow.ui.modification.Modification
|
import com.aiosman.ravenow.ui.modification.Modification
|
||||||
import com.aiosman.ravenow.utils.FileUtil
|
import com.aiosman.ravenow.utils.FileUtil
|
||||||
@@ -151,9 +152,9 @@ object NewPostViewModel : ViewModel() {
|
|||||||
return tempFile
|
return tempFile
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateMoment(): String? {
|
fun validateMoment(context: Context): String? {
|
||||||
if (imageList.isEmpty()) {
|
if (imageList.isEmpty()) {
|
||||||
return "Please select at least one image"
|
return context.getString(R.string.error_select_at_least_one_image)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user