fix: 修复消息为空时提示网络问题

This commit is contained in:
HuanChengFly 2020-10-05 20:12:57 +08:00
parent 9b7435a779
commit 5d5331e8b5
3 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,18 @@
package com.huanchengfly.tieba.post.api.adapters
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.huanchengfly.tieba.post.api.models.MessageListBean.MessageInfoBean
import java.lang.reflect.Type
import java.util.*
class MessageListAdapter : JsonDeserializer<List<MessageInfoBean>> {
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): List<MessageInfoBean> {
return if (json.isJsonPrimitive) {
ArrayList()
} else context.deserialize(json, typeOfT)
}
}

View File

@ -34,13 +34,28 @@ class ForumPageBean : ErrorBean() {
class ZyqDefineBean : BaseBean() { class ZyqDefineBean : BaseBean() {
var name: String? = null var name: String? = null
var link: String? = null var link: String? = null
} }
class ManagerBean : BaseBean() { class ManagerBean : BaseBean() {
val id: String? = null val id: String? = null
val name: String? = null val name: String? = null
}
data class ThemeColors(
var day: ThemeColor,
var dark: ThemeColor,
var night: ThemeColor
) {
data class ThemeColor(
@SerializedName("common_color")
var commonColor: String,
@SerializedName("dark_color")
var darkColor: String,
@SerializedName("font_color")
var fontColor: String,
@SerializedName("light_color")
var lightColor: String,
)
} }
class ForumBean : BaseBean() { class ForumBean : BaseBean() {
@ -71,6 +86,12 @@ class ForumPageBean : ErrorBean() {
@SerializedName("member_num") @SerializedName("member_num")
var memberNum: String? = null var memberNum: String? = null
@SerializedName("thread_num")
var threadNum: String? = null
@SerializedName("theme_color")
lateinit var themeColor: ThemeColors
@SerializedName("post_num") @SerializedName("post_num")
var postNum: String? = null var postNum: String? = null
var managers: List<ManagerBean>? = null var managers: List<ManagerBean>? = null

View File

@ -2,6 +2,7 @@ package com.huanchengfly.tieba.post.api.models
import com.google.gson.annotations.JsonAdapter import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import com.huanchengfly.tieba.post.api.adapters.MessageListAdapter
import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter
import com.huanchengfly.tieba.post.models.BaseBean import com.huanchengfly.tieba.post.models.BaseBean
@ -10,9 +11,11 @@ class MessageListBean : BaseBean() {
val errorCode: String? = null val errorCode: String? = null
val time: Long = 0 val time: Long = 0
@JsonAdapter(MessageListAdapter::class)
@SerializedName("reply_list") @SerializedName("reply_list")
val replyList: List<MessageInfoBean>? = null val replyList: List<MessageInfoBean>? = null
@JsonAdapter(MessageListAdapter::class)
@SerializedName("at_list") @SerializedName("at_list")
val atList: List<MessageInfoBean>? = null val atList: List<MessageInfoBean>? = null
val page: PageInfoBean? = null val page: PageInfoBean? = null