DRY
This commit is contained in:
parent
83467b8597
commit
ca70ddb810
@ -70,7 +70,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
|
||||
private var initialIndex = 0
|
||||
private var isAnimatingOut = false
|
||||
|
||||
var currentSourceProvider: BaseAttachmentProvider? = null
|
||||
private var currentSourceProvider: BaseAttachmentProvider? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -117,26 +117,17 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
|
||||
val room = args.roomId?.let { session.getRoom(it) }
|
||||
|
||||
val inMemoryData = intent.getParcelableArrayListExtra<AttachmentData>(EXTRA_IN_MEMORY_DATA)
|
||||
if (inMemoryData != null) {
|
||||
val sourceProvider = dataSourceFactory.createProvider(inMemoryData, room)
|
||||
val sourceProvider = if (inMemoryData != null) {
|
||||
initialIndex = inMemoryData.indexOfFirst { it.eventId == args.eventId }.coerceAtLeast(0)
|
||||
sourceProvider.interactionListener = this
|
||||
setSourceProvider(sourceProvider)
|
||||
this.currentSourceProvider = sourceProvider
|
||||
if (savedInstanceState == null) {
|
||||
pager2.setCurrentItem(initialIndex, false)
|
||||
// The page change listener is not notified of the change...
|
||||
pager2.post {
|
||||
onSelectedPositionChanged(initialIndex)
|
||||
}
|
||||
}
|
||||
dataSourceFactory.createProvider(inMemoryData, room)
|
||||
} else {
|
||||
val events = room?.getAttachmentMessages().orEmpty()
|
||||
initialIndex = events.indexOfFirst { it.eventId == args.eventId }.coerceAtLeast(0)
|
||||
val sourceProvider = dataSourceFactory.createProvider(events)
|
||||
dataSourceFactory.createProvider(events)
|
||||
}
|
||||
sourceProvider.interactionListener = this
|
||||
setSourceProvider(sourceProvider)
|
||||
this.currentSourceProvider = sourceProvider
|
||||
currentSourceProvider = sourceProvider
|
||||
if (savedInstanceState == null) {
|
||||
pager2.setCurrentItem(initialIndex, false)
|
||||
// The page change listener is not notified of the change...
|
||||
@ -144,7 +135,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
|
||||
onSelectedPositionChanged(initialIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.black_alpha)
|
||||
window.navigationBarColor = ContextCompat.getColor(this, R.color.black_alpha)
|
||||
@ -274,7 +264,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), BaseAttachmen
|
||||
}
|
||||
|
||||
override fun onShareTapped() {
|
||||
this.currentSourceProvider?.getFileForSharing(currentPosition) { data ->
|
||||
currentSourceProvider?.getFileForSharing(currentPosition) { data ->
|
||||
if (data != null && lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
shareMedia(this@VectorAttachmentViewerActivity, data, getMimeTypeFromUri(this@VectorAttachmentViewerActivity, data.toUri()))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user