mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Merge pull request #280 from Dominaezzz/kotlinify-1
Enhance CancelableBag
This commit is contained in:
commit
205af8b122
3 changed files with 5 additions and 22 deletions
|
@ -16,20 +16,8 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.api.util
|
package im.vector.matrix.android.api.util
|
||||||
|
|
||||||
class CancelableBag : Cancelable {
|
class CancelableBag : Cancelable, MutableList<Cancelable> by ArrayList() {
|
||||||
|
|
||||||
private val cancelableList = ArrayList<Cancelable>()
|
|
||||||
|
|
||||||
fun add(cancelable: Cancelable) {
|
|
||||||
cancelableList.add(cancelable)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
cancelableList.forEach { it.cancel() }
|
forEach { it.cancel() }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Cancelable.addTo(cancelables: CancelableBag) {
|
|
||||||
cancelables.add(this)
|
|
||||||
}
|
|
|
@ -26,7 +26,6 @@ import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.room.send.SendService
|
import im.vector.matrix.android.api.session.room.send.SendService
|
||||||
import im.vector.matrix.android.api.util.Cancelable
|
import im.vector.matrix.android.api.util.Cancelable
|
||||||
import im.vector.matrix.android.api.util.CancelableBag
|
import im.vector.matrix.android.api.util.CancelableBag
|
||||||
import im.vector.matrix.android.api.util.addTo
|
|
||||||
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
||||||
import im.vector.matrix.android.internal.util.CancelableWork
|
import im.vector.matrix.android.internal.util.CancelableWork
|
||||||
|
@ -82,11 +81,9 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendMedias(attachments: List<ContentAttachmentData>): Cancelable {
|
override fun sendMedias(attachments: List<ContentAttachmentData>): Cancelable {
|
||||||
val cancelableBag = CancelableBag()
|
return attachments.mapTo(CancelableBag()) {
|
||||||
attachments.forEach {
|
sendMedia(it)
|
||||||
sendMedia(it).addTo(cancelableBag)
|
|
||||||
}
|
}
|
||||||
return cancelableBag
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun redactEvent(event: Event, reason: String?): Cancelable {
|
override fun redactEvent(event: Event, reason: String?): Cancelable {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.timeline.Timeline
|
import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.matrix.android.api.util.CancelableBag
|
import im.vector.matrix.android.api.util.CancelableBag
|
||||||
import im.vector.matrix.android.api.util.addTo
|
|
||||||
import im.vector.matrix.android.internal.crypto.NewSessionListener
|
import im.vector.matrix.android.internal.crypto.NewSessionListener
|
||||||
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
|
@ -396,7 +395,7 @@ internal class DefaultTimeline(
|
||||||
limit = limit)
|
limit = limit)
|
||||||
|
|
||||||
Timber.v("Should fetch $limit items $direction")
|
Timber.v("Should fetch $limit items $direction")
|
||||||
paginationTask.configureWith(params)
|
cancelableBag += paginationTask.configureWith(params)
|
||||||
.enableRetry()
|
.enableRetry()
|
||||||
.dispatchTo(object : MatrixCallback<TokenChunkEventPersistor.Result> {
|
.dispatchTo(object : MatrixCallback<TokenChunkEventPersistor.Result> {
|
||||||
override fun onSuccess(data: TokenChunkEventPersistor.Result) {
|
override fun onSuccess(data: TokenChunkEventPersistor.Result) {
|
||||||
|
@ -415,7 +414,6 @@ internal class DefaultTimeline(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
.addTo(cancelableBag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue