From 4f2618021e6826604be9b13bae592d74e912326d Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 15 Feb 2020 13:21:41 +0100 Subject: [PATCH] Ad network constraint to sync worker --- .../readrops/app/fragments/settings/SettingsFragment.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/readrops/app/fragments/settings/SettingsFragment.java b/app/src/main/java/com/readrops/app/fragments/settings/SettingsFragment.java index 1215bd59..956c1479 100644 --- a/app/src/main/java/com/readrops/app/fragments/settings/SettingsFragment.java +++ b/app/src/main/java/com/readrops/app/fragments/settings/SettingsFragment.java @@ -8,7 +8,9 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatDelegate; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.work.Constraints; import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.NetworkType; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; @@ -68,8 +70,13 @@ public class SettingsFragment extends PreferenceFragmentCompat { Pair interval = getWorkerInterval((String) newValue); if (interval != null) { + Constraints constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .build(); + PeriodicWorkRequest request = new PeriodicWorkRequest.Builder(SyncWorker.class, interval.first, interval.second) .addTag(SyncWorker.Companion.getTAG()) + .setConstraints(constraints) .setInitialDelay(15, TimeUnit.MINUTES) .build();