From 1a17057ac33dfe608360d2b6f27e92334541c04b Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Fri, 15 Jul 2022 19:27:38 +0530 Subject: advancedPrivacy: Fetch list on 1st start and update it weekly --- .../e/privacycentralapp/UpdateTrackersWorker.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') 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( - 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 ) } -- cgit v1.2.1