diff --git a/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt b/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt index 26ad1c9..98ac41d 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt @@ -1,5 +1,6 @@ package com.aiosman.riderpro.ui.post +import android.util.Log import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExperimentalSharedTransitionApi import androidx.compose.animation.animateContentSize @@ -55,6 +56,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight @@ -258,113 +260,110 @@ fun PostScreen( val scope = rememberCoroutineScope() val commentsPagging = viewModel.commentsFlow.collectAsLazyPagingItems() - var showCollapseContent by remember { mutableStateOf(true) } + var showCollapseContent by remember { mutableStateOf(false) } val scrollState = rememberLazyListState() - val uiController = rememberSystemUiController() LaunchedEffect(Unit) { -// uiController.setNavigationBarColor(Color.Transparent) viewModel.initData() } - Scaffold( - modifier = Modifier.fillMaxSize(), - bottomBar = { - BottomNavigationBar( - onLikeClick = { - scope.launch { - if (viewModel.moment?.liked == true) { - viewModel.dislikeMoment() - } else { - viewModel.likeMoment() - } - } - }, - onCreateComment = { - scope.launch { - viewModel.createComment(it) - commentsPagging.refresh() - } - }, - onFavoriteClick = { - scope.launch { - if (viewModel.moment?.isFavorite == true) { - viewModel.unfavoriteMoment() - } else { - viewModel.favoriteMoment() - } - } - }, - momentEntity = viewModel.moment - ) - } - ) { - it - Column( - modifier = Modifier - .fillMaxSize() - ) { - StatusBarSpacer() - Header( - avatar = viewModel.avatar, - nickname = viewModel.nickname, - userId = viewModel.moment?.authorId, - isFollowing = viewModel.accountProfileEntity?.isFollowing ?: false, - onFollowClick = { - scope.launch { - if (viewModel.accountProfileEntity?.isFollowing == true) { - viewModel.unfollowUser() - } else { - viewModel.followUser() - } + Scaffold( + modifier = Modifier.fillMaxSize(), + bottomBar = { + BottomNavigationBar( + onLikeClick = { + scope.launch { + if (viewModel.moment?.liked == true) { + viewModel.dislikeMoment() + } else { + viewModel.likeMoment() } } - ) - Column(modifier = Modifier.animateContentSize()) { - AnimatedVisibility(visible = showCollapseContent) { - // collapse content - Column( - modifier = Modifier - .fillMaxWidth() - ) { - Box( - modifier = Modifier - .fillMaxWidth() - .aspectRatio(1f) - ) { - PostImageView( - id, - viewModel.moment?.images ?: emptyList() - ) - - } - PostDetails( - id, - viewModel.moment - ) + }, + onCreateComment = { + scope.launch { + viewModel.createComment(it) + commentsPagging.refresh() + } + }, + onFavoriteClick = { + scope.launch { + if (viewModel.moment?.isFavorite == true) { + viewModel.unfavoriteMoment() + } else { + viewModel.favoriteMoment() + } + } + }, + momentEntity = viewModel.moment + ) + } + ) { + it + Column( + modifier = Modifier + .fillMaxSize() + ) { + StatusBarSpacer() + Header( + avatar = viewModel.avatar, + nickname = viewModel.nickname, + userId = viewModel.moment?.authorId, + isFollowing = viewModel.accountProfileEntity?.isFollowing ?: false, + onFollowClick = { + scope.launch { + if (viewModel.accountProfileEntity?.isFollowing == true) { + viewModel.unfollowUser() + } else { + viewModel.followUser() } } } - Box( - modifier = Modifier - .fillMaxWidth() - ) { - CommentsSection( - lazyPagingItems = commentsPagging, - scrollState, - onLike = { commentEntity: CommentEntity -> + ) + LazyColumn( + modifier = Modifier + .fillMaxWidth().weight(1f) + ) { + item { + Box( + modifier = Modifier + .fillMaxWidth() + .aspectRatio(1f) + ) { + PostImageView( + id, + viewModel.moment?.images ?: emptyList() + ) + + } + PostDetails( + id, + viewModel.moment + ) + } + items(commentsPagging.itemCount) { idx -> + val item = commentsPagging[idx] ?: return@items + Box( + modifier = Modifier.padding(horizontal = 16.dp) + ) { + CommentItem(item, onLike = { scope.launch { - if (commentEntity.liked) { - viewModel.unlikeComment(commentEntity.id) + if (item.liked) { + viewModel.unlikeComment(item.id) } else { - viewModel.likeComment(commentEntity.id) + viewModel.likeComment(item.id) } } - }) { - showCollapseContent = it + }) } + } + item { + Spacer(modifier = Modifier.height(72.dp)) + } + } } + } } @@ -439,7 +438,9 @@ fun Header( contentDescription = "" ) Text( - text = if (isFollowing) "Following" else "Follow", + text = if (isFollowing) stringResource(R.string.following_upper) else stringResource( + R.string.follow_upper + ), fontSize = 12.sp, color = Color.White, style = TextStyle(fontWeight = FontWeight.Bold) @@ -540,9 +541,9 @@ fun PostDetails( fontSize = 16.sp, fontWeight = FontWeight.Bold, ) - Text(text = "${momentEntity?.time?.formatPostTime()} 发布") + Text(text = "${momentEntity?.time?.formatPostTime()}") Spacer(modifier = Modifier.height(8.dp)) - Text(text = "${momentEntity?.commentCount ?: 0} Comments") + Text(text = stringResource(R.string.comment_count, (momentEntity?.commentCount ?: 0))) } } @@ -556,8 +557,8 @@ fun CommentsSection( ) { LazyColumn( state = scrollState, modifier = Modifier - .padding(start = 16.dp, end = 16.dp) .fillMaxHeight() + .padding(start = 16.dp, end = 16.dp) ) { items(lazyPagingItems.itemCount) { idx -> val item = lazyPagingItems[idx] ?: return@items @@ -573,6 +574,7 @@ fun CommentsSection( coroutineScope.launch { snapshotFlow { scrollState.firstVisibleItemScrollOffset } .collect { offset -> + Log.d("scroll", "offset: $offset") onWillCollapse(offset == 0) } } @@ -600,11 +602,15 @@ fun CommentItem(commentEntity: CommentEntity, onLike: () -> Unit = {}) { ) { Text(text = commentEntity.name, fontWeight = FontWeight.Bold) Text(text = commentEntity.comment) - Text(text = commentEntity.date.timeAgo(context), fontSize = 12.sp, color = Color.Gray) + Text( + text = commentEntity.date.timeAgo(context), + fontSize = 12.sp, + color = Color.Gray + ) } Column( - modifier = Modifier.width(64.dp), - horizontalAlignment = Alignment.CenterHorizontally) { + horizontalAlignment = Alignment.CenterHorizontally + ) { IconButton(onClick = { onLike() }) { @@ -660,7 +666,7 @@ fun BottomNavigationBar( Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier - .padding(horizontal = 16.dp, vertical = 8.dp) + .padding(horizontal = 16.dp) .background(Color.White) ) { // grey round box @@ -681,7 +687,7 @@ fun BottomNavigationBar( ) { Icon(Icons.Filled.Edit, contentDescription = "Send") Spacer(modifier = Modifier.width(8.dp)) - Text(text = "说点什么", fontSize = 12.sp) + Text(text = stringResource(R.string.post_comment_hint), fontSize = 12.sp) } }