From 42dbaef67a50d86777ef26ad631d81771211cf81 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Mon, 24 May 2021 06:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E7=A4=BE=E5=9B=A2=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csams/main/model/ManagerActViewModel.kt | 50 +++++++++++++ .../gyf/csams/main/ui/ManagerActActivity.kt | 72 +++++++++++++++++++ .../main/java/com/gyf/csams/uikit/Table.kt | 25 ++++--- background/src/main/res/values-en/strings.xml | 5 +- background/src/main/res/values-zh/strings.xml | 5 +- background/src/main/res/values/strings.xml | 5 +- 6 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt diff --git a/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt b/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt new file mode 100644 index 0000000..03d58a6 --- /dev/null +++ b/background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt @@ -0,0 +1,50 @@ +package com.gyf.csams.main.model + +import android.app.Application +import androidx.annotation.IntRange +import com.gyf.lib.ScrollListW +import com.gyf.lib.util.randomChinese +import com.gyf.lib.util.randomDateTime +import com.gyf.lib.util.randomNum +import java.util.* + +data class ActivityVo( + val activityId: Long, val activityName: String, val association: String, + @IntRange(from = 1, to = MAX_SCORE) val score: Int, val activityTime: Date, val location: String +) + +/** + * 活动信息数据管理 + * + * @constructor + * + * @param application + */ +class ManagerActViewModel(application: Application) : ScrollListW(application) { + override val initSize: Int = 10 + + init { + load() + } + + override fun load() { + _data.value?.apply { + repeat(initSize) { + add( + ActivityVo( + activityId = randomNum(8).toLong(), + activityName = randomChinese(5), + association = randomChinese(5), + score = (1..5).random(), + activityTime = randomDateTime(), + location = 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/ManagerActActivity.kt b/background/src/main/java/com/gyf/csams/main/ui/ManagerActActivity.kt index ef7969b..66017c9 100644 --- a/background/src/main/java/com/gyf/csams/main/ui/ManagerActActivity.kt +++ b/background/src/main/java/com/gyf/csams/main/ui/ManagerActActivity.kt @@ -1,6 +1,78 @@ package com.gyf.csams.main.ui +import android.os.Bundle import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +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.painterResource +import androidx.compose.ui.unit.dp +import com.gyf.csams.R +import com.gyf.csams.main.model.ActivityVo +import com.gyf.csams.main.model.MAX_SCORE +import com.gyf.csams.main.model.ManagerActViewModel +import com.gyf.csams.uikit.RowItem +import com.gyf.csams.uikit.TestTable +import com.gyf.lib.util.format +/** + * 查看活动信息 + * + */ class ManagerActActivity : ComponentActivity() { + @ExperimentalComposeApi + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + TestTable(clazz = ManagerActViewModel::class.java) { + ActivityTable(vo = it) + } + } + } + + @Composable + private fun ActivityTable(vo: ActivityVo) { + val baseHeight = 50.dp + RowItem( + modifier = Modifier.height(baseHeight), + key = R.string.activity_id, value = "${vo.activityId}" + ) + RowItem( + modifier = Modifier.height(baseHeight), + key = R.string.activity_name, value = vo.activityName + ) + RowItem( + modifier = Modifier.height(baseHeight), + key = R.string.activity_association, value = vo.association + ) + RowItem(modifier = Modifier.height(baseHeight), key = R.string.activity_evaluate) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center + ) { + repeat(MAX_SCORE.toInt()) { + Image( + modifier = Modifier.weight(1F / MAX_SCORE), + painter = painterResource(id = if (it < vo.score) R.drawable.ic_collection_fill else R.drawable.ic_collection), + contentDescription = null + ) + } + } + } + RowItem( + modifier = Modifier.height(baseHeight), + key = R.string.activity_time, value = vo.activityTime.format() + ) + RowItem( + modifier = Modifier.height(baseHeight * 2), + key = R.string.activity_location, value = vo.location + ) + } } \ No newline at end of file diff --git a/background/src/main/java/com/gyf/csams/uikit/Table.kt b/background/src/main/java/com/gyf/csams/uikit/Table.kt index a469742..bd9b7f8 100644 --- a/background/src/main/java/com/gyf/csams/uikit/Table.kt +++ b/background/src/main/java/com/gyf/csams/uikit/Table.kt @@ -30,7 +30,7 @@ import com.gyf.lib.uikit.MainColumnFrame @Composable fun TestTable( clazz: Class>, - @StringRes title: Int, + @StringRes title: Int? = null, callback: @Composable (vo: A) -> Unit ) { BodyS { @@ -38,17 +38,20 @@ fun TestTable( val listState = rememberLazyListState() val model = viewModel(modelClass = clazz) val data by model.data.observeAsState() - Row( - horizontalArrangement = Arrangement.Center, - modifier = Modifier - .fillMaxWidth() - .padding(10.dp) - ) { - Text( - text = stringResource(id = title), - style = MaterialTheme.typography.h4 - ) + title?.let { + Row( + horizontalArrangement = Arrangement.Center, + modifier = Modifier + .fillMaxWidth() + .padding(10.dp) + ) { + Text( + text = stringResource(id = title), + style = MaterialTheme.typography.h4 + ) + } } + LazyColumn(state = listState) { data?.forEach { item { diff --git a/background/src/main/res/values-en/strings.xml b/background/src/main/res/values-en/strings.xml index d6db783..1eed946 100644 --- a/background/src/main/res/values-en/strings.xml +++ b/background/src/main/res/values-en/strings.xml @@ -22,5 +22,8 @@ 驳回 优点 缺点 - 评价 + 活动评价 + 活动编号 + 活动社团 + 活动地点 \ No newline at end of file diff --git a/background/src/main/res/values-zh/strings.xml b/background/src/main/res/values-zh/strings.xml index d6db783..1eed946 100644 --- a/background/src/main/res/values-zh/strings.xml +++ b/background/src/main/res/values-zh/strings.xml @@ -22,5 +22,8 @@ 驳回 优点 缺点 - 评价 + 活动评价 + 活动编号 + 活动社团 + 活动地点 \ No newline at end of file diff --git a/background/src/main/res/values/strings.xml b/background/src/main/res/values/strings.xml index d6db783..1eed946 100644 --- a/background/src/main/res/values/strings.xml +++ b/background/src/main/res/values/strings.xml @@ -22,5 +22,8 @@ 驳回 优点 缺点 - 评价 + 活动评价 + 活动编号 + 活动社团 + 活动地点 \ No newline at end of file