feat: 收藏中已被删除贴子提示

This commit is contained in:
HuanCheng65 2023-07-24 12:05:49 +08:00
parent c7c646d7de
commit 2edb341451
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
3 changed files with 110 additions and 102 deletions

View File

@ -32,7 +32,6 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.Placeholder import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.TextMeasurer
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@ -138,8 +137,6 @@ fun ThreadStorePage(
) )
} }
) { contentPaddings -> ) { contentPaddings ->
val textMeasurer = rememberTextMeasurer()
StateScreen( StateScreen(
isEmpty = data.isEmpty(), isEmpty = data.isEmpty(),
isError = isError, isError = isError,
@ -171,16 +168,15 @@ fun ThreadStorePage(
items = data, items = data,
key = { it.threadId } key = { it.threadId }
) { info -> ) { info ->
LongClickMenu( StoreItem(
menuContent = { info = info,
DropdownMenuItem(onClick = { onUserClick = {
viewModel.send( info.author.lzUid?.let {
ThreadStoreUiIntent.Delete( UserActivity.launch(
info.threadId context,
) it,
StringUtil.getAvatarUrl(info.author.userPortrait)
) )
}) {
Text(text = stringResource(id = R.string.title_collect_on))
} }
}, },
onClick = { 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( private fun StoreItem(
info: ThreadStoreBean.ThreadStoreInfo, info: ThreadStoreBean.ThreadStoreInfo,
onUserClick: () -> Unit, onUserClick: () -> Unit,
onDelete: () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
textMeasurer: TextMeasurer = rememberTextMeasurer()
) { ) {
val hasUpdate = info.count != "0" && info.postNo != "0" val hasUpdate = remember(info) { info.count != "0" && info.postNo != "0" }
var width = 0 val isDeleted = remember(info) { info.isDeleted == "1" }
var height = 0 val textMeasurer = rememberTextMeasurer()
Column( LongClickMenu(
modifier = modifier menuContent = {
.padding(16.dp), DropdownMenuItem(onClick = onDelete) {
verticalArrangement = Arrangement.spacedBy(8.dp), Text(text = stringResource(id = R.string.title_collect_on))
}
},
onClick = onClick
) { ) {
UserHeader( Column(
avatar = { modifier = modifier
Avatar( .padding(16.dp),
data = StringUtil.getAvatarUrl(info.author.userPortrait), verticalArrangement = Arrangement.spacedBy(8.dp),
size = Sizes.Small, ) {
contentDescription = null UserHeader(
) avatar = {
}, Avatar(
name = { data = StringUtil.getAvatarUrl(info.author.userPortrait),
Text( size = Sizes.Small,
text = getUsernameAnnotatedString( contentDescription = null
LocalContext.current,
info.author.name ?: "",
info.author.nameShow,
LocalContentColor.current
) )
) },
}, name = {
onClick = onUserClick, Text(
) text = getUsernameAnnotatedString(
val title = remember(info, hasUpdate) { LocalContext.current,
buildAnnotatedString { info.author.name ?: "",
append(info.title) info.author.nameShow,
if (hasUpdate) { LocalContentColor.current
append(" ") )
appendInlineContent("Update", info.postNo) )
},
onClick = onUserClick,
)
val title = remember(info, hasUpdate) {
buildAnnotatedString {
append(info.title)
if (hasUpdate) {
append(" ")
appendInlineContent("Update", info.postNo)
}
} }
} }
} val updateTip = stringResource(
val updateTip = stringResource( id = R.string.tip_thread_store_update,
id = R.string.tip_thread_store_update, info.postNo
info.postNo
)
if (hasUpdate) {
val result = textMeasurer.measure(
AnnotatedString(updateTip),
style = UpdateTipTextStyle
) )
width = val result = remember {
result.size.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1 textMeasurer.measure(
height = result.size.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2 AnnotatedString(updateTip),
} style = UpdateTipTextStyle
Text( ).size
text = title, }
fontSize = 15.sp, val width = result.width.pxToSp() + 12F.dpToPxFloat().pxToSp() * 2 + 1
color = ExtendedTheme.colors.text, val height = result.height.pxToSp() + 4F.dpToPxFloat().pxToSp() * 2
inlineContent = mapOf( Text(
"Update" to InlineTextContent( text = title,
placeholder = Placeholder( fontSize = 15.sp,
width = width.sp, color = if (isDeleted) ExtendedTheme.colors.textDisabled else ExtendedTheme.colors.text,
height = height.sp, inlineContent = mapOf(
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter "Update" to InlineTextContent(
), placeholder = Placeholder(
children = { width = width.sp,
Box( height = height.sp,
modifier = Modifier placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
.fillMaxSize() ),
.background( children = {
color = ExtendedTheme.colors.chip, Box(
shape = RoundedCornerShape(3.dp) 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
)
}
}
} }
} }

View File

@ -110,12 +110,13 @@ fun ClickMenu(
fun LongClickMenu( fun LongClickMenu(
menuContent: @Composable (ColumnScope.() -> Unit), menuContent: @Composable (ColumnScope.() -> Unit),
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
enabled: Boolean = true,
menuState: MenuState = rememberMenuState(), menuState: MenuState = rememberMenuState(),
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
shape: Shape = RoundedCornerShape(14.dp), shape: Shape = RoundedCornerShape(14.dp),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication? = LocalIndication.current, indication: Indication? = LocalIndication.current,
content: @Composable () -> Unit content: @Composable () -> Unit,
) { ) {
LaunchedEffect(key1 = null) { LaunchedEffect(key1 = null) {
launch { launch {
@ -138,6 +139,7 @@ fun LongClickMenu(
.combinedClickable( .combinedClickable(
interactionSource = interactionSource, interactionSource = interactionSource,
indication = indication, indication = indication,
enabled = enabled,
onLongClick = { onLongClick = {
menuState.expanded = true menuState.expanded = true
} }

View File

@ -708,4 +708,5 @@
<string name="btn_open_origin_thread">查看原贴</string> <string name="btn_open_origin_thread">查看原贴</string>
<string name="tip_blocked_thread">由于你的屏蔽设置,该贴已被屏蔽</string> <string name="tip_blocked_thread">由于你的屏蔽设置,该贴已被屏蔽</string>
<string name="desc_picture">图片</string> <string name="desc_picture">图片</string>
<string name="tip_thread_store_deleted">该贴已被删除</string>
</resources> </resources>