From 70907c211c29ea379d5346e9e8ee5c1c8e98306d Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 21 Jul 2023 22:54:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B6=E8=97=8F=E6=A5=BC=E5=B1=82?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/page/thread/ThreadPage.kt | 53 ++++++++++++++++++- .../tieba/post/ui/widgets/Chip.kt | 34 ++++++++---- app/src/main/res/values/strings.xml | 2 + 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt index 2a71628f..65f2ebfc 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt @@ -118,6 +118,7 @@ import com.huanchengfly.tieba.post.ui.page.destinations.ForumPageDestination import com.huanchengfly.tieba.post.ui.page.destinations.ReplyPageDestination import com.huanchengfly.tieba.post.ui.page.destinations.SubPostsSheetPageDestination import com.huanchengfly.tieba.post.ui.page.destinations.ThreadPageDestination +import com.huanchengfly.tieba.post.ui.widgets.Chip import com.huanchengfly.tieba.post.ui.widgets.compose.Avatar import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon import com.huanchengfly.tieba.post.ui.widgets.compose.Button @@ -916,6 +917,42 @@ fun ThreadPage( postHolder = firstPost!!, contentRenders = firstPostContentRenders, immersiveMode = isImmersiveMode, + isCollected = { + it.id == thread?.get { collectMarkPid } + ?.toLongOrNull() + }, + showSubPosts = false, + onReplyClick = { + navigator.navigate( + ReplyPageDestination( + forumId = curForumId ?: 0, + forumName = forum?.get { name } + .orEmpty(), + threadId = threadId, + ) + ) + }, + onMenuCopyClick = { + TiebaUtil.copyText( + context, + it.content.plainText + ) + }, + onMenuReportClick = { + TiebaUtil.reportPost( + context, + it.id.toString() + ) + }, + onMenuFavoriteClick = { + viewModel.send( + ThreadUiIntent.AddFavorite( + threadId, + it.id, + it.floor + ) + ) + }, ) VerticalDivider( @@ -1421,7 +1458,7 @@ fun PostCard( if (isCollected(post)) { Text(text = stringResource(id = R.string.title_collect_on)) } else { - Text(text = stringResource(id = R.string.title_collect)) + Text(text = stringResource(id = R.string.title_collect_floor)) } } } @@ -1507,6 +1544,20 @@ fun PostCard( ) } + if (isCollected(post)) { + Chip( + text = stringResource(id = R.string.title_collected_floor), + invertColor = true, + icon = { + Icon( + imageVector = Icons.Rounded.Star, + contentDescription = null, + modifier = Modifier.size(16.dp) + ) + } + ) + } + contentRenders.forEach { it.Render() } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/Chip.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/Chip.kt index 8781ba92..8ffbc2c3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/Chip.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/Chip.kt @@ -2,11 +2,14 @@ package com.huanchengfly.tieba.post.ui.widgets import androidx.compose.animation.animateColorAsState import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Shape @@ -16,13 +19,15 @@ import androidx.compose.ui.unit.sp import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme import com.huanchengfly.tieba.post.ui.common.theme.compose.invertChipBackground import com.huanchengfly.tieba.post.ui.common.theme.compose.invertChipContent +import com.huanchengfly.tieba.post.ui.widgets.compose.ProvideContentColor @Composable fun Chip( text: String, modifier: Modifier = Modifier, + icon: @Composable (() -> Unit)? = null, invertColor: Boolean = false, - shape: Shape = RoundedCornerShape(100) + shape: Shape = RoundedCornerShape(100), ) { val color = if (invertColor) ExtendedTheme.colors.invertChipContent else ExtendedTheme.colors.onChip @@ -35,14 +40,21 @@ fun Chip( label = "ChipBackgroundColor" ) - Text( - color = animatedColor, - fontSize = 12.sp, - fontWeight = FontWeight.Bold, - text = text, - modifier = modifier - .clip(shape) - .background(color = animatedBackgroundColor) - .padding(horizontal = 16.dp, vertical = 4.dp) - ) + ProvideContentColor(color = animatedColor) { + Row( + modifier = modifier + .clip(shape) + .background(color = animatedBackgroundColor) + .padding(horizontal = 16.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + icon?.invoke() + Text( + fontSize = 12.sp, + fontWeight = FontWeight.Bold, + text = text + ) + } + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ea06dc5f..8f2b14a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -697,4 +697,6 @@ 显示吧名 修改用户名 回复 + 收藏到此楼 + 已收藏到本楼