2024-07-29 00:01:09 +08:00
|
|
|
package com.aiosman.riderpro.data
|
2024-07-23 15:25:00 +08:00
|
|
|
|
2024-07-30 15:49:59 +08:00
|
|
|
import com.aiosman.riderpro.R
|
2024-08-11 17:15:17 +08:00
|
|
|
import com.aiosman.riderpro.data.api.ApiClient
|
2024-08-24 23:11:20 +08:00
|
|
|
import com.aiosman.riderpro.entity.MomentEntity
|
|
|
|
|
import com.aiosman.riderpro.entity.MomentImageEntity
|
2024-08-11 17:15:17 +08:00
|
|
|
import com.google.gson.annotations.SerializedName
|
|
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
|
|
data class Moment(
|
|
|
|
|
@SerializedName("id")
|
|
|
|
|
val id: Long,
|
|
|
|
|
@SerializedName("textContent")
|
|
|
|
|
val textContent: String,
|
|
|
|
|
@SerializedName("images")
|
|
|
|
|
val images: List<Image>,
|
|
|
|
|
@SerializedName("user")
|
|
|
|
|
val user: User,
|
|
|
|
|
@SerializedName("likeCount")
|
|
|
|
|
val likeCount: Long,
|
|
|
|
|
@SerializedName("isLiked")
|
|
|
|
|
val isLiked: Boolean,
|
|
|
|
|
@SerializedName("favoriteCount")
|
|
|
|
|
val favoriteCount: Long,
|
|
|
|
|
@SerializedName("isFavorite")
|
|
|
|
|
val isFavorite: Boolean,
|
|
|
|
|
@SerializedName("shareCount")
|
|
|
|
|
val isCommented: Boolean,
|
|
|
|
|
@SerializedName("commentCount")
|
|
|
|
|
val commentCount: Long,
|
|
|
|
|
@SerializedName("time")
|
2024-09-14 23:27:44 +08:00
|
|
|
val time: String,
|
|
|
|
|
@SerializedName("isFollowed")
|
|
|
|
|
val isFollowed: Boolean,
|
2024-08-11 17:15:17 +08:00
|
|
|
) {
|
|
|
|
|
fun toMomentItem(): MomentEntity {
|
|
|
|
|
return MomentEntity(
|
|
|
|
|
id = id.toInt(),
|
2024-08-22 23:43:01 +08:00
|
|
|
avatar = "${ApiClient.BASE_SERVER}${user.avatar}",
|
2024-08-11 17:15:17 +08:00
|
|
|
nickname = user.nickName,
|
|
|
|
|
location = "Worldwide",
|
2024-08-24 21:59:16 +08:00
|
|
|
time = ApiClient.dateFromApiString(time),
|
2024-09-14 23:27:44 +08:00
|
|
|
followStatus = isFollowed,
|
2024-08-11 17:15:17 +08:00
|
|
|
momentTextContent = textContent,
|
|
|
|
|
momentPicture = R.drawable.default_moment_img,
|
|
|
|
|
likeCount = likeCount.toInt(),
|
|
|
|
|
commentCount = commentCount.toInt(),
|
|
|
|
|
shareCount = 0,
|
|
|
|
|
favoriteCount = favoriteCount.toInt(),
|
2024-08-17 17:40:21 +08:00
|
|
|
images = images.map {
|
|
|
|
|
MomentImageEntity(
|
2024-08-22 23:43:01 +08:00
|
|
|
url = "${ApiClient.BASE_SERVER}${it.url}",
|
|
|
|
|
thumbnail = "${ApiClient.BASE_SERVER}${it.thumbnail}",
|
|
|
|
|
id = it.id,
|
2024-10-08 17:25:27 +08:00
|
|
|
blurHash = it.blurHash,
|
|
|
|
|
width = it.width,
|
|
|
|
|
height = it.height
|
2024-08-17 17:40:21 +08:00
|
|
|
)
|
|
|
|
|
},
|
2024-08-11 17:15:17 +08:00
|
|
|
authorId = user.id.toInt(),
|
|
|
|
|
liked = isLiked,
|
2024-10-08 17:25:27 +08:00
|
|
|
isFavorite = isFavorite,
|
2024-08-11 17:15:17 +08:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data class Image(
|
|
|
|
|
@SerializedName("id")
|
|
|
|
|
val id: Long,
|
|
|
|
|
@SerializedName("url")
|
|
|
|
|
val url: String,
|
|
|
|
|
@SerializedName("thumbnail")
|
2024-08-22 20:57:32 +08:00
|
|
|
val thumbnail: String,
|
|
|
|
|
@SerializedName("blurHash")
|
2024-10-08 17:25:27 +08:00
|
|
|
val blurHash: String?,
|
|
|
|
|
@SerializedName("width")
|
|
|
|
|
val width: Int?,
|
|
|
|
|
@SerializedName("height")
|
|
|
|
|
val height: Int?
|
2024-08-11 17:15:17 +08:00
|
|
|
)
|
2024-07-29 16:50:07 +08:00
|
|
|
|
2024-08-11 17:15:17 +08:00
|
|
|
data class User(
|
|
|
|
|
@SerializedName("id")
|
|
|
|
|
val id: Long,
|
|
|
|
|
@SerializedName("nickName")
|
|
|
|
|
val nickName: String,
|
|
|
|
|
@SerializedName("avatar")
|
|
|
|
|
val avatar: String
|
|
|
|
|
)
|
2024-08-17 17:40:21 +08:00
|
|
|
|
2024-08-11 17:15:17 +08:00
|
|
|
data class UploadImage(
|
|
|
|
|
val file: File,
|
|
|
|
|
val filename: String,
|
|
|
|
|
val url: String,
|
|
|
|
|
val ext: String
|
|
|
|
|
)
|
2024-08-17 17:40:21 +08:00
|
|
|
|
2024-07-29 16:50:07 +08:00
|
|
|
interface MomentService {
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 获取动态详情
|
|
|
|
|
* @param id 动态ID
|
|
|
|
|
*/
|
2024-08-11 17:15:17 +08:00
|
|
|
suspend fun getMomentById(id: Int): MomentEntity
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 点赞动态
|
|
|
|
|
* @param id 动态ID
|
|
|
|
|
*/
|
2024-07-29 16:50:07 +08:00
|
|
|
suspend fun likeMoment(id: Int)
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取消点赞动态
|
|
|
|
|
* @param id 动态ID
|
|
|
|
|
*/
|
2024-07-30 14:28:13 +08:00
|
|
|
suspend fun dislikeMoment(id: Int)
|
2024-08-24 23:11:20 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取动态列表
|
|
|
|
|
* @param pageNumber 页码
|
|
|
|
|
* @param author 作者ID,过滤条件
|
|
|
|
|
* @param timelineId 用户时间线ID,指定用户 ID 的时间线
|
|
|
|
|
* @param contentSearch 内容搜索,过滤条件
|
2024-09-01 19:39:46 +08:00
|
|
|
* @param trend 是否趋势动态
|
2024-10-26 17:17:29 +08:00
|
|
|
* @param explore 是否探索动态
|
2024-08-24 23:11:20 +08:00
|
|
|
* @return 动态列表
|
|
|
|
|
*/
|
2024-07-29 16:50:07 +08:00
|
|
|
suspend fun getMoments(
|
|
|
|
|
pageNumber: Int,
|
|
|
|
|
author: Int? = null,
|
2024-08-17 17:40:21 +08:00
|
|
|
timelineId: Int? = null,
|
2024-09-01 19:39:46 +08:00
|
|
|
contentSearch: String? = null,
|
2024-09-13 23:20:38 +08:00
|
|
|
trend: Boolean? = false,
|
2024-10-26 17:17:29 +08:00
|
|
|
explore: Boolean? = false,
|
2024-09-13 23:20:38 +08:00
|
|
|
favoriteUserId: Int? = null
|
2024-08-11 17:15:17 +08:00
|
|
|
): ListContainer<MomentEntity>
|
2024-07-30 15:49:59 +08:00
|
|
|
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 创建动态
|
|
|
|
|
* @param content 动态内容
|
|
|
|
|
* @param authorId 作者ID
|
|
|
|
|
* @param images 图片列表
|
|
|
|
|
* @param relPostId 关联动态ID
|
|
|
|
|
*/
|
2024-07-30 15:49:59 +08:00
|
|
|
suspend fun createMoment(
|
|
|
|
|
content: String,
|
|
|
|
|
authorId: Int,
|
2024-08-11 17:15:17 +08:00
|
|
|
images: List<UploadImage>,
|
2024-07-31 14:50:55 +08:00
|
|
|
relPostId: Int? = null
|
2024-08-11 17:15:17 +08:00
|
|
|
): MomentEntity
|
2024-08-17 17:40:21 +08:00
|
|
|
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 收藏动态
|
|
|
|
|
* @param id 动态ID
|
|
|
|
|
*/
|
2024-08-11 17:15:17 +08:00
|
|
|
suspend fun favoriteMoment(id: Int)
|
2024-07-30 15:49:59 +08:00
|
|
|
|
2024-08-24 23:11:20 +08:00
|
|
|
/**
|
|
|
|
|
* 取消收藏动态
|
|
|
|
|
* @param id 动态ID
|
|
|
|
|
*/
|
|
|
|
|
suspend fun unfavoriteMoment(id: Int)
|
2024-09-07 15:37:26 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除动态
|
|
|
|
|
*/
|
|
|
|
|
suspend fun deleteMoment(id: Int)
|
2024-07-23 15:25:00 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-30 15:49:59 +08:00
|
|
|
|