From 047ebe4f2c4fa78c3ec09514f3c7f624e40f78cc Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Wed, 4 Oct 2023 01:29:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=8A=A0=E8=BD=BD=E5=AF=BC=E8=87=B4=E9=97=AA?= =?UTF-8?q?=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/api/models/MessageListBean.kt | 62 ++++++++++--------- .../list/NotificationsListViewModel.kt | 18 ++++-- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/models/MessageListBean.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/models/MessageListBean.kt index 0173cf97..7989ea01 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/models/MessageListBean.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/models/MessageListBean.kt @@ -21,60 +21,62 @@ class MessageListBean : BaseBean() { val page: PageInfoBean? = null val message: MessageBean? = null - fun getErrorCode() = Integer.valueOf(errorCode!!) + fun getErrorCode(): Int = Integer.valueOf(errorCode!!) - open class UserInfoBean { - val id: String? = null - val name: String? = null + data class UserInfoBean( + val id: String? = null, + val name: String? = null, @SerializedName("name_show") - val nameShow: String? = null + val nameShow: String? = null, @JsonAdapter(PortraitAdapter::class) - val portrait: String? = null + val portrait: String? = null, + ) - } - - class ReplyerInfoBean : UserInfoBean() { + data class ReplyerInfoBean( + val id: String? = null, + val name: String? = null, + @SerializedName("name_show") + val nameShow: String? = null, + @JsonAdapter(PortraitAdapter::class) + val portrait: String? = null, @SerializedName("is_friend") - val isFriend: String? = null - + val isFriend: String? = null, @SerializedName("is_fans") - val isFans: String? = null + val isFans: String? = null, + ) - } - - class MessageInfoBean { + data class MessageInfoBean( @SerializedName("is_floor") - val isFloor: String? = null - val title: String? = null - val content: String? = null + val isFloor: String? = null, + val title: String? = null, + val content: String? = null, @SerializedName("quote_content") - val quoteContent: String? = null - val replyer: ReplyerInfoBean? = null + val quoteContent: String? = null, + val replyer: ReplyerInfoBean? = null, @SerializedName("quote_user") - val quoteUser: UserInfoBean? = null + val quoteUser: UserInfoBean? = null, @SerializedName("thread_id") - val threadId: String? = null + val threadId: String? = null, @SerializedName("post_id") - val postId: String? = null - val time: String? = null + val postId: String? = null, + val time: String? = null, @SerializedName("fname") - val forumName: String? = null + val forumName: String? = null, @SerializedName("quote_pid") - val quotePid: String? = null + val quotePid: String? = null, @SerializedName("thread_type") - val threadType: String? = null - val unread: String? = null - - } + val threadType: String? = null, + val unread: String? = null, + ) class MessageBean { @SerializedName("replyme") diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt index b046bf88..a75585d8 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt @@ -146,12 +146,18 @@ sealed interface NotificationsListPartialChange : PartialChange oldState.copy(isLoadingMore = true) - is Success -> oldState.copy( - isLoadingMore = false, - currentPage = currentPage, - data = (oldState.data + data).toImmutableList(), - hasMore = hasMore - ) + is Success -> { + val uniqueData = data.filter { item -> + oldState.data.none { it.info == item.info } + } + oldState.copy( + isLoadingMore = false, + currentPage = currentPage, + data = (oldState.data + uniqueData).toImmutableList(), + hasMore = hasMore + ) + } + is Failure -> oldState.copy(isLoadingMore = false) }