diff options
author | TheScarastic <warabhishek@e.email> | 2022-07-15 19:27:38 +0530 |
---|---|---|
committer | TheScarastic <warabhishek@e.email> | 2022-07-15 20:02:06 +0530 |
commit | 1a17057ac33dfe608360d2b6f27e92334541c04b (patch) | |
tree | 5b2f4dcb8f9a0ea90564d23107a43b95990d5bac /app/src/main/java | |
parent | 6f845c22a55134d60fdb7710f5c4795e3dea8108 (diff) |
advancedPrivacy: Fetch list on 1st start and update it weekly
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 ) } |