forked from GitHub-Mirror/riotX-android
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
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||||
|
import im.vector.matrix.android.internal.worker.startChain
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -288,11 +289,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
|||||||
return matrixOneTimeWorkRequestBuilder<EncryptEventWorker>()
|
return matrixOneTimeWorkRequestBuilder<EncryptEventWorker>()
|
||||||
.setConstraints(WorkManagerUtil.workConstraints)
|
.setConstraints(WorkManagerUtil.workConstraints)
|
||||||
.setInputData(sendWorkData)
|
.setInputData(sendWorkData)
|
||||||
.apply {
|
.startChain(startChain)
|
||||||
if (startChain) {
|
|
||||||
setInputMerger(NoMerger::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@ -322,11 +319,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
|||||||
|
|
||||||
return matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
|
return matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
|
||||||
.setConstraints(WorkManagerUtil.workConstraints)
|
.setConstraints(WorkManagerUtil.workConstraints)
|
||||||
.apply {
|
.startChain(startChain)
|
||||||
if (startChain) {
|
|
||||||
setInputMerger(NoMerger::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setInputData(uploadWorkData)
|
.setInputData(uploadWorkData)
|
||||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||||
.build()
|
.build()
|
||||||
|
@ -19,7 +19,7 @@ import androidx.work.Data
|
|||||||
import androidx.work.InputMerger
|
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() {
|
internal class NoMerger : InputMerger() {
|
||||||
override fun merge(inputs: MutableList<Data>): Data {
|
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 android.content.Context
|
||||||
import androidx.work.*
|
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
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||||
|
import im.vector.matrix.android.internal.worker.startChain
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
@ -61,11 +61,7 @@ internal object TimelineSendEventWorkCommon {
|
|||||||
inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest {
|
inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest {
|
||||||
return matrixOneTimeWorkRequestBuilder<W>()
|
return matrixOneTimeWorkRequestBuilder<W>()
|
||||||
.setConstraints(WorkManagerUtil.workConstraints)
|
.setConstraints(WorkManagerUtil.workConstraints)
|
||||||
.apply {
|
.startChain(startChain)
|
||||||
if (startChain) {
|
|
||||||
setInputMerger(NoMerger::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setInputData(data)
|
.setInputData(data)
|
||||||
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
|
||||||
.build()
|
.build()
|
||||||
|
@ -16,3 +16,15 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.worker
|
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