From 531c02232832a0e76da5676b9c80049ad68a395c Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sun, 23 May 2021 00:18:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E5=9B=A2=E6=8D=A2=E5=90=8D=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E8=A1=A8=20=E7=A4=BE=E5=9B=A2=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background/src/main/AndroidManifest.xml | 21 +-- .../com/gyf/csams/main/model/MainViewModel.kt | 11 ++ .../com/gyf/csams/main/model/MenuViewModel.kt | 8 +- .../gyf/csams/main/model/RenameViewModel.kt | 59 +++++++ .../com/gyf/csams/main/ui/MainActivity.kt | 16 -- .../com/gyf/csams/main/ui/RenameActivity.kt | 146 ++++++++++++++++++ lib/src/main/java/com/gyf/lib/ScrollList.kt | 16 ++ lib/src/main/res/values-en/strings.xml | 8 + lib/src/main/res/values-zh/strings.xml | 8 + lib/src/main/res/values/strings.xml | 8 + 10 files changed, 269 insertions(+), 32 deletions(-) create mode 100644 background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt create mode 100644 background/src/main/java/com/gyf/csams/main/ui/RenameActivity.kt diff --git a/background/src/main/AndroidManifest.xml b/background/src/main/AndroidManifest.xml index e171ed9..7f78b8c 100644 --- a/background/src/main/AndroidManifest.xml +++ b/background/src/main/AndroidManifest.xml @@ -23,21 +23,12 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/main/model/MainViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/MainViewModel.kt index 26f2166..09f2ce6 100644 --- a/background/src/main/java/com/gyf/csams/main/model/MainViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/MainViewModel.kt @@ -6,6 +6,17 @@ import androidx.lifecycle.ViewModel import com.gyf.lib.uikit.PersonInfoVo import com.gyf.lib.util.randomChinese + +object LocalToken { + lateinit var token: String + lateinit var infoVo: PersonInfoVo + + fun register(token: String, infoVo: PersonInfoVo) { + this.token = token + this.infoVo = infoVo + } +} + /** * 部长 * diff --git a/background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt index 9e01c6a..39e1b3d 100644 --- a/background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt +++ b/background/src/main/java/com/gyf/csams/main/model/MenuViewModel.kt @@ -3,11 +3,17 @@ package com.gyf.csams.main.model import android.app.Activity import androidx.lifecycle.ViewModel import com.gyf.csams.main.ui.AssociationManagementActivity +import com.gyf.csams.main.ui.RenameActivity enum class MenuType(val desc: String, val clazz: Map>) { //老师 //总部长 - Association("社团管理", mapOf("社团信息管理" to AssociationManagementActivity::class.java)) + Association( + "社团管理", mapOf( + "社团信息管理" to AssociationManagementActivity::class.java, + "审核换名申请表" to RenameActivity::class.java + ) + ) } class MenuViewModel : ViewModel() { diff --git a/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt new file mode 100644 index 0000000..c19ce07 --- /dev/null +++ b/background/src/main/java/com/gyf/csams/main/model/RenameViewModel.kt @@ -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(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") + } +} \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/main/ui/MainActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/MainActivity.kt index bd1f3e5..41cb73a 100644 --- a/background/src/main/java/com/gyf/csams/main/ui/MainActivity.kt +++ b/background/src/main/java/com/gyf/csams/main/ui/MainActivity.kt @@ -10,19 +10,16 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.OutlinedButton 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.Modifier import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.gyf.csams.R import com.gyf.csams.main.model.MainViewModel import com.gyf.csams.main.model.MenuType import com.gyf.lib.uikit.* -import com.gyf.lib.uikit.theme.CSAMSTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -67,17 +64,4 @@ class MainActivity : ComponentActivity() { } } } -} - -@Composable -fun Greeting(name: String) { - Text(text = "Hello $name!") -} - -@Preview(showBackground = true) -@Composable -fun DefaultPreview() { - CSAMSTheme { - Greeting("Android") - } } \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/main/ui/RenameActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/RenameActivity.kt new file mode 100644 index 0000000..066c39f --- /dev/null +++ b/background/src/main/java/com/gyf/csams/main/ui/RenameActivity.kt @@ -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( + "参数错误" + ) + ) + } + } +} \ No newline at end of file diff --git a/lib/src/main/java/com/gyf/lib/ScrollList.kt b/lib/src/main/java/com/gyf/lib/ScrollList.kt index a4b6998..5cad943 100644 --- a/lib/src/main/java/com/gyf/lib/ScrollList.kt +++ b/lib/src/main/java/com/gyf/lib/ScrollList.kt @@ -1,9 +1,12 @@ package com.gyf.lib +import android.app.Application +import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +@Deprecated(message = "", replaceWith = ReplaceWith("")) abstract class ScrollList : ViewModel() { protected val _data = MutableLiveData>(mutableListOf()) val data: LiveData> = _data @@ -13,6 +16,19 @@ abstract class ScrollList : ViewModel() { //加载列表 abstract fun load() + //加载更多数据 + abstract fun loadMore(callback: (message: String) -> Unit) +} + +abstract class ScrollListW(application: Application) : AndroidViewModel(application) { + protected val _data = MutableLiveData>(mutableListOf()) + val data: LiveData> = _data + + abstract val initSize: Int + + //加载列表 + abstract fun load() + //加载更多数据 abstract fun loadMore(callback: (message: String) -> Unit) } \ No newline at end of file diff --git a/lib/src/main/res/values-en/strings.xml b/lib/src/main/res/values-en/strings.xml index 5387c0c..5e676ac 100644 --- a/lib/src/main/res/values-en/strings.xml +++ b/lib/src/main/res/values-en/strings.xml @@ -12,4 +12,12 @@ 活动介绍 检索 未找到结果 + 社团换名申请表 + 申请人 + 社团原名 + 社团新名 + 申请理由 + 审批人 + 审核理由 + 抱歉此功能尚未开放 \ No newline at end of file diff --git a/lib/src/main/res/values-zh/strings.xml b/lib/src/main/res/values-zh/strings.xml index 5387c0c..5e676ac 100644 --- a/lib/src/main/res/values-zh/strings.xml +++ b/lib/src/main/res/values-zh/strings.xml @@ -12,4 +12,12 @@ 活动介绍 检索 未找到结果 + 社团换名申请表 + 申请人 + 社团原名 + 社团新名 + 申请理由 + 审批人 + 审核理由 + 抱歉此功能尚未开放 \ No newline at end of file diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml index 5387c0c..5e676ac 100644 --- a/lib/src/main/res/values/strings.xml +++ b/lib/src/main/res/values/strings.xml @@ -12,4 +12,12 @@ 活动介绍 检索 未找到结果 + 社团换名申请表 + 申请人 + 社团原名 + 社团新名 + 申请理由 + 审批人 + 审核理由 + 抱歉此功能尚未开放 \ No newline at end of file