更新代码
This commit is contained in:
@@ -10,6 +10,7 @@ import com.aiosman.riderpro.data.api.UpdateNoticeRequestBody
|
|||||||
import com.aiosman.riderpro.entity.AccountFavouriteEntity
|
import com.aiosman.riderpro.entity.AccountFavouriteEntity
|
||||||
import com.aiosman.riderpro.entity.AccountLikeEntity
|
import com.aiosman.riderpro.entity.AccountLikeEntity
|
||||||
import com.aiosman.riderpro.entity.AccountProfileEntity
|
import com.aiosman.riderpro.entity.AccountProfileEntity
|
||||||
|
import com.aiosman.riderpro.entity.NoticeCommentEntity
|
||||||
import com.aiosman.riderpro.entity.NoticePostEntity
|
import com.aiosman.riderpro.entity.NoticePostEntity
|
||||||
import com.aiosman.riderpro.entity.NoticeUserEntity
|
import com.aiosman.riderpro.entity.NoticeUserEntity
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
@@ -102,6 +103,34 @@ data class NoticePost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//"comment": {
|
||||||
|
// "id": 103,
|
||||||
|
// "content": "ppp",
|
||||||
|
// "time": "2024-09-08 15:31:37"
|
||||||
|
//}
|
||||||
|
data class NoticeComment(
|
||||||
|
@SerializedName("id")
|
||||||
|
val id: Int,
|
||||||
|
@SerializedName("content")
|
||||||
|
val content: String,
|
||||||
|
@SerializedName("time")
|
||||||
|
val time: String,
|
||||||
|
@SerializedName("replyComment")
|
||||||
|
val replyComment: NoticeComment?,
|
||||||
|
@SerializedName("postId")
|
||||||
|
val postId: Int,
|
||||||
|
) {
|
||||||
|
fun toNoticeCommentEntity(): NoticeCommentEntity {
|
||||||
|
return NoticeCommentEntity(
|
||||||
|
id = id,
|
||||||
|
content = content,
|
||||||
|
postId = postId,
|
||||||
|
time = ApiClient.dateFromApiString(time),
|
||||||
|
replyComment = replyComment?.toNoticeCommentEntity()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息关联用户
|
* 消息关联用户
|
||||||
*/
|
*/
|
||||||
@@ -137,19 +166,26 @@ data class AccountLike(
|
|||||||
val isUnread: Boolean,
|
val isUnread: Boolean,
|
||||||
// 动态
|
// 动态
|
||||||
@SerializedName("post")
|
@SerializedName("post")
|
||||||
val post: NoticePost,
|
val post: NoticePost?,
|
||||||
|
@SerializedName("comment")
|
||||||
|
val comment: NoticeComment?,
|
||||||
// 点赞用户
|
// 点赞用户
|
||||||
@SerializedName("user")
|
@SerializedName("user")
|
||||||
val user: NoticeUser,
|
val user: NoticeUser,
|
||||||
// 点赞时间
|
// 点赞时间
|
||||||
@SerializedName("likeTime")
|
@SerializedName("likeTime")
|
||||||
val likeTime: String,
|
val likeTime: String,
|
||||||
|
// 动态ID
|
||||||
|
@SerializedName("postId")
|
||||||
|
val postId: Int,
|
||||||
) {
|
) {
|
||||||
fun toAccountLikeEntity(): AccountLikeEntity {
|
fun toAccountLikeEntity(): AccountLikeEntity {
|
||||||
return AccountLikeEntity(
|
return AccountLikeEntity(
|
||||||
post = post.toNoticePostEntity(),
|
post = post?.toNoticePostEntity(),
|
||||||
|
comment = comment?.toNoticeCommentEntity(),
|
||||||
user = user.toNoticeUserEntity(),
|
user = user.toNoticeUserEntity(),
|
||||||
likeTime = ApiClient.dateFromApiString(likeTime)
|
likeTime = ApiClient.dateFromApiString(likeTime),
|
||||||
|
postId = postId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,8 +356,13 @@ class AccountServiceImpl : AccountService {
|
|||||||
|
|
||||||
override suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth {
|
override suspend fun loginUserWithPassword(loginName: String, password: String): UserAuth {
|
||||||
val resp = ApiClient.api.login(LoginUserRequestBody(loginName, password))
|
val resp = ApiClient.api.login(LoginUserRequestBody(loginName, password))
|
||||||
val body = resp.body() ?: throw ServiceException("Failed to login")
|
if (!resp.isSuccessful) {
|
||||||
return UserAuth(0, body.token)
|
parseErrorResponse(resp.errorBody())?.let {
|
||||||
|
throw it.toServiceException()
|
||||||
|
}
|
||||||
|
throw ServiceException("Failed to register")
|
||||||
|
}
|
||||||
|
return UserAuth(0, resp.body()?.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun loginUserWithGoogle(googleId: String): UserAuth {
|
override suspend fun loginUserWithGoogle(googleId: String): UserAuth {
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ import java.util.Date
|
|||||||
*/
|
*/
|
||||||
data class AccountLikeEntity(
|
data class AccountLikeEntity(
|
||||||
// 动态
|
// 动态
|
||||||
val post: NoticePostEntity,
|
val post: NoticePostEntity?,
|
||||||
|
// 回复评论
|
||||||
|
val comment: NoticeCommentEntity?,
|
||||||
// 点赞用户
|
// 点赞用户
|
||||||
val user: NoticeUserEntity,
|
val user: NoticeUserEntity,
|
||||||
// 点赞时间
|
// 点赞时间
|
||||||
val likeTime: Date,
|
val likeTime: Date,
|
||||||
|
// 动态ID
|
||||||
|
val postId: Int
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,6 +75,19 @@ data class NoticePostEntity(
|
|||||||
val time: Date,
|
val time: Date,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class NoticeCommentEntity(
|
||||||
|
// 评论ID
|
||||||
|
val id: Int,
|
||||||
|
// 评论内容
|
||||||
|
val content: String,
|
||||||
|
// 评论时间
|
||||||
|
val time: Date,
|
||||||
|
// 引用评论
|
||||||
|
val replyComment: NoticeCommentEntity?,
|
||||||
|
// 动态
|
||||||
|
val postId: Int,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息关联的用户
|
* 消息关联的用户
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ fun rememberImageBitmap(imageUrl: String, imageLoader: ImageLoader): Bitmap? {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CustomAsyncImage(
|
fun CustomAsyncImage(
|
||||||
context: Context,
|
context: Context? = null,
|
||||||
imageUrl: String?,
|
imageUrl: String?,
|
||||||
contentDescription: String?,
|
contentDescription: String?,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -58,7 +58,9 @@ fun CustomAsyncImage(
|
|||||||
placeholderRes: Int? = null,
|
placeholderRes: Int? = null,
|
||||||
contentScale: ContentScale = ContentScale.Crop
|
contentScale: ContentScale = ContentScale.Crop
|
||||||
) {
|
) {
|
||||||
val imageLoader = getImageLoader(context)
|
val localContext = LocalContext.current
|
||||||
|
|
||||||
|
val imageLoader = getImageLoader(context ?: localContext)
|
||||||
// val blurBitmap = remember(blurHash) {
|
// val blurBitmap = remember(blurHash) {
|
||||||
// blurHash?.let {
|
// blurHash?.let {
|
||||||
// BlurHashDecoder.decode(
|
// BlurHashDecoder.decode(
|
||||||
@@ -86,7 +88,7 @@ fun CustomAsyncImage(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = ImageRequest.Builder(context)
|
model = ImageRequest.Builder(context ?: localContext)
|
||||||
.data(imageUrl)
|
.data(imageUrl)
|
||||||
.crossfade(200)
|
.crossfade(200)
|
||||||
.build(),
|
.build(),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import com.aiosman.riderpro.R
|
|||||||
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
|
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
|
||||||
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
|
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
|
||||||
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
|
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
|
||||||
import com.aiosman.riderpro.ui.like.ActionNoticeItem
|
import com.aiosman.riderpro.ui.like.ActionPostNoticeItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收藏消息界面
|
* 收藏消息界面
|
||||||
@@ -59,7 +59,7 @@ fun FavouriteNoticeScreen() {
|
|||||||
items(favourites.itemCount) {
|
items(favourites.itemCount) {
|
||||||
val favouriteItem = favourites[it]
|
val favouriteItem = favourites[it]
|
||||||
if (favouriteItem != null) {
|
if (favouriteItem != null) {
|
||||||
ActionNoticeItem(
|
ActionPostNoticeItem(
|
||||||
avatar = favouriteItem.user.avatar,
|
avatar = favouriteItem.user.avatar,
|
||||||
nickName = favouriteItem.user.nickName,
|
nickName = favouriteItem.user.nickName,
|
||||||
likeTime = favouriteItem.favoriteTime,
|
likeTime = favouriteItem.favoriteTime,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.text.ClickableText
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -20,21 +21,30 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.withStyle
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
|
import com.aiosman.riderpro.AppState
|
||||||
import com.aiosman.riderpro.LocalNavController
|
import com.aiosman.riderpro.LocalNavController
|
||||||
import com.aiosman.riderpro.R
|
import com.aiosman.riderpro.R
|
||||||
|
import com.aiosman.riderpro.entity.AccountLikeEntity
|
||||||
import com.aiosman.riderpro.exp.timeAgo
|
import com.aiosman.riderpro.exp.timeAgo
|
||||||
import com.aiosman.riderpro.ui.NavigationRoute
|
import com.aiosman.riderpro.ui.NavigationRoute
|
||||||
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
|
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
|
||||||
|
import com.aiosman.riderpro.ui.composables.AnimatedLikeIcon
|
||||||
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
|
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
|
||||||
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
|
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
|
||||||
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
|
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
|
||||||
|
import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
|
||||||
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
|
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@@ -77,16 +87,21 @@ fun LikeNoticeScreen() {
|
|||||||
items(likes.itemCount) {
|
items(likes.itemCount) {
|
||||||
val likeItem = likes[it]
|
val likeItem = likes[it]
|
||||||
if (likeItem != null) {
|
if (likeItem != null) {
|
||||||
ActionNoticeItem(
|
likeItem.post?.let { post ->
|
||||||
|
ActionPostNoticeItem(
|
||||||
avatar = likeItem.user.avatar,
|
avatar = likeItem.user.avatar,
|
||||||
nickName = likeItem.user.nickName,
|
nickName = likeItem.user.nickName,
|
||||||
likeTime = likeItem.likeTime,
|
likeTime = likeItem.likeTime,
|
||||||
thumbnail = likeItem.post.images[0].thumbnail,
|
thumbnail = post.images[0].thumbnail,
|
||||||
action = "like",
|
action = "like",
|
||||||
userId = likeItem.user.id,
|
userId = likeItem.user.id,
|
||||||
postId = likeItem.post.id
|
postId = post.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
likeItem.comment?.let { comment ->
|
||||||
|
LikeCommentNoticeItem(likeItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
BottomNavigationPlaceholder()
|
BottomNavigationPlaceholder()
|
||||||
@@ -98,7 +113,7 @@ fun LikeNoticeScreen() {
|
|||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ActionNoticeItem(
|
fun ActionPostNoticeItem(
|
||||||
avatar: String,
|
avatar: String,
|
||||||
nickName: String,
|
nickName: String,
|
||||||
likeTime: Date,
|
likeTime: Date,
|
||||||
@@ -146,7 +161,12 @@ fun ActionNoticeItem(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(nickName, fontWeight = FontWeight.Bold, fontSize = 16.sp)
|
Text(nickName, fontWeight = FontWeight.Bold, fontSize = 16.sp)
|
||||||
Spacer(modifier = Modifier.height(5.dp))
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
|
when (action) {
|
||||||
|
"like" -> Text("Like your post")
|
||||||
|
"favourite" -> Text("Favourite your post")
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
Row {
|
Row {
|
||||||
Text(likeTime.timeAgo(context), fontSize = 12.sp, color = Color(0x99000000))
|
Text(likeTime.timeAgo(context), fontSize = 12.sp, color = Color(0x99000000))
|
||||||
}
|
}
|
||||||
@@ -160,3 +180,94 @@ fun ActionNoticeItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LikeCommentNoticeItem(
|
||||||
|
item: AccountLikeEntity
|
||||||
|
) {
|
||||||
|
val navController = LocalNavController.current
|
||||||
|
val context = LocalContext.current
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp).noRippleClickable {
|
||||||
|
item.comment?.postId.let {
|
||||||
|
navController.navigate(
|
||||||
|
NavigationRoute.Post.route.replace(
|
||||||
|
"{id}",
|
||||||
|
it.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.Top,
|
||||||
|
) {
|
||||||
|
CustomAsyncImage(
|
||||||
|
imageUrl = item.user.avatar,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(48.dp)
|
||||||
|
.clip(CircleShape),
|
||||||
|
contentDescription = "Like your comment"
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
) {
|
||||||
|
Text(item.user.nickName, fontWeight = FontWeight.Bold, fontSize = 16.sp)
|
||||||
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
|
Text("Like your comment")
|
||||||
|
Spacer(modifier = Modifier.height(2.dp))
|
||||||
|
Row {
|
||||||
|
Text(
|
||||||
|
item.likeTime.timeAgo(context),
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = Color(0x99000000)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(start = 48.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(24.dp)
|
||||||
|
.background(Color.Gray.copy(alpha = 0.1f))
|
||||||
|
) {
|
||||||
|
CustomAsyncImage(
|
||||||
|
context = context,
|
||||||
|
imageUrl = MyProfileViewModel.avatar,
|
||||||
|
contentDescription = "Comment Profile Picture",
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = MyProfileViewModel.nickName,
|
||||||
|
fontWeight = FontWeight.W600,
|
||||||
|
fontSize = 14.sp
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = item.comment?.content ?: "",
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = Color(0x99000000)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user