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.
141 lines
3.6 KiB
141 lines
3.6 KiB
package com.gyf.csams.message.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.util.SimpleCallback
|
|
import com.gyf.lib.model.ScrollViewModel
|
|
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("社团重命名审核通知")
|
|
|
|
}
|
|
|
|
data class NotificationVo(val title: String, val content: String, val id: Int, val createTime: Long)
|
|
|
|
/**
|
|
* 通知内容
|
|
*
|
|
*/
|
|
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(application: Application) : ScrollViewModel<NotificationVo>(application) {
|
|
val title = "系统通知"
|
|
|
|
override val initSize: Int = 10
|
|
|
|
private val _currentPage = MutableLiveData<Long>()
|
|
val currentPage: LiveData<Long> = _currentPage
|
|
|
|
init {
|
|
load()
|
|
}
|
|
|
|
/**
|
|
*加载通知列表
|
|
*
|
|
*/
|
|
override fun load() {
|
|
viewModelScope.launch {
|
|
TokenManager.token?.let { it ->
|
|
HttpClient.post(
|
|
Api.buildUrl(NotificationApi.List),
|
|
SimpleCallback<MutableList<NotificationVo>>(
|
|
action = "获取通知列表",
|
|
onSuccess = {
|
|
it.body?.let {
|
|
_data.postValue(it)
|
|
}
|
|
Logger.i(it.message)
|
|
},
|
|
onFail = {
|
|
Logger.e(it)
|
|
},
|
|
type = object :
|
|
TypeToken<ApiResponse<MutableList<NotificationVo>>>() {}.type
|
|
),
|
|
jsonParam = NotificationDto(
|
|
receiverId = it.id,
|
|
receiverClient = ClientType.Foreground,
|
|
token = it, page = PageDto(
|
|
currentPage = _currentPage.value ?: 1,
|
|
pageSize = initSize
|
|
)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*TODO
|
|
*
|
|
* @param callback
|
|
*/
|
|
override fun loadMore(callback: (message: String) -> Unit) {
|
|
callback(NOT_IMPL_TIP)
|
|
}
|
|
} |