查看社团活动

master
pan 4 years ago
parent f531b72442
commit 42dbaef67a
  1. 50
      background/src/main/java/com/gyf/csams/main/model/ManagerActViewModel.kt
  2. 72
      background/src/main/java/com/gyf/csams/main/ui/ManagerActActivity.kt
  3. 5
      background/src/main/java/com/gyf/csams/uikit/Table.kt
  4. 5
      background/src/main/res/values-en/strings.xml
  5. 5
      background/src/main/res/values-zh/strings.xml
  6. 5
      background/src/main/res/values/strings.xml

@ -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<ActivityVo>(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")
}
}

@ -1,6 +1,78 @@
package com.gyf.csams.main.ui package com.gyf.csams.main.ui
import android.os.Bundle
import androidx.activity.ComponentActivity 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() { 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
)
}
} }

@ -30,7 +30,7 @@ import com.gyf.lib.uikit.MainColumnFrame
@Composable @Composable
fun <A> TestTable( fun <A> TestTable(
clazz: Class<out ScrollListW<A>>, clazz: Class<out ScrollListW<A>>,
@StringRes title: Int, @StringRes title: Int? = null,
callback: @Composable (vo: A) -> Unit callback: @Composable (vo: A) -> Unit
) { ) {
BodyS { BodyS {
@ -38,6 +38,7 @@ fun <A> TestTable(
val listState = rememberLazyListState() val listState = rememberLazyListState()
val model = viewModel(modelClass = clazz) val model = viewModel(modelClass = clazz)
val data by model.data.observeAsState() val data by model.data.observeAsState()
title?.let {
Row( Row(
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,
modifier = Modifier modifier = Modifier
@ -49,6 +50,8 @@ fun <A> TestTable(
style = MaterialTheme.typography.h4 style = MaterialTheme.typography.h4
) )
} }
}
LazyColumn(state = listState) { LazyColumn(state = listState) {
data?.forEach { data?.forEach {
item { item {

@ -22,5 +22,8 @@
<string name="reject_btn">驳回</string> <string name="reject_btn">驳回</string>
<string name="activity_merit">优点</string> <string name="activity_merit">优点</string>
<string name="activitiy_defect">缺点</string> <string name="activitiy_defect">缺点</string>
<string name="activity_evaluate">评价</string> <string name="activity_evaluate">活动评价</string>
<string name="activity_id">活动编号</string>
<string name="activity_association">活动社团</string>
<string name="activity_location">活动地点</string>
</resources> </resources>

@ -22,5 +22,8 @@
<string name="reject_btn">驳回</string> <string name="reject_btn">驳回</string>
<string name="activity_merit">优点</string> <string name="activity_merit">优点</string>
<string name="activitiy_defect">缺点</string> <string name="activitiy_defect">缺点</string>
<string name="activity_evaluate">评价</string> <string name="activity_evaluate">活动评价</string>
<string name="activity_id">活动编号</string>
<string name="activity_association">活动社团</string>
<string name="activity_location">活动地点</string>
</resources> </resources>

@ -22,5 +22,8 @@
<string name="reject_btn">驳回</string> <string name="reject_btn">驳回</string>
<string name="activity_merit">优点</string> <string name="activity_merit">优点</string>
<string name="activitiy_defect">缺点</string> <string name="activitiy_defect">缺点</string>
<string name="activity_evaluate">评价</string> <string name="activity_evaluate">活动评价</string>
<string name="activity_id">活动编号</string>
<string name="activity_association">活动社团</string>
<string name="activity_location">活动地点</string>
</resources> </resources>
Loading…
Cancel
Save