mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Start chain: create extension
This commit is contained in:
parent
d82fd10f3b
commit
7a6fc4936b
@ -42,6 +42,7 @@ import im.vector.matrix.android.internal.worker.AlwaysSuccessfulWorker
|
||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||
import im.vector.matrix.android.internal.worker.startChain
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -288,11 +289,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||
return matrixOneTimeWorkRequestBuilder<EncryptEventWorker>()
|
||||
.setConstraints(WorkManagerUtil.workConstraints)
|
||||
.setInputData(sendWorkData)
|
||||
.apply {
|
||||
if (startChain) {
|
||||
setInputMerger(NoMerger::class.java)
|
||||
}
|
||||
}
|
||||
.startChain(startChain)
|
||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
}
|
||||
@ -322,11 +319,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||
|
||||
return matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
|
||||
.setConstraints(WorkManagerUtil.workConstraints)
|
||||
.apply {
|
||||
if (startChain) {
|
||||
setInputMerger(NoMerger::class.java)
|
||||
}
|
||||
}
|
||||
.startChain(startChain)
|
||||
.setInputData(uploadWorkData)
|
||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
|
@ -19,7 +19,7 @@ import androidx.work.Data
|
||||
import androidx.work.InputMerger
|
||||
|
||||
/**
|
||||
* InputMerger which takes only the first input, to ensure an appended work with only have the specified parameters
|
||||
* InputMerger which takes only the first input, to ensure an appended work will only have the specified parameters
|
||||
*/
|
||||
internal class NoMerger : InputMerger() {
|
||||
override fun merge(inputs: MutableList<Data>): Data {
|
||||
|
@ -17,9 +17,9 @@ package im.vector.matrix.android.internal.session.room.timeline
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.*
|
||||
import im.vector.matrix.android.internal.session.room.send.NoMerger
|
||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||
import im.vector.matrix.android.internal.worker.startChain
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
@ -61,11 +61,7 @@ internal object TimelineSendEventWorkCommon {
|
||||
inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest {
|
||||
return matrixOneTimeWorkRequestBuilder<W>()
|
||||
.setConstraints(WorkManagerUtil.workConstraints)
|
||||
.apply {
|
||||
if (startChain) {
|
||||
setInputMerger(NoMerger::class.java)
|
||||
}
|
||||
}
|
||||
.startChain(startChain)
|
||||
.setInputData(data)
|
||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
|
@ -16,3 +16,15 @@
|
||||
|
||||
package im.vector.matrix.android.internal.worker
|
||||
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import im.vector.matrix.android.internal.session.room.send.NoMerger
|
||||
|
||||
/**
|
||||
* If startChain parameter is true, the builder will have a inputMerger set to [NoMerger]
|
||||
*/
|
||||
internal fun OneTimeWorkRequest.Builder.startChain(startChain: Boolean): OneTimeWorkRequest.Builder {
|
||||
if (startChain) {
|
||||
setInputMerger(NoMerger::class.java)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user