kopia lustrzana https://github.com/vitorpamplona/amethyst
Avoids the animations when loading NIP94 and NIP95 content
rodzic
9d75fb7074
commit
b055e520c2
|
@ -123,6 +123,7 @@ import com.vitorpamplona.amethyst.ui.actions.toImmutableListOfLists
|
||||||
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
||||||
|
import com.vitorpamplona.amethyst.ui.components.LoadNote
|
||||||
import com.vitorpamplona.amethyst.ui.components.LoadThumbAndThenVideoView
|
import com.vitorpamplona.amethyst.ui.components.LoadThumbAndThenVideoView
|
||||||
import com.vitorpamplona.amethyst.ui.components.MeasureSpaceWidth
|
import com.vitorpamplona.amethyst.ui.components.MeasureSpaceWidth
|
||||||
import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status
|
import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status
|
||||||
|
@ -3128,19 +3129,16 @@ fun FileHeaderDisplay(note: Note, accountViewModel: AccountViewModel) {
|
||||||
val event = (note.event as? FileHeaderEvent) ?: return
|
val event = (note.event as? FileHeaderEvent) ?: return
|
||||||
val fullUrl = event.url() ?: return
|
val fullUrl = event.url() ?: return
|
||||||
|
|
||||||
var content by remember { mutableStateOf<ZoomableContent?>(null) }
|
val content by remember(note) {
|
||||||
|
|
||||||
if (content == null) {
|
|
||||||
LaunchedEffect(key1 = event.id) {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
val blurHash = event.blurhash()
|
val blurHash = event.blurhash()
|
||||||
val hash = event.hash()
|
val hash = event.hash()
|
||||||
val dimensions = event.dimensions()
|
val dimensions = event.dimensions()
|
||||||
val description = event.content
|
val description = event.content
|
||||||
val removedParamsFromUrl = fullUrl.split("?")[0].lowercase()
|
val isImage = imageExtensions.any { fullUrl.split("?")[0].lowercase().endsWith(it) }
|
||||||
val isImage = imageExtensions.any { removedParamsFromUrl.endsWith(it) }
|
|
||||||
val uri = note.toNostrUri()
|
val uri = note.toNostrUri()
|
||||||
val newContent = if (isImage) {
|
|
||||||
|
mutableStateOf<ZoomableContent>(
|
||||||
|
if (isImage) {
|
||||||
ZoomableUrlImage(
|
ZoomableUrlImage(
|
||||||
url = fullUrl,
|
url = fullUrl,
|
||||||
description = description,
|
description = description,
|
||||||
|
@ -3159,67 +3157,43 @@ fun FileHeaderDisplay(note: Note, accountViewModel: AccountViewModel) {
|
||||||
authorName = note.author?.toBestDisplayName()
|
authorName = note.author?.toBestDisplayName()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
content = newContent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Crossfade(targetState = content) {
|
|
||||||
if (it != null) {
|
|
||||||
SensitivityWarning(note = note, accountViewModel = accountViewModel) {
|
SensitivityWarning(note = note, accountViewModel = accountViewModel) {
|
||||||
ZoomableContentView(content = it, accountViewModel = accountViewModel)
|
ZoomableContentView(content = content, accountViewModel = accountViewModel)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FileStorageHeaderDisplay(baseNote: Note, accountViewModel: AccountViewModel) {
|
fun FileStorageHeaderDisplay(baseNote: Note, accountViewModel: AccountViewModel) {
|
||||||
val eventHeader = (baseNote.event as? FileStorageHeaderEvent) ?: return
|
val eventHeader = (baseNote.event as? FileStorageHeaderEvent) ?: return
|
||||||
|
val dataEventId = eventHeader.dataEventId() ?: return
|
||||||
|
|
||||||
var fileNote by remember { mutableStateOf<Note?>(null) }
|
LoadNote(baseNoteHex = dataEventId) { contentNote ->
|
||||||
|
if (contentNote != null) {
|
||||||
if (fileNote == null) {
|
ObserverAndRenderNIP95(baseNote, contentNote, accountViewModel)
|
||||||
LaunchedEffect(key1 = eventHeader.id) {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
val newFileNote = eventHeader.dataEventId()?.let { LocalCache.checkGetOrCreateNote(it) }
|
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
fileNote = newFileNote
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Crossfade(targetState = fileNote) {
|
|
||||||
if (it != null) {
|
|
||||||
RenderNIP95(it, eventHeader, baseNote, accountViewModel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RenderNIP95(
|
private fun ObserverAndRenderNIP95(
|
||||||
content: Note,
|
|
||||||
eventHeader: FileStorageHeaderEvent,
|
|
||||||
header: Note,
|
header: Note,
|
||||||
|
content: Note,
|
||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
|
val eventHeader = (header.event as? FileStorageHeaderEvent) ?: return
|
||||||
|
|
||||||
val appContext = LocalContext.current.applicationContext
|
val appContext = LocalContext.current.applicationContext
|
||||||
|
|
||||||
val noteState by content.live().metadata.observeAsState()
|
val noteState by content.live().metadata.observeAsState()
|
||||||
val note = remember(noteState) { noteState?.note }
|
|
||||||
|
|
||||||
var content by remember { mutableStateOf<ZoomableContent?>(null) }
|
val content by remember(noteState) {
|
||||||
|
// Creates a new object when the event arrives to force an update of the image.
|
||||||
if (content == null) {
|
val note = noteState?.note
|
||||||
LaunchedEffect(key1 = eventHeader.id, key2 = noteState, key3 = note?.event) {
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
val uri = header.toNostrUri()
|
val uri = header.toNostrUri()
|
||||||
val localDir =
|
val localDir = note?.idHex?.let { File(File(appContext.externalCacheDir, "NIP95"), it) }
|
||||||
note?.idHex?.let { File(File(appContext.externalCacheDir, "NIP95"), it) }
|
|
||||||
val blurHash = eventHeader.blurhash()
|
val blurHash = eventHeader.blurhash()
|
||||||
val dimensions = eventHeader.dimensions()
|
val dimensions = eventHeader.dimensions()
|
||||||
val description = eventHeader.content
|
val description = eventHeader.content
|
||||||
|
@ -3247,11 +3221,7 @@ private fun RenderNIP95(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.Main) {
|
mutableStateOf<ZoomableContent?>(newContent)
|
||||||
content = newContent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Crossfade(targetState = content) {
|
Crossfade(targetState = content) {
|
||||||
|
|
Ładowanie…
Reference in New Issue