Holds the state of expanded text button between edits and translations.

This commit is contained in:
Vitor Pamplona
2024-03-06 14:25:19 -05:00
parent 5f76cdf721
commit 2038994613
20 changed files with 40 additions and 5 deletions
@@ -68,6 +68,7 @@ fun NotifyRequestDialog(
Modifier.fillMaxWidth(),
EmptyTagList,
background,
textContent,
accountViewModel,
nav,
)
@@ -20,6 +20,7 @@
*/
package com.vitorpamplona.amethyst.ui.components
import android.util.LruCache
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -51,6 +52,10 @@ import com.vitorpamplona.amethyst.ui.theme.ButtonPadding
import com.vitorpamplona.amethyst.ui.theme.secondaryButtonBackground
import com.vitorpamplona.quartz.events.ImmutableListOfLists
object ShowFullTextCache {
val cache = LruCache<String, Boolean>(20)
}
@Composable
fun ExpandableRichTextViewer(
content: String,
@@ -58,10 +63,11 @@ fun ExpandableRichTextViewer(
modifier: Modifier,
tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>,
id: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
var showFullText by remember { mutableStateOf(false) }
var showFullText by remember { mutableStateOf(ShowFullTextCache.cache[id] ?: false) }
val whereToCut = remember(content) { ExpandableTextCutOffCalculator.indexToCutOff(content) }
@@ -96,7 +102,10 @@ fun ExpandableRichTextViewer(
.fillMaxWidth()
.background(getGradient(backgroundColor)),
) {
ShowMoreButton { showFullText = !showFullText }
ShowMoreButton {
showFullText = !showFullText
ShowFullTextCache.cache.put(id, showFullText)
}
}
}
}
@@ -641,6 +641,7 @@ private fun RenderRegularTextNote(
modifier = HalfTopPadding,
tags = tags,
backgroundColor = backgroundBubbleColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -652,6 +653,7 @@ private fun RenderRegularTextNote(
modifier = HalfTopPadding,
tags = EmptyTagList,
backgroundColor = backgroundBubbleColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -474,6 +474,7 @@ fun CrossfadeToDisplayComment(
tags = EmptyTagList,
modifier = textBoxModifier,
backgroundColor = backgroundColor,
id = comment,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -274,6 +274,7 @@ private fun RenderOptionAfterVote(
Modifier,
tags,
backgroundColor,
poolOption.descriptor,
accountViewModel,
nav,
)
@@ -307,6 +308,7 @@ private fun RenderOptionBeforeVote(
remember { Modifier.padding(15.dp) },
tags,
backgroundColor,
id = description,
accountViewModel,
nav,
)
@@ -234,6 +234,7 @@ fun RenderAppDefinition(
canPreview = false,
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -218,6 +218,7 @@ fun AudioHeader(
canPreview = true,
tags = tags,
backgroundColor = background,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -182,6 +182,7 @@ fun LongCommunityHeader(
canPreview = false,
tags = EmptyTagList,
backgroundColor = background,
id = baseNote.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -189,9 +190,9 @@ fun LongCommunityHeader(
if (summary != null && noteEvent.hasHashtags()) {
DisplayUncitedHashtags(
remember(noteEvent) { noteEvent.hashtags().toImmutableList() },
summary ?: "",
nav,
hashtags = remember(key1 = noteEvent) { noteEvent.hashtags().toImmutableList() },
eventContent = summary,
nav = nav,
)
}
}
@@ -183,6 +183,7 @@ private fun RenderGitPatchEvent(
modifier = modifier,
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -281,6 +282,7 @@ private fun RenderGitIssueEvent(
modifier = modifier,
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -107,6 +107,7 @@ fun DisplayHighlight(
remember { Modifier.fillMaxWidth() },
EmptyTagList,
backgroundColor,
id = quote,
accountViewModel,
nav,
)
@@ -107,6 +107,7 @@ fun RenderPinListEvent(
canPreview = true,
tags = EmptyTagList,
backgroundColor = backgroundColor,
id = baseNote.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -73,6 +73,7 @@ fun RenderPoll(
modifier = remember { Modifier.fillMaxWidth() },
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -84,6 +84,7 @@ fun RenderPrivateMessage(
modifier = modifier,
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -111,6 +112,7 @@ fun RenderPrivateMessage(
Modifier.fillMaxWidth(),
EmptyTagList,
backgroundColor,
id = note.idHex,
accountViewModel,
nav,
)
@@ -80,6 +80,7 @@ fun RenderReport(
modifier = Modifier,
tags = EmptyTagList,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -106,6 +106,7 @@ fun RenderTextEvent(
modifier = modifier,
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -116,6 +116,7 @@ fun RenderTextModificationEvent(
modifier = Modifier.fillMaxWidth(),
tags = EmptyTagList,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -166,6 +166,7 @@ fun VideoDisplay(
modifier = Modifier.fillMaxWidth(),
tags = tags,
backgroundColor = backgroundColor,
id = note.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -811,6 +811,7 @@ fun LongChannelHeader(
canPreview = false,
tags = tags,
backgroundColor = background,
id = baseChannel.idHex,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -1103,6 +1103,7 @@ private fun DrawAdditionalInfo(
canPreview = false,
tags = EmptyTagList,
backgroundColor = background,
id = it,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -74,6 +74,7 @@ fun TranslatableRichTextViewer(
modifier: Modifier = Modifier,
tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>,
id: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
@@ -98,6 +99,7 @@ fun TranslatableRichTextViewer(
modifier,
tags,
backgroundColor,
id,
accountViewModel,
nav,
)
@@ -112,6 +114,7 @@ private fun RenderText(
modifier: Modifier,
tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>,
id: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
@@ -130,6 +133,7 @@ private fun RenderText(
modifier,
tags,
backgroundColor,
id,
accountViewModel,
nav,
)