aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-22 09:30:42 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-22 09:30:42 +0000
commit23c76a86cb0ccb71776c13bd619155d35797a26e (patch)
treea9322ed6855203a71d0673e1074cb9ca64134244 /app
parentd864ec6d7fa92d18a5d4482fb50907c03f7731a5 (diff)
downloadinfinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.gz
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.bz2
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.lz
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.xz
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.tar.zst
infinity-for-reddit-23c76a86cb0ccb71776c13bd619155d35797a26e.zip
Correctly cancel periodic work request by id not by tag. Add an initial delay which is the same time as the interval when start PullNotificationWorker in NotificationPreferenceFragment.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/Settings/NotificationPreferenceFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java6
2 files changed, 9 insertions, 7 deletions
diff --git a/app/src/main/java/Settings/NotificationPreferenceFragment.java b/app/src/main/java/Settings/NotificationPreferenceFragment.java
index 17a5d07a..4d9051fe 100644
--- a/app/src/main/java/Settings/NotificationPreferenceFragment.java
+++ b/app/src/main/java/Settings/NotificationPreferenceFragment.java
@@ -76,12 +76,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
notificationInterval, TimeUnit.HOURS)
.setConstraints(constraints)
+ .setInitialDelay(notificationInterval, TimeUnit.HOURS)
.build();
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
- ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
+ ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
} else {
- workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
+ workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
}
return true;
});
@@ -100,12 +101,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
notificationInterval, TimeUnit.HOURS)
.setConstraints(constraints)
+ .setInitialDelay(notificationInterval, TimeUnit.HOURS)
.build();
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
- ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
+ ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
} else {
- workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
+ workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
}
return true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 300cd4c1..8be70369 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -319,7 +319,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
} else {
- workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
+ workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
}
bindView();
@@ -345,7 +345,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
} else {
- workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
+ workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
}
bindView();
@@ -375,7 +375,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
} else {
- workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
+ workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
}
bindView();