diff --git a/app/src/main/java/com/nextcloud/utils/extensions/WorkManagerExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/WorkManagerExtensions.kt index 885f5668e161..5be0c16479bb 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/WorkManagerExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/WorkManagerExtensions.kt @@ -29,7 +29,6 @@ import java.util.concurrent.ExecutionException fun WorkManager.isWorkScheduled(tag: String): Boolean { val statuses: ListenableFuture> = this.getWorkInfosByTag(tag) - var running = false var workInfoList: List = emptyList() try { @@ -40,17 +39,13 @@ fun WorkManager.isWorkScheduled(tag: String): Boolean { Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e") } - for (workInfo in workInfoList) { - val state = workInfo.state - running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED) + return workInfoList.any { + it.state == WorkInfo.State.RUNNING || it.state == WorkInfo.State.ENQUEUED } - - return running } fun WorkManager.isWorkRunning(tag: String): Boolean { val statuses: ListenableFuture> = this.getWorkInfosByTag(tag) - var running = false var workInfoList: List = emptyList() try { @@ -61,10 +56,7 @@ fun WorkManager.isWorkRunning(tag: String): Boolean { Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e") } - for (workInfo in workInfoList) { - val state = workInfo.state - running = running || state == WorkInfo.State.RUNNING + return workInfoList.any { + it.state == WorkInfo.State.RUNNING } - - return running }