Fix crash on AttachmentViewer (#2365)

Not sure how to reproduce it, but if the value is -1, it will crash for sure
This commit is contained in:
Benoit Marty 2020-11-10 15:12:21 +01:00
parent 816301bf8d
commit 83467b8597
2 changed files with 3 additions and 2 deletions

View File

@ -8,6 +8,7 @@ Improvements 🙌:
- Open an existing DM instead of creating a new one (#2319)
Bugfix 🐛:
- Fix crash on AttachmentViewer (#2365)
- Fix issue when updating the avatar of a room (new avatar vanishing)
- Discard change dialog displayed by mistake when avatar has been updated

View File

@ -119,7 +119,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
val inMemoryData = intent.getParcelableArrayListExtra<AttachmentData>(EXTRA_IN_MEMORY_DATA)
if (inMemoryData != null) {
val sourceProvider = dataSourceFactory.createProvider(inMemoryData, room)
initialIndex = inMemoryData.indexOfFirst { it.eventId == args.eventId }
initialIndex = inMemoryData.indexOfFirst { it.eventId == args.eventId }.coerceAtLeast(0)
sourceProvider.interactionListener = this
setSourceProvider(sourceProvider)
this.currentSourceProvider = sourceProvider
@ -132,7 +132,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
}
} else {
val events = room?.getAttachmentMessages().orEmpty()
initialIndex = events.indexOfFirst { it.eventId == args.eventId }
initialIndex = events.indexOfFirst { it.eventId == args.eventId }.coerceAtLeast(0)
val sourceProvider = dataSourceFactory.createProvider(events)
sourceProvider.interactionListener = this
setSourceProvider(sourceProvider)