mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-10 12:59:51 +02:00
Optimizing the performance of Highlight rendering
This commit is contained in:
parent
e40cd8d932
commit
99270662ee
@ -40,8 +40,6 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.lifecycle.distinctUntilChanged
|
||||
import androidx.lifecycle.map
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
||||
@ -67,16 +65,13 @@ fun RenderHighlight(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val quote = remember { (note.event as? HighlightEvent)?.quote() ?: "" }
|
||||
val author = remember { (note.event as? HighlightEvent)?.author() }
|
||||
val url = remember { (note.event as? HighlightEvent)?.inUrl() }
|
||||
val postHex = remember { (note.event as? HighlightEvent)?.taggedAddresses()?.firstOrNull() }
|
||||
val noteEvent = note.event as? HighlightEvent ?: return
|
||||
|
||||
DisplayHighlight(
|
||||
highlight = quote,
|
||||
authorHex = author,
|
||||
url = url,
|
||||
postAddress = postHex,
|
||||
highlight = noteEvent.quote(),
|
||||
authorHex = noteEvent.author(),
|
||||
url = noteEvent.inUrl(),
|
||||
postAddress = noteEvent.inPost(),
|
||||
makeItShort = makeItShort,
|
||||
canPreview = canPreview,
|
||||
quotesLeft = quotesLeft,
|
||||
@ -175,7 +170,7 @@ fun LoadAndDisplayUrl(url: String) {
|
||||
}
|
||||
|
||||
validatedUrl?.host?.let { host ->
|
||||
Text(remember { "-" }, maxLines = 1)
|
||||
Text("-", maxLines = 1)
|
||||
ClickableUrl(urlText = host, url = url)
|
||||
}
|
||||
}
|
||||
@ -186,17 +181,15 @@ private fun LoadAndDisplayPost(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
LoadAddressableNote(aTag = postAddress, accountViewModel) {
|
||||
it?.let { note ->
|
||||
val noteEvent by
|
||||
note.live().metadata.map { it.note.event }.distinctUntilChanged().observeAsState(note.event)
|
||||
LoadAddressableNote(aTag = postAddress, accountViewModel) { aTag ->
|
||||
aTag?.let { note ->
|
||||
val noteState by note.live().metadata.observeAsState()
|
||||
val noteEvent = noteState?.note?.event as? LongTextNoteEvent ?: return@LoadAddressableNote
|
||||
|
||||
val title = remember(noteEvent) { (noteEvent as? LongTextNoteEvent)?.title() }
|
||||
|
||||
title?.let {
|
||||
Text(remember { "-" }, maxLines = 1)
|
||||
noteEvent.title()?.let {
|
||||
Text("-", maxLines = 1)
|
||||
ClickableText(
|
||||
text = AnnotatedString(title),
|
||||
text = AnnotatedString(it),
|
||||
onClick = { routeFor(note, accountViewModel.userProfile())?.let { nav(it) } },
|
||||
style = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary),
|
||||
)
|
||||
|
@ -34,13 +34,13 @@ class HighlightEvent(
|
||||
content: String,
|
||||
sig: HexKey,
|
||||
) : BaseTextNoteEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
fun inUrl() = taggedUrls().firstOrNull()
|
||||
fun inUrl() = firstTaggedUrl()
|
||||
|
||||
fun author() = taggedUsers().firstOrNull()
|
||||
fun author() = firstTaggedUser()
|
||||
|
||||
fun quote() = content
|
||||
|
||||
fun inPost() = taggedAddresses().firstOrNull()
|
||||
fun inPost() = firstTaggedAddress()
|
||||
|
||||
companion object {
|
||||
const val KIND = 9802
|
||||
|
Loading…
x
Reference in New Issue
Block a user