feat: 实现探索动态功能
在动态列表中新增探索动态功能,允许用户浏览和发现新的动态内容。 具体修改包括: - 在API接口中添加`explore`参数,用于请求探索动态数据。 - 修改MomentService,添加`explore`参数,用于获取探索动态数据。 - 更新MomentViewModel,使用`explore`参数请求探索动态数据。 - 修改MomentPagingSource,使用`explore`参数请求探索动态数据。 - 修改MomentCard,使用`explore`参数显示探索动态数据。
This commit is contained in:
@@ -121,6 +121,7 @@ interface MomentService {
|
||||
* @param timelineId 用户时间线ID,指定用户 ID 的时间线
|
||||
* @param contentSearch 内容搜索,过滤条件
|
||||
* @param trend 是否趋势动态
|
||||
* @param explore 是否探索动态
|
||||
* @return 动态列表
|
||||
*/
|
||||
suspend fun getMoments(
|
||||
@@ -129,6 +130,7 @@ interface MomentService {
|
||||
timelineId: Int? = null,
|
||||
contentSearch: String? = null,
|
||||
trend: Boolean? = false,
|
||||
explore: Boolean? = false,
|
||||
favoriteUserId: Int? = null
|
||||
): ListContainer<MomentEntity>
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ interface RiderProAPI {
|
||||
@Query("postUser") postUser: Int? = null,
|
||||
@Query("trend") trend: String? = null,
|
||||
@Query("favouriteUserId") favouriteUserId: Int? = null,
|
||||
@Query("explore") explore: String? = null,
|
||||
): Response<ListContainer<Moment>>
|
||||
|
||||
@Multipart
|
||||
|
||||
@@ -27,6 +27,7 @@ class MomentPagingSource(
|
||||
private val timelineId: Int? = null,
|
||||
private val contentSearch: String? = null,
|
||||
private val trend: Boolean? = false,
|
||||
private val explore: Boolean? = false,
|
||||
private val favoriteUserId: Int? = null
|
||||
) : PagingSource<Int, MomentEntity>() {
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MomentEntity> {
|
||||
@@ -38,6 +39,7 @@ class MomentPagingSource(
|
||||
timelineId = timelineId,
|
||||
contentSearch = contentSearch,
|
||||
trend = trend,
|
||||
explore = explore,
|
||||
favoriteUserId = favoriteUserId
|
||||
)
|
||||
|
||||
@@ -66,6 +68,7 @@ class MomentRemoteDataSource(
|
||||
timelineId: Int?,
|
||||
contentSearch: String?,
|
||||
trend: Boolean?,
|
||||
explore: Boolean?,
|
||||
favoriteUserId: Int?
|
||||
): ListContainer<MomentEntity> {
|
||||
return momentService.getMoments(
|
||||
@@ -74,6 +77,7 @@ class MomentRemoteDataSource(
|
||||
timelineId = timelineId,
|
||||
contentSearch = contentSearch,
|
||||
trend = trend,
|
||||
explore = explore,
|
||||
favoriteUserId = favoriteUserId
|
||||
)
|
||||
}
|
||||
@@ -88,7 +92,8 @@ class MomentServiceImpl() : MomentService {
|
||||
timelineId: Int?,
|
||||
contentSearch: String?,
|
||||
trend: Boolean?,
|
||||
favoriteUserId: Int?
|
||||
explore: Boolean?,
|
||||
favoriteUserId: Int?,
|
||||
): ListContainer<MomentEntity> {
|
||||
return momentBackend.fetchMomentItems(
|
||||
pageNumber = pageNumber,
|
||||
@@ -96,7 +101,8 @@ class MomentServiceImpl() : MomentService {
|
||||
timelineId = timelineId,
|
||||
contentSearch = contentSearch,
|
||||
trend = trend,
|
||||
favoriteUserId = favoriteUserId
|
||||
favoriteUserId = favoriteUserId,
|
||||
explore = explore
|
||||
)
|
||||
}
|
||||
|
||||
@@ -144,6 +150,7 @@ class MomentBackend {
|
||||
timelineId: Int?,
|
||||
contentSearch: String?,
|
||||
trend: Boolean?,
|
||||
explore: Boolean?,
|
||||
favoriteUserId: Int? = null
|
||||
): ListContainer<MomentEntity> {
|
||||
val resp = ApiClient.api.getPosts(
|
||||
@@ -153,7 +160,8 @@ class MomentBackend {
|
||||
authorId = author,
|
||||
contentSearch = contentSearch,
|
||||
trend = if (trend == true) "true" else "",
|
||||
favouriteUserId = favoriteUserId
|
||||
favouriteUserId = favoriteUserId,
|
||||
explore = if (explore == true) "true" else ""
|
||||
)
|
||||
val body = resp.body() ?: throw ServiceException("Failed to get moments")
|
||||
return ListContainer(
|
||||
|
||||
@@ -46,7 +46,7 @@ fun ExploreMomentsList() {
|
||||
) {
|
||||
items(
|
||||
moments.itemCount,
|
||||
key = { idx -> moments[idx]?.id ?: idx }
|
||||
key = { idx -> idx }
|
||||
) { idx ->
|
||||
val momentItem = moments[idx] ?: return@items
|
||||
MomentCard(momentEntity = momentItem,
|
||||
|
||||
@@ -53,7 +53,7 @@ object MomentExploreViewModel : ViewModel() {
|
||||
MomentPagingSource(
|
||||
MomentRemoteDataSource(momentService),
|
||||
// 如果没有动态,则显示热门动态
|
||||
trend = true
|
||||
explore = true
|
||||
)
|
||||
}
|
||||
).flow.cachedIn(viewModelScope).collectLatest {
|
||||
|
||||
Reference in New Issue
Block a user