diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt index ba6bae9..c83d8f9 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt @@ -18,12 +18,14 @@ package foundation.e.privacycentralapp import android.content.Context +import androidx.work.Constraints import androidx.work.CoroutineWorker import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.NetworkType import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters -import java.time.temporal.ChronoUnit +import java.util.concurrent.TimeUnit class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) : CoroutineWorker(appContext, workerParams) { @@ -37,15 +39,18 @@ class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) } companion object { + private val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .build() + fun periodicUpdate(context: Context) { val request = PeriodicWorkRequestBuilder<UpdateTrackersWorker>( - ChronoUnit.WEEKS.duration, - ChronoUnit.DAYS.duration - ).build() + 7, TimeUnit.DAYS) + .setConstraints(constraints).build() WorkManager.getInstance(context).enqueueUniquePeriodicWork( UpdateTrackersWorker::class.qualifiedName ?: "", - ExistingPeriodicWorkPolicy.REPLACE, + ExistingPeriodicWorkPolicy.KEEP, request ) } |