- 允许用户回复评论和子评论 - 点击回复按钮,弹出评论框,并显示回复的用户 - 评论 列表中显示回复的用户和内容 - 点击回复内容中的用户名,跳转到用户主页 - 优化评论列表加载逻辑,支持加载更多子评论
65 lines
2.0 KiB
Kotlin
65 lines
2.0 KiB
Kotlin
package com.aiosman.riderpro.entity
|
|
|
|
import androidx.paging.PagingSource
|
|
import androidx.paging.PagingState
|
|
import com.aiosman.riderpro.data.CommentRemoteDataSource
|
|
import com.aiosman.riderpro.data.NoticePost
|
|
import java.io.IOException
|
|
import java.util.Date
|
|
|
|
data class CommentEntity(
|
|
val id: Int,
|
|
val name: String,
|
|
val comment: String,
|
|
val date: Date,
|
|
val likes: Int,
|
|
val replies: List<CommentEntity>,
|
|
val postId: Int = 0,
|
|
val avatar: String,
|
|
val author: Long,
|
|
var liked: Boolean,
|
|
var unread: Boolean = false,
|
|
var post: NoticePost?,
|
|
var reply: List<CommentEntity>,
|
|
var replyUserId: Long?,
|
|
var replyUserNickname: String?,
|
|
var replyUserAvatar: String?,
|
|
var parentCommentId: Int?,
|
|
var replyCount: Int,
|
|
var replyPage: Int = 1
|
|
)
|
|
|
|
class CommentPagingSource(
|
|
private val remoteDataSource: CommentRemoteDataSource,
|
|
private val postId: Int? = null,
|
|
private val postUser: Int? = null,
|
|
private val selfNotice: Boolean? = null,
|
|
private val order: String? = null,
|
|
private val parentCommentId: Int? = null
|
|
) : PagingSource<Int, CommentEntity>() {
|
|
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, CommentEntity> {
|
|
return try {
|
|
val currentPage = params.key ?: 1
|
|
val comments = remoteDataSource.getComments(
|
|
pageNumber = currentPage,
|
|
postId = postId,
|
|
postUser = postUser,
|
|
selfNotice = selfNotice,
|
|
order = order,
|
|
parentCommentId = parentCommentId
|
|
)
|
|
LoadResult.Page(
|
|
data = comments.list,
|
|
prevKey = if (currentPage == 1) null else currentPage - 1,
|
|
nextKey = if (comments.list.isEmpty()) null else comments.page + 1
|
|
)
|
|
} catch (exception: IOException) {
|
|
return LoadResult.Error(exception)
|
|
}
|
|
}
|
|
|
|
override fun getRefreshKey(state: PagingState<Int, CommentEntity>): Int? {
|
|
return state.anchorPosition
|
|
}
|
|
|
|
} |