You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
6.4 KiB
194 lines
6.4 KiB
package com.gyf.csams.association.ui
|
|
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.gyf.csams.association.model.AssociationViewModel
|
|
import com.gyf.csams.association.model.RenameViewModel
|
|
import com.gyf.csams.module.CheckStatus
|
|
import com.gyf.csams.uikit.Background
|
|
import com.gyf.csams.uikit.BackgroundImage
|
|
import com.gyf.csams.uikit.CheckTip
|
|
import com.gyf.lib.uikit.BaseTextField
|
|
import com.gyf.lib.uikit.Body
|
|
import com.gyf.lib.uikit.MainColumnFrame
|
|
import com.gyf.lib.uikit.checkForm
|
|
import com.gyf.lib.util.BottomButton
|
|
import com.orhanobut.logger.Logger
|
|
|
|
/**
|
|
* 社团重命名
|
|
*
|
|
*/
|
|
class RenameActivity : ComponentActivity() {
|
|
|
|
private val associationId: Int
|
|
get() {
|
|
val id = intent.getIntExtra(
|
|
AssociationActivity::class.java.name,
|
|
0
|
|
)
|
|
return if (id == 0) throw IllegalArgumentException("社团id:${id}不合法,初始化失败") else id
|
|
}
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContent {
|
|
Body {
|
|
MainColumnFrame(background = { Background(image = BackgroundImage.Rename) }) {
|
|
val model: RenameViewModel = viewModel()
|
|
val checkInfo by model.checkInfo.observeAsState()
|
|
|
|
checkInfo?.body?.auditCheckVo.let {
|
|
if (it == null) {
|
|
Title(modifier = Modifier.weight(0.2F))
|
|
} else {
|
|
Title()
|
|
CheckTip(it = it, modifier = Modifier.weight(0.15F))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
OldName(modifier = Modifier.weight(0.1F))
|
|
|
|
NewName(modifier = Modifier.weight(0.1F))
|
|
|
|
Cause(modifier = Modifier.weight(0.2F))
|
|
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
|
|
val newNameStatus by model.newName.statusForm.observeAsState()
|
|
|
|
|
|
val cause by model.cause.statusForm.observeAsState()
|
|
|
|
val hasError = repeatError()
|
|
BottomButton(
|
|
modifier = Modifier
|
|
.weight(0.1F)
|
|
.fillMaxWidth(),
|
|
enabled = checkForm(newNameStatus, cause) && !hasError
|
|
) {
|
|
|
|
model.apply(associationId = associationId)
|
|
}
|
|
|
|
|
|
val actionResult by model.actionResult.observeAsState()
|
|
actionResult?.let {
|
|
if (it.isNotEmpty()) {
|
|
setResult(
|
|
RESULT_OK,
|
|
Intent().apply {
|
|
putExtra(
|
|
RenameActivity::class.java.name,
|
|
actionResult
|
|
)
|
|
})
|
|
finish()
|
|
} else {
|
|
Logger.w("申请已提交,但是没有收到返回")
|
|
}
|
|
}
|
|
|
|
Spacer(modifier = Modifier.weight(1 - 0.2F * 2 - 0.1F * 4))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO 合并ValidStringForm
|
|
@Composable
|
|
private fun repeatError(model: RenameViewModel = viewModel()): Boolean {
|
|
val oldName by model.oldName.formValue.observeAsState()
|
|
val newName by model.newName.formValue.observeAsState()
|
|
return oldName?.isNotEmpty() == true && newName?.isNotEmpty() == true && oldName == newName
|
|
}
|
|
|
|
@Composable
|
|
private fun isReadOnly(model: RenameViewModel): Boolean {
|
|
val checkInfo by model.checkInfo.observeAsState()
|
|
val flag = (checkInfo?.body?.let { it.auditCheckVo.checkStatus != CheckStatus.Finish })
|
|
Logger.d("flag=${flag}")
|
|
return flag == true
|
|
}
|
|
|
|
/**
|
|
* 标题
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun Title(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) {
|
|
Row(modifier = modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
|
|
Text(text = model.menuName, style = MaterialTheme.typography.h6)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 社团原名
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun OldName(
|
|
modifier: Modifier = Modifier,
|
|
model: RenameViewModel = viewModel(),
|
|
ass: AssociationViewModel = viewModel()
|
|
) {
|
|
LaunchedEffect(associationId) {
|
|
ass.load(id = associationId)
|
|
}
|
|
|
|
val associationVo by ass.associationVo.observeAsState()
|
|
associationVo?.let {
|
|
model.oldName.setValue(it.associationVo.name)
|
|
}
|
|
BaseTextField(
|
|
form = model.oldName, modifier = modifier.fillMaxWidth(), singeLine = true,
|
|
readOnly = true, isError = repeatError()
|
|
)
|
|
|
|
if (repeatError()) {
|
|
Text(text = "社团原名和社团新名不能重复", color = MaterialTheme.colors.error)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 社团新名
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun NewName(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) {
|
|
BaseTextField(
|
|
form = model.newName, modifier = modifier.fillMaxWidth(), singeLine = true,
|
|
readOnly = isReadOnly(model = model), isError = repeatError()
|
|
)
|
|
if (repeatError()) {
|
|
Text(text = "社团原名和社团新名不能重复", color = MaterialTheme.colors.error)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 换名原因
|
|
*
|
|
*/
|
|
@Composable
|
|
private fun Cause(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) {
|
|
BaseTextField(
|
|
form = model.cause, modifier = modifier.fillMaxWidth(),
|
|
readOnly = isReadOnly(model = model)
|
|
)
|
|
}
|
|
} |