From 0af0f745bf591818873d28137d2c0e1b77b9b2c1 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Wed, 31 Jul 2024 14:57:44 -0400 Subject: [PATCH] Fixes the need for main thread note loading for galleries --- .../ui/screen/loggedIn/ProfileGallery.kt | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt index 00187f905..1eb43142a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt @@ -54,11 +54,12 @@ import com.vitorpamplona.amethyst.commons.richtext.BaseMediaContent import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVideoUrl -import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled import com.vitorpamplona.amethyst.ui.components.GalleryContentView +import com.vitorpamplona.amethyst.ui.components.LoadNote import com.vitorpamplona.amethyst.ui.components.SensitivityWarning +import com.vitorpamplona.amethyst.ui.components.mockAccountViewModel import com.vitorpamplona.amethyst.ui.note.CheckHiddenFeedWatchBlockAndReport import com.vitorpamplona.amethyst.ui.note.ClickableNote import com.vitorpamplona.amethyst.ui.note.LongPressToQuickActionGallery @@ -130,7 +131,12 @@ private fun GalleryFeedLoaded( state = listState, ) { itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item -> - val defaultModifier = remember { Modifier.fillMaxWidth().animateItemPlacement() } + val defaultModifier = + remember { + Modifier + .fillMaxWidth() + .animateItemPlacement() + } Row(defaultModifier) { GalleryCardCompose( @@ -169,29 +175,21 @@ fun GalleryCardCompose( nav = nav, ) { canPreview -> - // TODO Vitor, this works, but maybe you know of a better way to run this here in the background - // as LocalCache.checkGetOrCreateNote(it) can not run on the main thread - var note: Note? = null - val thread = - Thread { - note = (baseNote.event as ProfileGalleryEntryEvent).event()?.let { LocalCache.checkGetOrCreateNote(it) } - } - thread.start() - thread.join() - // TODO End - - val image = (baseNote.event as ProfileGalleryEntryEvent).url() - if (image != null) { - note?.let { - GalleryCard( - galleryNote = baseNote, - baseNote = it, - image = image, - modifier = modifier, - parentBackgroundColor = parentBackgroundColor, - accountViewModel = accountViewModel, - nav = nav, - ) + (baseNote.event as ProfileGalleryEntryEvent).event()?.let { + LoadNote(baseNoteHex = it, accountViewModel = accountViewModel) { note -> + note?.let { + (baseNote.event as ProfileGalleryEntryEvent).url()?.let { image -> + GalleryCard( + galleryNote = baseNote, + baseNote = it, + image = image, + modifier = modifier, + parentBackgroundColor = parentBackgroundColor, + accountViewModel = accountViewModel, + nav = nav, + ) + } + } } } } @@ -309,7 +307,9 @@ fun RenderGalleryThumb( @Preview @Composable -fun RenderGalleryThumbPreview(accountViewModel: AccountViewModel) { +fun RenderGalleryThumbPreview() { + val accountViewModel = mockAccountViewModel() + Surface(Modifier.size(200.dp)) { InnerRenderGalleryThumb( card =