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.
131 lines
3.2 KiB
131 lines
3.2 KiB
package com.gyf.lib.model
|
|
|
|
import android.app.Application
|
|
import androidx.lifecycle.LiveData
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.viewModelScope
|
|
import com.google.gson.reflect.TypeToken
|
|
import com.gyf.csams.module.ApiResponse
|
|
import com.gyf.csams.module.ClientType
|
|
import com.gyf.csams.module.NotificationDto
|
|
import com.gyf.csams.module.NotificationVo
|
|
import com.gyf.lib.util.*
|
|
import com.orhanobut.logger.Logger
|
|
import kotlinx.coroutines.launch
|
|
import java.util.*
|
|
|
|
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()
|
|
|
|
/**
|
|
* 系统通知数据状态管理
|
|
*
|
|
*/
|
|
abstract class SysMessageViewModel(application: Application) :
|
|
ScrollViewModel<NotificationVo>(application) {
|
|
val title = "系统通知"
|
|
|
|
override val initSize: Int = 10
|
|
|
|
private val _currentPage = MutableLiveData<Long>()
|
|
val currentPage: LiveData<Long> = _currentPage
|
|
|
|
abstract fun clientType(): ClientType
|
|
|
|
init {
|
|
load()
|
|
}
|
|
|
|
|
|
/**
|
|
*加载通知列表
|
|
*
|
|
*/
|
|
fun load() {
|
|
viewModelScope.launch {
|
|
HttpClient.post(
|
|
Api.buildUrl(NotificationApi.List),
|
|
HttpCallback<MutableList<NotificationVo>>(
|
|
action = "获取通知列表",
|
|
onSuccess = {
|
|
it.body?.let {
|
|
_data.postValue(it)
|
|
}
|
|
Logger.i(it.message)
|
|
},
|
|
onFail = {
|
|
Logger.e(it)
|
|
},
|
|
typeToken = object :
|
|
TypeToken<ApiResponse<MutableList<NotificationVo>>>() {}.type
|
|
),
|
|
jsonParam = NotificationDto(
|
|
receiverId = TokenManager.getToken().id,
|
|
receiverClient = clientType(),
|
|
token = TokenManager.getToken()
|
|
)
|
|
)
|
|
}
|
|
}
|
|
} |