parent
a68a79ddb5
commit
531c022328
@ -0,0 +1,59 @@ |
||||
package com.gyf.csams.main.model |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.viewModelScope |
||||
import com.gyf.csams.R |
||||
import com.gyf.lib.ScrollListW |
||||
import com.gyf.lib.uikit.StringForm |
||||
import com.gyf.lib.util.randomChinese |
||||
import com.gyf.lib.util.randomNum |
||||
import kotlinx.coroutines.launch |
||||
|
||||
/** |
||||
* 换名申请表 |
||||
* |
||||
* @property studentId 学号 |
||||
* @property oldName 社团原名 |
||||
* @property newName 社团新名 |
||||
* @property reason 申请理由 |
||||
*/ |
||||
data class RenameVo( |
||||
val studentId: String, |
||||
val oldName: String, |
||||
val newName: String, |
||||
val reason: String |
||||
) |
||||
|
||||
class RenameViewModel(application: Application) : ScrollListW<RenameVo>(application) { |
||||
|
||||
val approverOrigin = |
||||
StringForm(formDesc = application.getString(R.string.approver_origin), textLength = 30) |
||||
|
||||
|
||||
override val initSize: Int = 10 |
||||
|
||||
init { |
||||
load() |
||||
} |
||||
|
||||
override fun load() { |
||||
viewModelScope.launch { |
||||
_data.value?.apply { |
||||
repeat(initSize) { |
||||
add( |
||||
RenameVo( |
||||
studentId = randomNum(8), |
||||
oldName = randomChinese(5), |
||||
newName = randomChinese(5), |
||||
reason = randomChinese(10) |
||||
) |
||||
) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun loadMore(callback: (message: String) -> Unit) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
} |
@ -0,0 +1,146 @@ |
||||
package com.gyf.csams.main.ui |
||||
|
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.annotation.StringRes |
||||
import androidx.compose.foundation.border |
||||
import androidx.compose.foundation.layout.* |
||||
import androidx.compose.foundation.lazy.LazyColumn |
||||
import androidx.compose.foundation.lazy.rememberLazyListState |
||||
import androidx.compose.material.MaterialTheme |
||||
import androidx.compose.material.Text |
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.runtime.getValue |
||||
import androidx.compose.runtime.livedata.observeAsState |
||||
import androidx.compose.ui.Alignment |
||||
import androidx.compose.ui.Modifier |
||||
import androidx.compose.ui.graphics.Color |
||||
import androidx.compose.ui.res.stringResource |
||||
import androidx.compose.ui.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.main.model.RenameViewModel |
||||
import com.gyf.csams.main.model.RenameVo |
||||
import com.gyf.lib.uikit.BaseTextField |
||||
import com.gyf.lib.uikit.BodyS |
||||
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 { |
||||
BodyS { |
||||
MainColumnFrame(background = { /*TODO*/ }) { |
||||
val listState = rememberLazyListState() |
||||
val model: RenameViewModel = viewModel() |
||||
val data by model.data.observeAsState() |
||||
Row( |
||||
horizontalArrangement = Arrangement.Center, |
||||
modifier = Modifier |
||||
.fillMaxWidth() |
||||
.padding(10.dp) |
||||
) { |
||||
Text( |
||||
text = stringResource(id = R.string.rename_form), |
||||
style = MaterialTheme.typography.h4 |
||||
) |
||||
} |
||||
LazyColumn(state = listState) { |
||||
data?.forEach { |
||||
item { |
||||
RenameForm(renameVo = it) |
||||
Spacer(modifier = Modifier.height(10.dp)) |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun RenameForm(modifier: Modifier = Modifier, renameVo: RenameVo) { |
||||
val model: RenameViewModel = viewModel() |
||||
val scaffoldModel: ScaffoldModel = viewModel() |
||||
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), |
||||
key = R.string.reason_for_application, |
||||
value = renameVo.reason |
||||
) |
||||
RowItem( |
||||
modifier = Modifier.height(baseHeight), key = R.string.approver, value = "" |
||||
/**TODO 获取审批人**/ |
||||
) |
||||
RowItem(modifier = Modifier.height(baseHeight * 3), key = R.string.approver_origin) { |
||||
BaseTextField(modifier = Modifier.fillMaxSize(), form = model.approverOrigin) |
||||
} |
||||
val message = stringResource(id = R.string.not_impl_error) |
||||
BottomButton(modifier = Modifier.fillMaxWidth()) { |
||||
scaffoldModel.update(message = message) |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun RowItem( |
||||
modifier: Modifier = Modifier, |
||||
@StringRes key: Int, |
||||
value: String? = null, |
||||
content: (@Composable () -> Unit)? = null |
||||
) { |
||||
Row( |
||||
modifier = modifier |
||||
.fillMaxWidth() |
||||
.border(width = 1.dp, color = Color.Black) |
||||
) { |
||||
Cell( |
||||
modifier = Modifier.weight(0.5F), |
||||
value = stringResource(id = key) |
||||
) |
||||
Cell(modifier = Modifier.weight(0.5F), value = value, content = content) |
||||
} |
||||
} |
||||
|
||||
@Composable |
||||
private fun Cell( |
||||
modifier: Modifier = Modifier, |
||||
value: String? = null, |
||||
content: (@Composable () -> Unit)? = null |
||||
) { |
||||
Box( |
||||
modifier = modifier |
||||
.fillMaxSize() |
||||
.border(width = 1.dp, color = MaterialTheme.colors.onBackground), |
||||
contentAlignment = Alignment.Center |
||||
) { |
||||
if (content != null) content() else Text( |
||||
text = value ?: throw IllegalArgumentException( |
||||
"参数错误" |
||||
) |
||||
) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue