massive speed up of rendering the gallery
This commit is contained in:
@@ -139,8 +139,6 @@ open class Note(
|
|||||||
var relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
var relays = listOf<RelayBriefInfoCache.RelayBriefInfo>()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var associatedNote: Note? = null
|
|
||||||
|
|
||||||
var lastReactionsDownloadTime: Map<String, EOSETime> = emptyMap()
|
var lastReactionsDownloadTime: Map<String, EOSETime> = emptyMap()
|
||||||
|
|
||||||
fun id() = Hex.decode(idHex)
|
fun id() = Hex.decode(idHex)
|
||||||
|
|||||||
+1
-10
@@ -47,16 +47,7 @@ class UserProfileGalleryFeedFilter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sorted = sort(notes)
|
var sorted = sort(notes)
|
||||||
var finalnotes = setOf<Note>()
|
return sorted.toList()
|
||||||
for (item in sorted) {
|
|
||||||
val note = (item.event as ProfileGalleryEntryEvent).event()?.let { LocalCache.checkGetOrCreateNote(it) }
|
|
||||||
if (note != null) {
|
|
||||||
note.associatedNote = item
|
|
||||||
finalnotes = finalnotes + note
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return finalnotes.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyFilter(collection: Set<Note>): Set<Note> = innerApplyFilter(collection)
|
override fun applyFilter(collection: Set<Note>): Set<Note> = innerApplyFilter(collection)
|
||||||
|
|||||||
+26
-21
@@ -54,6 +54,7 @@ import com.vitorpamplona.amethyst.commons.richtext.BaseMediaContent
|
|||||||
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage
|
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage
|
||||||
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo
|
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlVideo
|
||||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser.Companion.isVideoUrl
|
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.model.Note
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
|
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
|
||||||
import com.vitorpamplona.amethyst.ui.components.GalleryContentView
|
import com.vitorpamplona.amethyst.ui.components.GalleryContentView
|
||||||
@@ -80,7 +81,6 @@ import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent
|
|||||||
fun RenderGalleryFeed(
|
fun RenderGalleryFeed(
|
||||||
viewModel: FeedViewModel,
|
viewModel: FeedViewModel,
|
||||||
routeForLastRead: String?,
|
routeForLastRead: String?,
|
||||||
forceEventKind: Int?,
|
|
||||||
listState: LazyGridState,
|
listState: LazyGridState,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
@@ -104,7 +104,6 @@ fun RenderGalleryFeed(
|
|||||||
state,
|
state,
|
||||||
routeForLastRead,
|
routeForLastRead,
|
||||||
listState,
|
listState,
|
||||||
forceEventKind,
|
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
@@ -122,7 +121,6 @@ private fun GalleryFeedLoaded(
|
|||||||
state: FeedState.Loaded,
|
state: FeedState.Loaded,
|
||||||
routeForLastRead: String?,
|
routeForLastRead: String?,
|
||||||
listState: LazyGridState,
|
listState: LazyGridState,
|
||||||
forceEventKind: Int?,
|
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -139,7 +137,6 @@ private fun GalleryFeedLoaded(
|
|||||||
baseNote = item,
|
baseNote = item,
|
||||||
routeForLastRead = routeForLastRead,
|
routeForLastRead = routeForLastRead,
|
||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
forceEventKind = forceEventKind,
|
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
)
|
)
|
||||||
@@ -158,7 +155,6 @@ fun GalleryCardCompose(
|
|||||||
routeForLastRead: String? = null,
|
routeForLastRead: String? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
parentBackgroundColor: MutableState<Color>? = null,
|
parentBackgroundColor: MutableState<Color>? = null,
|
||||||
forceEventKind: Int?,
|
|
||||||
isHiddenFeed: Boolean = false,
|
isHiddenFeed: Boolean = false,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
@@ -173,13 +169,23 @@ fun GalleryCardCompose(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
) { canPreview ->
|
) { canPreview ->
|
||||||
|
|
||||||
if (baseNote.associatedNote != null) {
|
// TODO Vitor, this works, but maybe you know of a better way to run this here in the background
|
||||||
if (baseNote.associatedNote!!.event != null) {
|
// as LocalCache.checkGetOrCreateNote(it) can not run on the main thread
|
||||||
val image = (baseNote.associatedNote!!.event as ProfileGalleryEntryEvent).url()
|
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) {
|
if (image != null) {
|
||||||
|
note?.let {
|
||||||
GalleryCard(
|
GalleryCard(
|
||||||
galleryNote = baseNote.associatedNote!!,
|
galleryNote = baseNote,
|
||||||
baseNote = baseNote,
|
baseNote = it,
|
||||||
image = image,
|
image = image,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
parentBackgroundColor = parentBackgroundColor,
|
parentBackgroundColor = parentBackgroundColor,
|
||||||
@@ -191,7 +197,6 @@ fun GalleryCardCompose(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GalleryCard(
|
fun GalleryCard(
|
||||||
@@ -207,6 +212,7 @@ fun GalleryCard(
|
|||||||
LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
|
LongPressToQuickActionGallery(baseNote = galleryNote, accountViewModel = accountViewModel) { showPopup ->
|
||||||
CheckNewAndRenderChannelCard(
|
CheckNewAndRenderChannelCard(
|
||||||
baseNote,
|
baseNote,
|
||||||
|
galleryNote,
|
||||||
image,
|
image,
|
||||||
modifier,
|
modifier,
|
||||||
parentBackgroundColor,
|
parentBackgroundColor,
|
||||||
@@ -220,6 +226,7 @@ fun GalleryCard(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun CheckNewAndRenderChannelCard(
|
private fun CheckNewAndRenderChannelCard(
|
||||||
baseNote: Note,
|
baseNote: Note,
|
||||||
|
galleryNote: Note,
|
||||||
image: String,
|
image: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
parentBackgroundColor: MutableState<Color>? = null,
|
parentBackgroundColor: MutableState<Color>? = null,
|
||||||
@@ -233,6 +240,7 @@ private fun CheckNewAndRenderChannelCard(
|
|||||||
parentBackgroundColor = parentBackgroundColor,
|
parentBackgroundColor = parentBackgroundColor,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
|
println("NOTE:" + (baseNote.event?.id() ?: "nah"))
|
||||||
|
|
||||||
ClickableNote(
|
ClickableNote(
|
||||||
baseNote = baseNote,
|
baseNote = baseNote,
|
||||||
@@ -242,7 +250,7 @@ private fun CheckNewAndRenderChannelCard(
|
|||||||
showPopup = showPopup,
|
showPopup = showPopup,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
) {
|
) {
|
||||||
InnerGalleryCardBox(baseNote, image, accountViewModel, nav)
|
InnerGalleryCardBox(galleryNote, image, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +276,6 @@ data class GalleryThumb(
|
|||||||
val id: String?,
|
val id: String?,
|
||||||
val image: String?,
|
val image: String?,
|
||||||
val title: String?,
|
val title: String?,
|
||||||
// val price: Price?,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -288,7 +295,6 @@ fun RenderGalleryThumb(
|
|||||||
image = image,
|
image = image,
|
||||||
title = "",
|
title = "",
|
||||||
// noteEvent?.title(),
|
// noteEvent?.title(),
|
||||||
// price = noteEvent?.price(),
|
|
||||||
)
|
)
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
.observeAsState(
|
.observeAsState(
|
||||||
@@ -299,7 +305,7 @@ fun RenderGalleryThumb(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
InnerRenderGalleryThumb(card as GalleryThumb, baseNote, accountViewModel)
|
InnerRenderGalleryThumb(card, baseNote, accountViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@@ -312,7 +318,6 @@ fun RenderGalleryThumbPreview(accountViewModel: AccountViewModel) {
|
|||||||
id = "",
|
id = "",
|
||||||
image = null,
|
image = null,
|
||||||
title = "Like New",
|
title = "Like New",
|
||||||
// price = Price("800000", "SATS", null),
|
|
||||||
),
|
),
|
||||||
note = Note("hex"),
|
note = Note("hex"),
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
@@ -333,11 +338,11 @@ fun InnerRenderGalleryThumb(
|
|||||||
contentAlignment = BottomStart,
|
contentAlignment = BottomStart,
|
||||||
) {
|
) {
|
||||||
card.image?.let {
|
card.image?.let {
|
||||||
var blurHash = (note.associatedNote?.event as ProfileGalleryEntryEvent).blurhash()
|
var blurHash = (note.event as ProfileGalleryEntryEvent).blurhash()
|
||||||
var description = (note.associatedNote?.event as ProfileGalleryEntryEvent).content
|
var description = (note.event as ProfileGalleryEntryEvent).content
|
||||||
// var hash = (note.associatedNote?.event as ProfileGalleryEntryEvent).hash()
|
// var hash = (note.event as ProfileGalleryEntryEvent).hash()
|
||||||
var dimensions = (note.associatedNote?.event as ProfileGalleryEntryEvent).dimensions()
|
var dimensions = (note.event as ProfileGalleryEntryEvent).dimensions()
|
||||||
var mimeType = (note.associatedNote?.event as ProfileGalleryEntryEvent).mimeType()
|
var mimeType = (note.event as ProfileGalleryEntryEvent).mimeType()
|
||||||
var content: BaseMediaContent? = null
|
var content: BaseMediaContent? = null
|
||||||
|
|
||||||
if (isVideoUrl(it)) {
|
if (isVideoUrl(it)) {
|
||||||
|
|||||||
@@ -1574,7 +1574,6 @@ fun TabGallery(
|
|||||||
RenderGalleryFeed(
|
RenderGalleryFeed(
|
||||||
feedViewModel,
|
feedViewModel,
|
||||||
null,
|
null,
|
||||||
0,
|
|
||||||
listState,
|
listState,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
|
|||||||
Reference in New Issue
Block a user