parent
f531b72442
commit
42dbaef67a
@ -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 |
||||
|
||||
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 |
||||
) |
||||
} |
||||
} |
Loading…
Reference in new issue