From f310f5882824c0ef398ba89e68884f98820d0a04 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:56:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(SearchPost):=20=E8=B7=B3=E8=BD=AC=E5=8E=9F?= =?UTF-8?q?=E8=B4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/api/models/SearchThreadBean.kt | 13 +++-- .../tieba/post/ui/common/PbContentRender.kt | 3 +- .../forum/searchpost/ForumSearchPostPage.kt | 51 +++++++++++++++++-- .../tieba/post/ui/widgets/compose/FeedCard.kt | 3 +- .../tieba/post/ui/widgets/compose/Search.kt | 16 ++++-- 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/models/SearchThreadBean.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/models/SearchThreadBean.kt index fff8d078..28a35e64 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/models/SearchThreadBean.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/models/SearchThreadBean.kt @@ -35,6 +35,7 @@ data class SearchThreadBean( data class ThreadInfoBean( val tid: String, val pid: String, + val cid: String, val title: String, val content: String, val time: String, @@ -74,18 +75,22 @@ data class SearchThreadBean( @Serializable data class MediaInfo( val type: String, - val size: String, + val size: String? = null, val width: String, val height: String, @SerialName("water_pic") @SerializedName("water_pic") - val waterPic: String, + val waterPic: String? = null, @SerialName("small_pic") @SerializedName("small_pic") - val smallPic: String, + val smallPic: String? = null, @SerialName("big_pic") @SerializedName("big_pic") - val bigPic: String, + val bigPic: String? = null, + val src: String? = null, + val vsrc: String? = null, + val vhsrc: String? = null, + val vpic: String? = null, ) @Immutable diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt index 81e53733..dd546ff2 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt @@ -47,6 +47,7 @@ import com.huanchengfly.tieba.post.ui.page.destinations.UserProfilePageDestinati import com.huanchengfly.tieba.post.ui.widgets.compose.EmoticonText import com.huanchengfly.tieba.post.ui.widgets.compose.NetworkImage import com.huanchengfly.tieba.post.ui.widgets.compose.VoicePlayer +import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString import com.huanchengfly.tieba.post.utils.appPreferences import com.huanchengfly.tieba.post.utils.launchUrl @@ -245,7 +246,7 @@ fun PbContentText( style: TextStyle = LocalTextStyle.current, ) { PbContentText( - text = AnnotatedString(text), + text = text.emoticonString, modifier = modifier, color = color, fontSize = fontSize, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/searchpost/ForumSearchPostPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/searchpost/ForumSearchPostPage.kt index f20a8d85..072d0c52 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/searchpost/ForumSearchPostPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/searchpost/ForumSearchPostPage.kt @@ -27,6 +27,7 @@ import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material.ripple.rememberRipple import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -51,6 +52,7 @@ import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme import com.huanchengfly.tieba.post.ui.common.theme.compose.pullRefreshIndicator import com.huanchengfly.tieba.post.ui.page.ProvideNavigator import com.huanchengfly.tieba.post.ui.page.destinations.ForumPageDestination +import com.huanchengfly.tieba.post.ui.page.destinations.SubPostsPageDestination import com.huanchengfly.tieba.post.ui.page.destinations.ThreadPageDestination import com.huanchengfly.tieba.post.ui.page.destinations.UserProfilePageDestination import com.huanchengfly.tieba.post.ui.widgets.compose.ClickMenu @@ -126,6 +128,12 @@ fun ForumSearchPostPage( } var inputKeyword by remember { mutableStateOf("") } + LaunchedEffect(currentKeyword) { + if (currentKeyword.isNotEmpty() && currentKeyword != inputKeyword) { + inputKeyword = currentKeyword + } + } + fun refresh() { viewModel.send( ForumSearchPostUiIntent.Refresh( @@ -266,11 +274,29 @@ fun ForumSearchPostPage( data = data, lazyListState = lazyListState, onItemClick = { - navigator.navigate( - ThreadPageDestination( - threadId = it.tid.toLong() + if (it.postInfo != null) { + navigator.navigate( + SubPostsPageDestination( + threadId = it.tid.toLong(), + subPostId = it.cid.toLong(), + loadFromSubPost = true + ) ) - ) + } else if (it.mainPost != null) { + navigator.navigate( + ThreadPageDestination( + threadId = it.tid.toLong(), + postId = it.pid.toLong(), + scrollToReply = true, + ) + ) + } else { + navigator.navigate( + ThreadPageDestination( + threadId = it.tid.toLong() + ) + ) + } }, onItemUserClick = { navigator.navigate(UserProfilePageDestination(it.userId.toLong())) @@ -282,6 +308,23 @@ fun ForumSearchPostPage( ) ) }, + onQuotePostClick = { + navigator.navigate( + ThreadPageDestination( + threadId = it.tid, + postId = it.pid, + scrollToReply = true + ) + ) + }, + onMainPostClick = { + navigator.navigate( + ThreadPageDestination( + threadId = it.tid, + scrollToReply = true + ) + ) + }, hideForum = true, ) { stickyHeader(key = "Sort&Filter") { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt index e10dee9b..3a9b8793 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/FeedCard.kt @@ -270,6 +270,7 @@ fun ThreadContent( showTitle: Boolean = true, showAbstract: Boolean = true, isGood: Boolean = false, + maxLines: Int = 5, ) { val content = buildAnnotatedString { if (showTitle) { @@ -305,7 +306,7 @@ fun ThreadContent( fontSize = 15.sp, lineSpacing = 0.8.sp, overflow = TextOverflow.Ellipsis, - maxLines = 5, + maxLines = maxLines, style = MaterialTheme.typography.body1, ) } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Search.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Search.kt index d60f4304..0c9f7c40 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Search.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Search.kt @@ -78,7 +78,6 @@ fun QuotePostCard( PbContentText( text = quoteContentString, style = MaterialTheme.typography.body2, - modifier = modifier, maxLines = 2, overflow = TextOverflow.Ellipsis, ) @@ -113,7 +112,6 @@ fun MainPostCard( text = titleString, style = MaterialTheme.typography.subtitle2, fontWeight = FontWeight.Bold, - modifier = modifier, maxLines = 2, overflow = TextOverflow.Ellipsis, ) @@ -121,7 +119,6 @@ fun MainPostCard( PbContentText( text = mainPost.content, style = MaterialTheme.typography.body2, - modifier = modifier, maxLines = 2, overflow = TextOverflow.Ellipsis, ) @@ -137,6 +134,8 @@ fun SearchThreadList( onItemUserClick: (SearchThreadBean.UserInfoBean) -> Unit, onItemForumClick: (SearchThreadBean.ForumInfo) -> Unit, modifier: Modifier = Modifier, + onQuotePostClick: (SearchThreadBean.PostInfo) -> Unit = {}, + onMainPostClick: (SearchThreadBean.MainPost) -> Unit = {}, hideForum: Boolean = false, header: LazyListScope.() -> Unit = {}, ) { @@ -155,6 +154,8 @@ fun SearchThreadList( onUserClick = onItemUserClick, onForumClick = onItemForumClick, hideForum = hideForum, + onQuotePostClick = onQuotePostClick, + onMainPostClick = onMainPostClick, ) } } @@ -202,6 +203,8 @@ fun SearchThreadItem( onUserClick: (SearchThreadBean.UserInfoBean) -> Unit, onForumClick: (SearchThreadBean.ForumInfo) -> Unit, modifier: Modifier = Modifier, + onQuotePostClick: (SearchThreadBean.PostInfo) -> Unit = {}, + onMainPostClick: (SearchThreadBean.MainPost) -> Unit = {}, hideForum: Boolean = false, ) { Card( @@ -219,6 +222,7 @@ fun SearchThreadItem( abstractText = item.content, showTitle = item.mainPost == null && item.title.isNotBlank(), showAbstract = item.content.isNotBlank(), + maxLines = 2, ) if (item.mainPost != null) { if (item.postInfo != null) { @@ -229,6 +233,9 @@ fun SearchThreadItem( .fillMaxWidth() .clip(RoundedCornerShape(6.dp)) .background(ExtendedTheme.colors.floorCard) + .clickable { + onQuotePostClick(item.postInfo) + } ) } else { MainPostCard( @@ -237,6 +244,9 @@ fun SearchThreadItem( .fillMaxWidth() .clip(RoundedCornerShape(6.dp)) .background(ExtendedTheme.colors.floorCard) + .clickable { + onMainPostClick(item.mainPost) + } ) } }