- 新增全新设计的AI智能体主页界面(`AiProfileV3`),包括个人信息卡片、操作按钮和动态列表。 - 添加相应的 `AiProfileViewModel` 来处理数据加载、关注/取关以及动态列表分页逻辑。 - 创建 `AiProfileWrap` 作为页面入口,并根据 `isAiAccount` 参数在导航中分发至新的AI主页。 - 在 `AccountProfileEntity` 和 `Account` 数据模型中增加了AI角色背景图字段(`aiRoleAvatar`, `aiRoleAvatarMedium`, `aiRoleAvatarLarge`)。
210 lines
5.4 KiB
Kotlin
210 lines
5.4 KiB
Kotlin
package com.aiosman.ravenow.entity
|
|
|
|
import androidx.paging.PagingSource
|
|
import androidx.paging.PagingState
|
|
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
|
|
import java.io.IOException
|
|
import java.util.Date
|
|
|
|
/**
|
|
* 用户点赞
|
|
*/
|
|
data class AccountLikeEntity(
|
|
// 动态
|
|
val post: NoticePostEntity?,
|
|
// 回复评论
|
|
val comment: NoticeCommentEntity?,
|
|
// 点赞用户
|
|
val user: NoticeUserEntity,
|
|
// 点赞时间
|
|
val likeTime: Date,
|
|
// 动态ID
|
|
val postId: Int
|
|
)
|
|
|
|
/**
|
|
* 用户收藏
|
|
*/
|
|
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?,
|
|
// trtcUserId
|
|
val trtcUserId: String,
|
|
val chatToken: String?,
|
|
|
|
val aiAccount: Boolean,
|
|
val rawAvatar: String,
|
|
|
|
val chatAIId: String,
|
|
|
|
// AI角色背景图
|
|
val aiRoleAvatar: String? = null,
|
|
val aiRoleAvatarMedium: String? = null,
|
|
val aiRoleAvatarLarge: String? = null,
|
|
)
|
|
|
|
/**
|
|
* 消息关联的动态
|
|
*/
|
|
data class NoticePostEntity(
|
|
// 动态ID
|
|
val id: Int,
|
|
// 动态内容
|
|
val textContent: String,
|
|
// 动态图片
|
|
val images: List<Image>,
|
|
// 时间
|
|
val time: Date,
|
|
)
|
|
|
|
data class NoticeCommentEntity(
|
|
// 评论ID
|
|
val id: Int,
|
|
// 评论内容
|
|
val content: String,
|
|
// 评论时间
|
|
val time: Date,
|
|
// 引用评论
|
|
val replyComment: NoticeCommentEntity?,
|
|
// 动态
|
|
val postId: Int,
|
|
// 动态
|
|
val post : NoticePostEntity?,
|
|
)
|
|
|
|
/**
|
|
* 消息关联的用户
|
|
*/
|
|
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
|
|
}
|
|
} |