parent
61113b6f5a
commit
acb519df85
@ -0,0 +1,25 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import android.app.Application |
||||
import com.google.gson.reflect.TypeToken |
||||
import com.gyf.csams.module.ApiResponse |
||||
import com.gyf.csams.module.AuditRenameVo |
||||
import com.gyf.lib.util.AssociationApi |
||||
import com.gyf.lib.util.UrlPath |
||||
import java.lang.reflect.Type |
||||
|
||||
|
||||
class AuditRenameViewModel(application: Application) : |
||||
BaseAuditViewModel<AuditRenameVo>(application) { |
||||
|
||||
override val auditApi: UrlPath = AssociationApi.RenameAudit |
||||
override val acceptApi: UrlPath = AssociationApi.RenameAccept |
||||
override val checkApi: UrlPath = AssociationApi.RenameCheck |
||||
override val typeToken: Type = |
||||
object : TypeToken<ApiResponse<MutableList<AuditRenameVo>>>() {}.type |
||||
|
||||
|
||||
init { |
||||
load() |
||||
} |
||||
} |
@ -1,29 +1,22 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import android.app.Activity |
||||
import androidx.lifecycle.ViewModel |
||||
import com.gyf.csams.main.ui.AuditActActivity |
||||
import com.gyf.csams.main.ui.AuditAssociationActivity |
||||
import com.gyf.csams.main.ui.RenameActivity |
||||
import com.gyf.csams.main.ui.* |
||||
|
||||
enum class MenuType(val desc: String, val clazz: Map<String, Class<out Activity>>) { |
||||
Association( |
||||
"社团管理", |
||||
mapOf( |
||||
// TODO "社团信息管理" to AssociationManagementActivity::class.java, |
||||
"审核社团换名" to RenameActivity::class.java, |
||||
"社团信息管理" to AssociationManagementActivity::class.java, |
||||
"审核社团换名" to AuditRenameActivity::class.java, |
||||
"审核社团注册" to AuditAssociationActivity::class.java |
||||
), |
||||
), |
||||
Act( |
||||
"活动管理", mapOf( |
||||
"审核社团活动" to AuditActActivity::class.java, |
||||
// TODO "审核质量报告单" to CheckQualityReportActivity::class.java, |
||||
// "查看社团活动" to ManagerActActivity::class.java |
||||
"审核质量报告单" to CheckQualityReportActivity::class.java, |
||||
"查看社团活动" to ManagerActActivity::class.java |
||||
) |
||||
) |
||||
} |
||||
|
||||
class MenuViewModel : ViewModel() { |
||||
|
||||
} |
@ -1,46 +0,0 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.viewModelScope |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.module.RenameVo |
||||
import com.gyf.lib.model.ScrollViewModel |
||||
import com.gyf.lib.uikit.StringForm |
||||
|
||||
import com.gyf.lib.util.randomChinese |
||||
import com.gyf.lib.util.randomNum |
||||
import kotlinx.coroutines.launch |
||||
|
||||
|
||||
class RenameViewModel(application: Application) : ScrollViewModel<RenameVo>(application) { |
||||
|
||||
val approverOrigin = |
||||
StringForm( |
||||
formDesc = application.getString(R.string.first_approver_origin), |
||||
textLength = 30 |
||||
) |
||||
|
||||
|
||||
override val initSize: Int = 10 |
||||
|
||||
init { |
||||
load() |
||||
} |
||||
|
||||
fun load() { |
||||
viewModelScope.launch { |
||||
_data.value?.apply { |
||||
repeat(initSize) { |
||||
add( |
||||
RenameVo( |
||||
studentId = randomNum(8), |
||||
oldName = randomChinese(5), |
||||
newName = randomChinese(5), |
||||
reason = randomChinese(10) |
||||
) |
||||
) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
package com.gyf.csams.main.ui |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.layout.Column |
||||
import androidx.compose.foundation.layout.Spacer |
||||
import androidx.compose.foundation.layout.height |
||||
import androidx.compose.material.ExperimentalMaterialApi |
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.runtime.ExperimentalComposeApi |
||||
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.google.accompanist.insets.ExperimentalAnimatedInsets |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.main.model.AuditRenameViewModel |
||||
import com.gyf.csams.module.AuditRenameVo |
||||
import com.gyf.csams.uikit.CheckForm |
||||
import com.gyf.csams.uikit.RowItem |
||||
import com.gyf.csams.uikit.TestTable |
||||
import com.gyf.csams.uikit.TestTableImeSimple |
||||
import com.gyf.lib.uikit.ImeBody |
||||
|
||||
class AuditRenameActivity : ComponentActivity() { |
||||
|
||||
@ExperimentalMaterialApi |
||||
@ExperimentalAnimatedInsets |
||||
@ExperimentalComposeApi |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
setContent { |
||||
TestTable(clazz = AuditRenameViewModel::class.java, title = R.string.rename_form) { |
||||
RenameForm(vo = it) |
||||
} |
||||
ImeBody { |
||||
val model: AuditRenameViewModel = viewModel() |
||||
val data by model.data.observeAsState() |
||||
TestTableImeSimple( |
||||
title = R.string.rename_form |
||||
) { |
||||
data?.forEach { |
||||
item { |
||||
RenameForm(vo = it) |
||||
CheckForm<AuditRenameVo, AuditRenameViewModel>(vo = it) |
||||
Spacer(modifier = Modifier.height(10.dp)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun RenameForm( |
||||
modifier: Modifier = Modifier, |
||||
vo: AuditRenameVo |
||||
) { |
||||
Column(modifier = modifier) { |
||||
val baseHeight = 50.dp |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.petitioner, |
||||
value = vo.audit.user.name |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.oldname, |
||||
value = vo.associationVo.name |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.newname, |
||||
value = vo.renameVo.newName |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight * 3), |
||||
key = R.string.reason_for_application, |
||||
value = vo.renameVo.cause |
||||
) |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,87 +0,0 @@ |
||||
package com.gyf.csams.main.ui |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.layout.Column |
||||
import androidx.compose.foundation.layout.fillMaxSize |
||||
import androidx.compose.foundation.layout.fillMaxWidth |
||||
import androidx.compose.foundation.layout.height |
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.runtime.ExperimentalComposeApi |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.res.stringResource |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import com.google.accompanist.insets.ExperimentalAnimatedInsets |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.main.model.RenameViewModel |
||||
import com.gyf.csams.module.RenameVo |
||||
import com.gyf.csams.uikit.RowItem |
||||
import com.gyf.csams.uikit.TestTable |
||||
import com.gyf.lib.uikit.BaseTextField |
||||
import com.gyf.lib.uikit.ScaffoldModel |
||||
import com.gyf.lib.util.BottomButton |
||||
|
||||
class RenameActivity : ComponentActivity() { |
||||
|
||||
@ExperimentalAnimatedInsets |
||||
@ExperimentalComposeApi |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
setContent { |
||||
TestTable(clazz = RenameViewModel::class.java, title = R.string.rename_form) { |
||||
RenameForm(renameVo = it) |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun RenameForm( |
||||
modifier: Modifier = Modifier, model: RenameViewModel = viewModel(), |
||||
scaffoldModel: ScaffoldModel = viewModel(), renameVo: RenameVo |
||||
) { |
||||
Column(modifier = modifier) { |
||||
val baseHeight = 50.dp |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.petitioner, |
||||
value = renameVo.studentId |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.oldname, |
||||
value = renameVo.oldName |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), |
||||
key = R.string.newname, |
||||
value = renameVo.newName |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight * 3), |
||||
key = R.string.reason_for_application, |
||||
value = renameVo.reason |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), key = R.string.first_approver, value = "" |
||||
/**TODO 获取审批人**/ |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight * 3), |
||||
key = R.string.first_approver_origin |
||||
) { |
||||
BaseTextField(modifier = Modifier.fillMaxSize(), form = model.approverOrigin) |
||||
} |
||||
val message = stringResource(id = R.string.not_impl_error) |
||||
BottomButton( |
||||
confirmDesc = R.string.reported_btn, backDesc = R.string.reject_btn, |
||||
modifier = Modifier.fillMaxWidth() |
||||
) { |
||||
scaffoldModel.update(message = message) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,99 +0,0 @@ |
||||
package com.gyf.csams.association.ui |
||||
|
||||
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.ui.Modifier |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import com.gyf.csams.association.model.RenameViewModel |
||||
import com.gyf.csams.uikit.Background |
||||
import com.gyf.csams.uikit.BackgroundImage |
||||
import com.gyf.lib.uikit.BaseTextField |
||||
import com.gyf.lib.uikit.Body |
||||
import com.gyf.lib.uikit.MainColumnFrame |
||||
import com.gyf.lib.uikit.ScaffoldModel |
||||
import com.gyf.lib.util.BottomButton |
||||
|
||||
/** |
||||
* 社团重命名 |
||||
* |
||||
*/ |
||||
class ReNameActivity : ComponentActivity() { |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
setContent { |
||||
Body { |
||||
MainColumnFrame(background = { Background(image = BackgroundImage.Rename) }) { |
||||
Spacer( |
||||
modifier = Modifier |
||||
.weight(0.2F) |
||||
) |
||||
Title(modifier = Modifier.weight(0.1F)) |
||||
|
||||
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 model: RenameViewModel = viewModel() |
||||
val scaffoldModel: ScaffoldModel = viewModel() |
||||
BottomButton( |
||||
modifier = Modifier |
||||
.weight(0.1F) |
||||
.fillMaxWidth() |
||||
) { |
||||
model.post { scaffoldModel.update(message = it) } |
||||
} |
||||
|
||||
Spacer(modifier = Modifier.weight(1 - 0.2F * 2 - 0.1F * 4)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 标题 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun Title(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) { |
||||
Row(modifier = modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { |
||||
Text(text = model.menuName, style = MaterialTheme.typography.h4) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 社团原名 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun OldName(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) { |
||||
BaseTextField(form = model.oldName, modifier = modifier.fillMaxWidth(), singeLine = true) |
||||
} |
||||
|
||||
/** |
||||
* 社团新名 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun NewName(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) { |
||||
BaseTextField(form = model.newName, modifier = modifier.fillMaxWidth(), singeLine = true) |
||||
} |
||||
|
||||
/** |
||||
* 换名原因 |
||||
* |
||||
*/ |
||||
@Composable |
||||
private fun Cause(modifier: Modifier = Modifier, model: RenameViewModel = viewModel()) { |
||||
BaseTextField(form = model.cause, modifier = modifier.fillMaxWidth()) |
||||
} |
||||
} |
@ -0,0 +1,195 @@ |
||||
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 oldNameStatus by model.oldName.statusForm.observeAsState() |
||||
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) |
||||
) |
||||
} |
||||
} |
Loading…
Reference in new issue