Prevent IndexOutOfBounds exception when media is deleted.

This commit is contained in:
Nicholas Tinsley 2024-08-27 09:05:50 -04:00
parent 1f196f74ff
commit ff47f784a3

View file

@ -210,7 +210,7 @@ class MediaPreviewV2Fragment : LoggingFragment(R.layout.fragment_media_preview_v
}
private fun bindCurrentState(currentState: MediaPreviewV2State) {
if (currentState.position == -1 && currentState.mediaRecords.isEmpty()) {
if (currentState.position < 0 && currentState.mediaRecords.isEmpty()) {
onMediaNotAvailable()
return
}
@ -225,7 +225,7 @@ class MediaPreviewV2Fragment : LoggingFragment(R.layout.fragment_media_preview_v
val currentPosition = currentState.position
val backingItems = currentState.mediaRecords.mapNotNull { it.attachment }
if (backingItems.isEmpty()) {
if (backingItems.isEmpty() || currentPosition < 0) {
onMediaNotAvailable()
return
}
@ -242,7 +242,7 @@ class MediaPreviewV2Fragment : LoggingFragment(R.layout.fragment_media_preview_v
* {@link OnPageChangeCallback}.
*/
private fun bindMediaReadyState(currentState: MediaPreviewV2State) {
if (currentState.mediaRecords.isEmpty()) {
if (currentState.mediaRecords.isEmpty() || currentState.position < 0) {
onMediaNotAvailable()
return
}