Skip to content

Commit 0ea53d9

Browse files
committed
Fix gallery not always showing the right item once it's clicked
1 parent d22d3c1 commit 0ea53d9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/src/main/kotlin/com/darkrockstudios/app/securecamera/viewphoto/ViewPhotoViewModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ class ViewPhotoViewModel(
3939
val initialIndex = mediaItems.indexOfFirst { it.mediaName == initialMediaName }
4040
val initialMedia = mediaItems.getOrNull(initialIndex)
4141

42+
// Set mediaItems and currentIndex so they're available immediately
43+
_uiState.update {
44+
it.copy(
45+
mediaItems = mediaItems,
46+
currentIndex = if (initialIndex >= 0) initialIndex else 0,
47+
)
48+
}
49+
4250
viewModelScope.launch {
4351
val hasPoisonPill = pinRepository.hasPoisonPillPin()
4452
val isDecoy = (initialMedia as? PhotoDef)?.let { imageManager.isDecoyPhoto(it) } ?: false
4553

4654
_uiState.update {
4755
it.copy(
48-
mediaItems = mediaItems,
49-
currentIndex = if (initialIndex >= 0) initialIndex else 0,
5056
hasPoisonPill = hasPoisonPill,
5157
isDecoy = isDecoy
5258
)

0 commit comments

Comments
 (0)