Browse Source

Keep selected Android originals while the catalog finishes loading

master
evgeny 5 days ago
parent
commit
5b4b17ae49
  1. 24
      tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/AvatarViewerScreen.kt

24
tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/AvatarViewerScreen.kt

@ -42,19 +42,19 @@ fun AvatarViewerScreen(group: String?, owner: Long, name: String, onClose: () ->
LaunchedEffect(account,revision) { if (account==0L) onClose() }
LaunchedEffect(source?.first,source?.second?.avatarServer,source?.second?.avatarFile,retry) {
val (channel,member)=source ?: return@LaunchedEffect
files=listOf(member.avatarFile); if (selected !in files) selected=member.avatarFile
if (selected.isEmpty()) selected=member.avatarFile
if (files.isEmpty()) files=listOf(member.avatarFile)
catalogFailed=false
try { files=repository.catalog(channel,member) }
try { files=repository.catalog(channel,member); if (selected !in files) selected=member.avatarFile }
catch (e: CancellationException) { throw e }
catch (e: Exception) { catalogFailed=true; LogManager.addLog("WARN","Avatar","Catalog failed owner=$owner: ${e.message}") }
}
val index=files.indexOf(selected)
LaunchedEffect(source?.first,source?.second?.avatarServer,selected,files,retry) {
val visible=if (index<0) emptyList() else files.subList((index-2).coerceAtLeast(0),(index+3).coerceAtMost(files.size))
LaunchedEffect(source?.first,source?.second?.avatarServer,selected,retry) {
original=null; failed=false
val (channel,member)=source ?: return@LaunchedEffect
if (index<0) return@LaunchedEffect
val visible=files.subList((index-2).coerceAtLeast(0),(index+3).coerceAtMost(files.size))
previews=previews.filterKeys { it in visible }
coroutineScope {
launch {
try { previews=previews+(selected to repository.loadAvatar(channel,member.copy(avatarFile=selected),false)) }
@ -66,13 +66,17 @@ fun AvatarViewerScreen(group: String?, owner: Long, name: String, onClose: () ->
catch (e: CancellationException) { throw e }
catch (e: Exception) { failed=true; LogManager.addLog("WARN","Avatar","Original failed file=$selected: ${e.message}") }
}
visible.filter { it!=selected && it !in previews }.forEach { file -> launch {
try { previews=previews+(file to repository.loadAvatar(channel,member.copy(avatarFile=file),false)) }
catch (e: CancellationException) { throw e }
catch (e: Exception) { LogManager.addLog("WARN","Avatar","Neighbor failed file=$file: ${e.message}") }
} }
}
}
LaunchedEffect(source?.first,source?.second?.avatarServer,visible,retry) {
val (channel,member)=source ?: return@LaunchedEffect
previews=previews.filterKeys { it in visible }
coroutineScope { visible.filter { it!=selected && it !in previews }.forEach { file -> launch {
try { previews=previews+(file to repository.loadAvatar(channel,member.copy(avatarFile=file),false)) }
catch (e: CancellationException) { throw e }
catch (e: Exception) { LogManager.addLog("WARN","Avatar","Neighbor failed file=$file: ${e.message}") }
} } }
}
fun move(delta: Int) { val next=index+delta; if (next in files.indices) selected=files[next] }
Dialog(onDismissRequest=onClose,properties=DialogProperties(usePlatformDefaultWidth=false)) {
Column(Modifier.fillMaxSize().background(Color.Black).systemBarsPadding()) {

Loading…
Cancel
Save