From 203899461306420819b6810a962cc637697b7611 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 6 Mar 2024 14:25:19 -0500 Subject: [PATCH] Holds the state of expanded text button between edits and translations. --- .../amethyst/ui/actions/NotifyRequestDialog.kt | 1 + .../ui/components/ExpandableRichTextViewer.kt | 13 +++++++++++-- .../amethyst/ui/note/ChatroomMessageCompose.kt | 2 ++ .../amethyst/ui/note/MultiSetCompose.kt | 1 + .../com/vitorpamplona/amethyst/ui/note/PollNote.kt | 2 ++ .../amethyst/ui/note/types/AppDefinition.kt | 1 + .../amethyst/ui/note/types/AudioTrack.kt | 1 + .../amethyst/ui/note/types/CommunityHeader.kt | 7 ++++--- .../com/vitorpamplona/amethyst/ui/note/types/Git.kt | 2 ++ .../amethyst/ui/note/types/Highlight.kt | 1 + .../vitorpamplona/amethyst/ui/note/types/PinList.kt | 1 + .../vitorpamplona/amethyst/ui/note/types/Poll.kt | 1 + .../amethyst/ui/note/types/PrivateMessage.kt | 2 ++ .../vitorpamplona/amethyst/ui/note/types/Report.kt | 1 + .../vitorpamplona/amethyst/ui/note/types/Text.kt | 1 + .../amethyst/ui/note/types/TextModification.kt | 1 + .../vitorpamplona/amethyst/ui/note/types/Video.kt | 1 + .../amethyst/ui/screen/loggedIn/ChannelScreen.kt | 1 + .../amethyst/ui/screen/loggedIn/ProfileScreen.kt | 1 + .../ui/components/TranslatableRichTextViewer.kt | 4 ++++ 20 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NotifyRequestDialog.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NotifyRequestDialog.kt index c19d7531c..672e7acb8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NotifyRequestDialog.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NotifyRequestDialog.kt @@ -68,6 +68,7 @@ fun NotifyRequestDialog( Modifier.fillMaxWidth(), EmptyTagList, background, + textContent, accountViewModel, nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt index 477e7ac2b..5a48184a2 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt @@ -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(20) +} + @Composable fun ExpandableRichTextViewer( content: String, @@ -58,10 +63,11 @@ fun ExpandableRichTextViewer( modifier: Modifier, tags: ImmutableListOfLists, backgroundColor: MutableState, + 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) + } } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChatroomMessageCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChatroomMessageCompose.kt index 4d647c181..38ce86483 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChatroomMessageCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/ChatroomMessageCompose.kt @@ -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, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt index 5a25e557e..b36e64c93 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/MultiSetCompose.kt @@ -474,6 +474,7 @@ fun CrossfadeToDisplayComment( tags = EmptyTagList, modifier = textBoxModifier, backgroundColor = backgroundColor, + id = comment, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt index e17404ba2..5b3d75f7c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/PollNote.kt @@ -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, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt index 607354e1b..fcffd450b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AppDefinition.kt @@ -234,6 +234,7 @@ fun RenderAppDefinition( canPreview = false, tags = tags, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AudioTrack.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AudioTrack.kt index 3a70d2d6b..78f442277 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AudioTrack.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/AudioTrack.kt @@ -218,6 +218,7 @@ fun AudioHeader( canPreview = true, tags = tags, backgroundColor = background, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt index 3dcf3a8cb..d3d29c557 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt @@ -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, ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Git.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Git.kt index bdf0986d1..9be1ef012 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Git.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Git.kt @@ -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, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt index 7fe5f703b..db227ced8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt @@ -107,6 +107,7 @@ fun DisplayHighlight( remember { Modifier.fillMaxWidth() }, EmptyTagList, backgroundColor, + id = quote, accountViewModel, nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PinList.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PinList.kt index b5261a7dd..4ab4876bb 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PinList.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PinList.kt @@ -107,6 +107,7 @@ fun RenderPinListEvent( canPreview = true, tags = EmptyTagList, backgroundColor = backgroundColor, + id = baseNote.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Poll.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Poll.kt index 2dfc1ed79..f9bd72547 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Poll.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Poll.kt @@ -73,6 +73,7 @@ fun RenderPoll( modifier = remember { Modifier.fillMaxWidth() }, tags = tags, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PrivateMessage.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PrivateMessage.kt index 537a9ee6d..84fbc70de 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PrivateMessage.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/PrivateMessage.kt @@ -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, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Report.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Report.kt index 50902b48d..7075af94c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Report.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Report.kt @@ -80,6 +80,7 @@ fun RenderReport( modifier = Modifier, tags = EmptyTagList, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Text.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Text.kt index cfea566bf..538e4f6a3 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Text.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Text.kt @@ -106,6 +106,7 @@ fun RenderTextEvent( modifier = modifier, tags = tags, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/TextModification.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/TextModification.kt index 41412de94..2920ae174 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/TextModification.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/TextModification.kt @@ -116,6 +116,7 @@ fun RenderTextModificationEvent( modifier = Modifier.fillMaxWidth(), tags = EmptyTagList, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Video.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Video.kt index e82869266..4e532de82 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Video.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Video.kt @@ -166,6 +166,7 @@ fun VideoDisplay( modifier = Modifier.fillMaxWidth(), tags = tags, backgroundColor = backgroundColor, + id = note.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt index 5f9b58238..7286cfc0b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ChannelScreen.kt @@ -811,6 +811,7 @@ fun LongChannelHeader( canPreview = false, tags = tags, backgroundColor = background, + id = baseChannel.idHex, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index d12f2de31..f1b118ed1 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -1103,6 +1103,7 @@ private fun DrawAdditionalInfo( canPreview = false, tags = EmptyTagList, backgroundColor = background, + id = it, accountViewModel = accountViewModel, nav = nav, ) diff --git a/app/src/play/java/com/vitorpamplona/amethyst/ui/components/TranslatableRichTextViewer.kt b/app/src/play/java/com/vitorpamplona/amethyst/ui/components/TranslatableRichTextViewer.kt index 5c1111c69..cff6738d5 100644 --- a/app/src/play/java/com/vitorpamplona/amethyst/ui/components/TranslatableRichTextViewer.kt +++ b/app/src/play/java/com/vitorpamplona/amethyst/ui/components/TranslatableRichTextViewer.kt @@ -74,6 +74,7 @@ fun TranslatableRichTextViewer( modifier: Modifier = Modifier, tags: ImmutableListOfLists, backgroundColor: MutableState, + 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, backgroundColor: MutableState, + id: String, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -130,6 +133,7 @@ private fun RenderText( modifier, tags, backgroundColor, + id, accountViewModel, nav, )