You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
csamsclient/foreground/src/main/java/com/gyf/csams/message/model/SysMessageViewModel.kt

136 lines
3.5 KiB

package com.gyf.csams.message.model
import androidx.lifecycle.viewModelScope
import com.gyf.csams.NOT_IMPL_TIP
import com.gyf.csams.uikit.ScrollList
import com.gyf.csams.util.randomChinese
import com.gyf.csams.util.randomDateTime
import com.gyf.csams.util.randomNum
import kotlinx.coroutines.launch
import java.util.*
import kotlin.random.Random
enum class SystemType(val desc: String) {
Join("入团通知"),
ActCheck("活动审核通知"),
Rename("社团重命名审核通知")
}
/**
* 通知内容
*
*/
sealed class MessageContent {
//通知时间
abstract val createTime: Date
//通知状态
abstract val readState: Boolean
//通知类型
abstract val type: SystemType
}
/**
* 入团通知
* @param studentId 学号
* @param studentName 姓名
*
*/
data class JoinContent(
val studentId: Long,
val studentName: String,
override val createTime: Date,
override val readState: Boolean,
override val type: SystemType = SystemType.Join
) : MessageContent()
/**
* 活动审核通知
*
* @property activityId 活动id
* @property activityName 活动名
*
*/
data class ActCheckContent(
val activityId: Long, val activityName: String,
override val createTime: Date,
override val readState: Boolean,
override val type: SystemType = SystemType.ActCheck
) : MessageContent()
/**
* 社团重命名审核通知
*
* @property oldAssociationName 老社团名字
* @property newAssociationName 新社团名字
*
*/
data class RenameContent(
val oldAssociationName: String, val newAssociationName: String,
override val createTime: Date,
override val readState: Boolean,
override val type: SystemType = SystemType.Rename
) : MessageContent()
/**
* 系统通知数据状态管理
*
*/
class SysMessageViewModel : ScrollList<MessageContent>() {
val title = "系统通知"
override val initSize: Int = 10
init {
load()
}
/**
* TODO 加载通知
*
*/
override fun load() {
viewModelScope.launch {
_data.value?.apply {
repeat(initSize) {
when ((0..2).random()) {
0 -> add(
JoinContent(
createTime = randomDateTime(),
readState = Random.nextBoolean(),
studentId = randomNum().toLong(),
studentName = randomChinese(5)
)
)
1 -> add(
ActCheckContent(
activityId = randomNum().toLong(),
activityName = randomChinese(5),
createTime = randomDateTime(),
readState = Random.nextBoolean()
)
)
2 -> add(
RenameContent(
oldAssociationName = randomChinese(3),
newAssociationName = randomChinese(3),
createTime = randomDateTime(),
readState = Random.nextBoolean()
)
)
}
}
}
}
}
/**
* TODO 加载更多通知
*
* @param callback
*/
override fun loadMore(callback: (message: String) -> Unit) {
callback(NOT_IMPL_TIP)
}
}