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

Commit

Permalink
feat: 收藏楼层提示
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Jul 21, 2023
1 parent a5e365a commit 70907c2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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() }
}

Expand Down
34 changes: 23 additions & 11 deletions app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/Chip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
)
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,6 @@
<string name="title_image_watermark_forum_name">显示吧名</string>
<string name="title_modify_username">修改用户名</string>
<string name="btn_reply">回复</string>
<string name="title_collect_floor">收藏到此楼</string>
<string name="title_collected_floor">已收藏到本楼</string>
</resources>

0 comments on commit 70907c2

Please sign in to comment.