Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
feat(SearchPost): 跳转原贴
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Jan 29, 2024
1 parent 1761507 commit f310f58
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -245,7 +246,7 @@ fun PbContentText(
style: TextStyle = LocalTextStyle.current,
) {
PbContentText(
text = AnnotatedString(text),
text = text.emoticonString,
modifier = modifier,
color = color,
fontSize = fontSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()))
Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ fun ThreadContent(
showTitle: Boolean = true,
showAbstract: Boolean = true,
isGood: Boolean = false,
maxLines: Int = 5,
) {
val content = buildAnnotatedString {
if (showTitle) {
Expand Down Expand Up @@ -305,7 +306,7 @@ fun ThreadContent(
fontSize = 15.sp,
lineSpacing = 0.8.sp,
overflow = TextOverflow.Ellipsis,
maxLines = 5,
maxLines = maxLines,
style = MaterialTheme.typography.body1,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ fun QuotePostCard(
PbContentText(
text = quoteContentString,
style = MaterialTheme.typography.body2,
modifier = modifier,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
Expand Down Expand Up @@ -113,15 +112,13 @@ fun MainPostCard(
text = titleString,
style = MaterialTheme.typography.subtitle2,
fontWeight = FontWeight.Bold,
modifier = modifier,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
if (mainPost.content.isNotBlank()) {
PbContentText(
text = mainPost.content,
style = MaterialTheme.typography.body2,
modifier = modifier,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
Expand All @@ -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 = {},
) {
Expand All @@ -155,6 +154,8 @@ fun SearchThreadList(
onUserClick = onItemUserClick,
onForumClick = onItemForumClick,
hideForum = hideForum,
onQuotePostClick = onQuotePostClick,
onMainPostClick = onMainPostClick,
)
}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -229,6 +233,9 @@ fun SearchThreadItem(
.fillMaxWidth()
.clip(RoundedCornerShape(6.dp))
.background(ExtendedTheme.colors.floorCard)
.clickable {
onQuotePostClick(item.postInfo)
}
)
} else {
MainPostCard(
Expand All @@ -237,6 +244,9 @@ fun SearchThreadItem(
.fillMaxWidth()
.clip(RoundedCornerShape(6.dp))
.background(ExtendedTheme.colors.floorCard)
.clickable {
onMainPostClick(item.mainPost)
}
)
}
}
Expand Down

0 comments on commit f310f58

Please sign in to comment.