From 2edb341451f5758311659bc12b5d71d9c3b1dbbe Mon Sep 17 00:00:00 2001
From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com>
Date: Mon, 24 Jul 2023 12:05:49 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B6=E8=97=8F=E4=B8=AD=E5=B7=B2?=
=?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E8=B4=B4=E5=AD=90=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ui/page/threadstore/ThreadStorePage.kt | 207 +++++++++---------
.../tieba/post/ui/widgets/compose/Menu.kt | 4 +-
app/src/main/res/values/strings.xml | 1 +
3 files changed, 110 insertions(+), 102 deletions(-)
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStorePage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStorePage.kt
index 319867c2..55af3fe4 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStorePage.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/threadstore/ThreadStorePage.kt
@@ -32,7 +32,6 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
-import androidx.compose.ui.text.TextMeasurer
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
@@ -138,8 +137,6 @@ fun ThreadStorePage(
)
}
) { contentPaddings ->
- val textMeasurer = rememberTextMeasurer()
-
StateScreen(
isEmpty = data.isEmpty(),
isError = isError,
@@ -171,16 +168,15 @@ fun ThreadStorePage(
items = data,
key = { it.threadId }
) { info ->
- LongClickMenu(
- menuContent = {
- DropdownMenuItem(onClick = {
- viewModel.send(
- ThreadStoreUiIntent.Delete(
- info.threadId
- )
+ StoreItem(
+ info = info,
+ onUserClick = {
+ info.author.lzUid?.let {
+ UserActivity.launch(
+ context,
+ it,
+ StringUtil.getAvatarUrl(info.author.userPortrait)
)
- }) {
- Text(text = stringResource(id = R.string.title_collect_on))
}
},
onClick = {
@@ -196,22 +192,15 @@ fun ThreadStorePage(
)
)
)
+ },
+ onDelete = {
+ viewModel.send(
+ ThreadStoreUiIntent.Delete(
+ info.threadId
+ )
+ )
}
- ) {
- StoreItem(
- info = info,
- onUserClick = {
- info.author.lzUid?.let {
- UserActivity.launch(
- context,
- it,
- StringUtil.getAvatarUrl(info.author.userPortrait)
- )
- }
- },
- textMeasurer = textMeasurer
- )
- }
+ )
}
}
}
@@ -233,90 +222,106 @@ fun ThreadStorePage(
private fun StoreItem(
info: ThreadStoreBean.ThreadStoreInfo,
onUserClick: () -> Unit,
+ onDelete: () -> Unit,
+ onClick: () -> Unit,
modifier: Modifier = Modifier,
- textMeasurer: TextMeasurer = rememberTextMeasurer()
) {
- val hasUpdate = info.count != "0" && info.postNo != "0"
- var width = 0
- var height = 0
- Column(
- modifier = modifier
- .padding(16.dp),
- verticalArrangement = Arrangement.spacedBy(8.dp),
+ val hasUpdate = remember(info) { info.count != "0" && info.postNo != "0" }
+ val isDeleted = remember(info) { info.isDeleted == "1" }
+ val textMeasurer = rememberTextMeasurer()
+ LongClickMenu(
+ menuContent = {
+ DropdownMenuItem(onClick = onDelete) {
+ Text(text = stringResource(id = R.string.title_collect_on))
+ }
+ },
+ onClick = onClick
) {
- UserHeader(
- avatar = {
- Avatar(
- data = StringUtil.getAvatarUrl(info.author.userPortrait),
- size = Sizes.Small,
- contentDescription = null
- )
- },
- name = {
- Text(
- text = getUsernameAnnotatedString(
- LocalContext.current,
- info.author.name ?: "",
- info.author.nameShow,
- LocalContentColor.current
+ Column(
+ modifier = modifier
+ .padding(16.dp),
+ verticalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ UserHeader(
+ avatar = {
+ Avatar(
+ data = StringUtil.getAvatarUrl(info.author.userPortrait),
+ size = Sizes.Small,
+ contentDescription = null
)
- )
- },
- onClick = onUserClick,
- )
- val title = remember(info, hasUpdate) {
- buildAnnotatedString {
- append(info.title)
- if (hasUpdate) {
- append(" ")
- appendInlineContent("Update", info.postNo)
+ },
+ name = {
+ Text(
+ text = getUsernameAnnotatedString(
+ LocalContext.current,
+ info.author.name ?: "",
+ info.author.nameShow,
+ LocalContentColor.current
+ )
+ )
+ },
+ onClick = onUserClick,
+ )
+ val title = remember(info, hasUpdate) {
+ buildAnnotatedString {
+ append(info.title)
+ if (hasUpdate) {
+ append(" ")
+ appendInlineContent("Update", info.postNo)
+ }
}
}
- }
- val updateTip = stringResource(
- id = R.string.tip_thread_store_update,
- info.postNo
- )
- if (hasUpdate) {
- val result = textMeasurer.measure(
- AnnotatedString(updateTip),
- style = UpdateTipTextStyle
+ val updateTip = stringResource(
+ id = R.string.tip_thread_store_update,
+ info.postNo
)
- width =
- result.size.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1
- height = result.size.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2
- }
- Text(
- text = title,
- fontSize = 15.sp,
- color = ExtendedTheme.colors.text,
- inlineContent = mapOf(
- "Update" to InlineTextContent(
- placeholder = Placeholder(
- width = width.sp,
- height = height.sp,
- placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
- ),
- children = {
- Box(
- modifier = Modifier
- .fillMaxSize()
- .background(
- color = ExtendedTheme.colors.chip,
- shape = RoundedCornerShape(3.dp)
+ val result = remember {
+ textMeasurer.measure(
+ AnnotatedString(updateTip),
+ style = UpdateTipTextStyle
+ ).size
+ }
+ val width = result.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1
+ val height = result.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2
+ Text(
+ text = title,
+ fontSize = 15.sp,
+ color = if (isDeleted) ExtendedTheme.colors.textDisabled else ExtendedTheme.colors.text,
+ inlineContent = mapOf(
+ "Update" to InlineTextContent(
+ placeholder = Placeholder(
+ width = width.sp,
+ height = height.sp,
+ placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
+ ),
+ children = {
+ Box(
+ modifier = Modifier
+ .fillMaxSize()
+ .background(
+ color = ExtendedTheme.colors.chip,
+ shape = RoundedCornerShape(3.dp)
+ )
+ .padding(vertical = 4.dp, horizontal = 12.dp)
+ ) {
+ Text(
+ text = updateTip,
+ style = UpdateTipTextStyle,
+ color = ExtendedTheme.colors.onChip,
+ modifier = Modifier.align(Alignment.Center)
)
- .padding(vertical = 4.dp, horizontal = 12.dp)
- ) {
- Text(
- text = updateTip,
- style = UpdateTipTextStyle,
- color = ExtendedTheme.colors.onChip,
- modifier = Modifier.align(Alignment.Center)
- )
+ }
}
- }
+ )
)
)
- )
+ if (isDeleted) {
+ Text(
+ text = stringResource(id = R.string.tip_thread_store_deleted),
+ fontSize = 12.sp,
+ color = ExtendedTheme.colors.textDisabled
+ )
+ }
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Menu.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Menu.kt
index 5c4591ba..1985ad39 100644
--- a/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Menu.kt
+++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/widgets/compose/Menu.kt
@@ -110,12 +110,13 @@ fun ClickMenu(
fun LongClickMenu(
menuContent: @Composable (ColumnScope.() -> Unit),
modifier: Modifier = Modifier,
+ enabled: Boolean = true,
menuState: MenuState = rememberMenuState(),
onClick: (() -> Unit)? = null,
shape: Shape = RoundedCornerShape(14.dp),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication? = LocalIndication.current,
- content: @Composable () -> Unit
+ content: @Composable () -> Unit,
) {
LaunchedEffect(key1 = null) {
launch {
@@ -138,6 +139,7 @@ fun LongClickMenu(
.combinedClickable(
interactionSource = interactionSource,
indication = indication,
+ enabled = enabled,
onLongClick = {
menuState.expanded = true
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b8525712..c9839af0 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -708,4 +708,5 @@
查看原贴
由于你的屏蔽设置,该贴已被屏蔽
图片
+ 该贴已被删除