This commit is contained in:
Benoit Marty 2019-07-09 17:16:17 +02:00
parent 4281b5967a
commit c19b1f917f
1 changed files with 7 additions and 2 deletions

View File

@ -22,17 +22,22 @@ import androidx.work.*
internal object WorkManagerUtil { internal object WorkManagerUtil {
private const val MATRIX_SDK_TAG = "MatrixSDK" private const val MATRIX_SDK_TAG = "MatrixSDK"
// Default constraints: network /**
* Default constraints: connected network
*/
val workConstraints = Constraints.Builder() val workConstraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
.build() .build()
/**
* Create a OneTimeWorkRequestBuilder, with the Matrix SDK tag
*/
inline fun <reified W : ListenableWorker> matrixOneTimeWorkRequestBuilder() = inline fun <reified W : ListenableWorker> matrixOneTimeWorkRequestBuilder() =
OneTimeWorkRequestBuilder<W>() OneTimeWorkRequestBuilder<W>()
.addTag(MATRIX_SDK_TAG) .addTag(MATRIX_SDK_TAG)
/** /**
* Cancel all work instanciated by the Matrix SDK and not those from the SDK client * Cancel all works instantiated by the Matrix SDK and not those from the SDK client
*/ */
fun cancelAllWorks(context: Context) { fun cancelAllWorks(context: Context) {
WorkManager.getInstance(context).also { WorkManager.getInstance(context).also {