From 078de3bb4d76c55e730d1a318521df4b3394e631 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Mon, 29 Jan 2024 15:27:01 +0100 Subject: [PATCH] remove for loops Signed-off-by: Jonas Mayer --- .../utils/extensions/WorkManagerExtensions.kt | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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 }