Files
rider-pro-android-app/app/src/main/java/com/aiosman/ravenow/entity/Account.kt

210 lines
5.4 KiB
Kotlin
Raw Normal View History

2024-11-17 20:07:42 +08:00
package com.aiosman.ravenow.entity
2024-08-24 23:11:20 +08:00
import androidx.paging.PagingSource
import androidx.paging.PagingState
2024-11-17 20:07:42 +08:00
import com.aiosman.ravenow.data.AccountFollow
import com.aiosman.ravenow.data.AccountService
import com.aiosman.ravenow.data.Image
import com.aiosman.ravenow.data.api.ApiClient
2024-08-24 23:11:20 +08:00
import java.io.IOException
import java.util.Date
/**
* 用户点赞
*/
data class AccountLikeEntity(
// 动态
2024-09-11 22:21:10 +08:00
val post: NoticePostEntity?,
// 回复评论
val comment: NoticeCommentEntity?,
2024-08-24 23:11:20 +08:00
// 点赞用户
val user: NoticeUserEntity,
// 点赞时间
val likeTime: Date,
2024-09-11 22:21:10 +08:00
// 动态ID
val postId: Int
2024-08-24 23:11:20 +08:00
)
/**
* 用户收藏
*/
data class AccountFavouriteEntity(
// 动态
val post: NoticePostEntity,
// 收藏用户
val user: NoticeUserEntity,
// 收藏时间
val favoriteTime: Date,
)
/**
* 用户信息
*/
data class AccountProfileEntity(
// 用户ID
val id: Int,
// 粉丝数
val followerCount: Int,
// 关注数
val followingCount: Int,
// 昵称
val nickName: String,
// 头像
val avatar: String,
// 个人简介
val bio: String,
// 国家
val country: String,
// 是否关注,针对当前登录用户
val isFollowing: Boolean,
// 主页背景图
val banner: String?,
2024-09-23 23:47:16 +08:00
// trtcUserId
val trtcUserId: String,
2025-09-08 16:02:46 +08:00
val chatToken: String?,
2025-08-07 19:03:05 +08:00
val aiAccount: Boolean,
val rawAvatar: String,
val chatAIId: String,
// AI角色背景图
val aiRoleAvatar: String? = null,
val aiRoleAvatarMedium: String? = null,
val aiRoleAvatarLarge: String? = null,
2024-08-24 23:11:20 +08:00
)
/**
* 消息关联的动态
*/
data class NoticePostEntity(
// 动态ID
val id: Int,
// 动态内容
val textContent: String,
// 动态图片
val images: List<Image>,
// 时间
val time: Date,
)
2024-09-11 22:21:10 +08:00
data class NoticeCommentEntity(
// 评论ID
val id: Int,
// 评论内容
val content: String,
// 评论时间
val time: Date,
// 引用评论
val replyComment: NoticeCommentEntity?,
// 动态
val postId: Int,
// 动态
val post : NoticePostEntity?,
2024-09-11 22:21:10 +08:00
)
2024-08-24 23:11:20 +08:00
/**
* 消息关联的用户
*/
data class NoticeUserEntity(
// 用户ID
val id: Int,
// 昵称
val nickName: String,
// 头像
val avatar: String,
)
/**
* 用户点赞消息分页数据加载器
*/
class LikeItemPagingSource(
private val accountService: AccountService,
) : PagingSource<Int, AccountLikeEntity>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AccountLikeEntity> {
return try {
val currentPage = params.key ?: 1
val likes = accountService.getMyLikeNotice(
page = currentPage,
pageSize = 20,
)
LoadResult.Page(
data = likes.list.map {
it.toAccountLikeEntity()
},
prevKey = if (currentPage == 1) null else currentPage - 1,
nextKey = if (likes.list.isEmpty()) null else likes.page + 1
)
} catch (exception: IOException) {
return LoadResult.Error(exception)
}
}
override fun getRefreshKey(state: PagingState<Int, AccountLikeEntity>): Int? {
return state.anchorPosition
}
}
/**
* 用户收藏消息分页数据加载器
*/
class FavoriteItemPagingSource(
private val accountService: AccountService,
) : PagingSource<Int, AccountFavouriteEntity>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AccountFavouriteEntity> {
return try {
val currentPage = params.key ?: 1
val favouriteListContainer = accountService.getMyFavouriteNotice(
page = currentPage,
pageSize = 20,
)
LoadResult.Page(
data = favouriteListContainer.list.map {
it.toAccountFavouriteEntity()
},
prevKey = if (currentPage == 1) null else currentPage - 1,
nextKey = if (favouriteListContainer.list.isEmpty()) null else favouriteListContainer.page + 1
)
} catch (exception: IOException) {
return LoadResult.Error(exception)
}
}
override fun getRefreshKey(state: PagingState<Int, AccountFavouriteEntity>): Int? {
return state.anchorPosition
}
}
/**
* 用户关注消息分页数据加载器
*/
class FollowItemPagingSource(
private val accountService: AccountService,
) : PagingSource<Int, AccountFollow>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AccountFollow> {
return try {
val currentPage = params.key ?: 1
val followListContainer = accountService.getMyFollowNotice(
page = currentPage,
pageSize = 20,
)
LoadResult.Page(
data = followListContainer.list.map {
it.copy(
avatar = "${ApiClient.BASE_SERVER}${it.avatar}",
)
},
prevKey = if (currentPage == 1) null else currentPage - 1,
nextKey = if (followListContainer.list.isEmpty()) null else followListContainer.page + 1
)
} catch (exception: IOException) {
return LoadResult.Error(exception)
}
}
override fun getRefreshKey(state: PagingState<Int, AccountFollow>): Int? {
return state.anchorPosition
}
}