More cleanup

This commit is contained in:
Benoit Marty 2020-11-10 15:09:49 +01:00
parent 345e8a0679
commit 816301bf8d

View file

@ -119,33 +119,29 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
val inMemoryData = intent.getParcelableArrayListExtra<AttachmentData>(EXTRA_IN_MEMORY_DATA) val inMemoryData = intent.getParcelableArrayListExtra<AttachmentData>(EXTRA_IN_MEMORY_DATA)
if (inMemoryData != null) { if (inMemoryData != null) {
val sourceProvider = dataSourceFactory.createProvider(inMemoryData, room) val sourceProvider = dataSourceFactory.createProvider(inMemoryData, room)
val index = inMemoryData.indexOfFirst { it.eventId == args.eventId } initialIndex = inMemoryData.indexOfFirst { it.eventId == args.eventId }
initialIndex = index
sourceProvider.interactionListener = this sourceProvider.interactionListener = this
setSourceProvider(sourceProvider) setSourceProvider(sourceProvider)
this.currentSourceProvider = sourceProvider this.currentSourceProvider = sourceProvider
if (savedInstanceState == null) { if (savedInstanceState == null) {
pager2.setCurrentItem(index, false) pager2.setCurrentItem(initialIndex, false)
// The page change listener is not notified of the change... // The page change listener is not notified of the change...
pager2.post { pager2.post {
onSelectedPositionChanged(index) onSelectedPositionChanged(initialIndex)
} }
} }
} else { } else {
val events = room?.getAttachmentMessages() val events = room?.getAttachmentMessages().orEmpty()
?: emptyList() initialIndex = events.indexOfFirst { it.eventId == args.eventId }
val index = events.indexOfFirst { it.eventId == args.eventId }
initialIndex = index
val sourceProvider = dataSourceFactory.createProvider(events) val sourceProvider = dataSourceFactory.createProvider(events)
sourceProvider.interactionListener = this sourceProvider.interactionListener = this
setSourceProvider(sourceProvider) setSourceProvider(sourceProvider)
this.currentSourceProvider = sourceProvider this.currentSourceProvider = sourceProvider
if (savedInstanceState == null) { if (savedInstanceState == null) {
pager2.setCurrentItem(index, false) pager2.setCurrentItem(initialIndex, false)
// The page change listener is not notified of the change... // The page change listener is not notified of the change...
pager2.post { pager2.post {
onSelectedPositionChanged(index) onSelectedPositionChanged(initialIndex)
} }
} }
} }