Convert a Task to a ConfigurableTask without parameter

This commit is contained in:
Benoit Marty 2019-07-09 18:41:08 +02:00
parent fe82ad2002
commit e6c74dc1fe
7 changed files with 22 additions and 11 deletions

View file

@ -73,6 +73,7 @@ import im.vector.matrix.android.internal.session.room.membership.RoomMembers
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
import im.vector.matrix.android.internal.util.JsonCanonicalizer
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import im.vector.matrix.android.internal.util.fetchCopied
@ -197,7 +198,7 @@ internal class CryptoManager @Inject constructor(
override fun getDevicesList(callback: MatrixCallback<DevicesListResponse>) {
getDevicesTask
.configureWith(Unit)
.toConfigurableTask()
.dispatchTo(callback)
.executeBy(taskExecutor)
}
@ -1054,7 +1055,8 @@ internal class CryptoManager @Inject constructor(
}
override fun clearCryptoCache(callback: MatrixCallback<Unit>) {
clearCryptoDataTask.configureWith(Unit)
clearCryptoDataTask
.toConfigurableTask()
.dispatchTo(callback)
.executeBy(taskExecutor)
}

View file

@ -51,6 +51,7 @@ import im.vector.matrix.android.internal.crypto.store.db.model.KeysBackupDataEnt
import im.vector.matrix.android.internal.di.MoshiProvider
import im.vector.matrix.android.internal.extensions.foldToCallback
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.*
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.TaskThread
@ -876,7 +877,7 @@ internal class KeysBackup @Inject constructor(
override fun getCurrentVersion(callback: MatrixCallback<KeysVersionResult?>) {
getKeysBackupLastVersionTask
.configureWith(Unit)
.toConfigurableTask()
.dispatchTo(object : MatrixCallback<KeysVersionResult> {
override fun onSuccess(data: KeysVersionResult) {
callback.onSuccess(data)

View file

@ -19,9 +19,8 @@ package im.vector.matrix.android.internal.session.cache
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.cache.CacheService
import im.vector.matrix.android.internal.di.SessionDatabase
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
import javax.inject.Inject
internal class DefaultCacheService @Inject constructor(@SessionDatabase private val clearCacheTask: ClearCacheTask,
@ -29,7 +28,7 @@ internal class DefaultCacheService @Inject constructor(@SessionDatabase private
override fun clearCache(callback: MatrixCallback<Unit>) {
clearCacheTask
.configureWith(Unit)
.toConfigurableTask()
.dispatchTo(callback)
.executeBy(taskExecutor)
}

View file

@ -29,6 +29,7 @@ import im.vector.matrix.android.internal.database.model.PusherEntity
import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
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
@ -49,7 +50,7 @@ internal class DefaultPusherService @Inject constructor(
override fun refreshPushers() {
getPusherTask
.configureWith(Unit)
.toConfigurableTask()
.executeBy(taskExecutor)
}

View file

@ -27,6 +27,7 @@ import im.vector.matrix.android.internal.session.room.directory.GetThirdPartyPro
import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
import javax.inject.Inject
internal class DefaultRoomDirectoryService @Inject constructor(private val getPublicRoomTask: GetPublicRoomTask,
@ -52,7 +53,7 @@ internal class DefaultRoomDirectoryService @Inject constructor(private val getPu
override fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>) {
getThirdPartyProtocolsTask
.configureWith(Unit)
.toConfigurableTask()
.dispatchTo(callback)
.executeBy(taskExecutor)
}

View file

@ -19,7 +19,7 @@ package im.vector.matrix.android.internal.session.signout
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.signout.SignOutService
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
import javax.inject.Inject
internal class DefaultSignOutService @Inject constructor(private val signOutTask: SignOutTask,
@ -27,7 +27,7 @@ internal class DefaultSignOutService @Inject constructor(private val signOutTask
override fun signOut(callback: MatrixCallback<Unit>) {
signOutTask
.configureWith(Unit)
.toConfigurableTask()
.dispatchTo(callback)
.executeBy(taskExecutor)
}

View file

@ -21,7 +21,14 @@ import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.util.Cancelable
internal fun <PARAMS, RESULT> Task<PARAMS, RESULT>.configureWith(params: PARAMS): ConfigurableTask<PARAMS, RESULT> {
return ConfigurableTask (this, params)
return ConfigurableTask(this, params)
}
/**
* Convert a Task to a ConfigurableTask without parameter
*/
internal fun <RESULT> Task<Unit, RESULT>.toConfigurableTask(): ConfigurableTask<Unit, RESULT> {
return ConfigurableTask(this, Unit)
}
internal data class ConfigurableTask<PARAMS, RESULT>(