diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-07-06 02:51:41 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-07-06 02:51:41 +0000 |
commit | 5e02a43ba7abacd484daf07e50ad26973fb83240 (patch) | |
tree | 3d85355e4aa84a0005104ea316a55b5638c5c949 /app/src/main/java | |
parent | 845e016f0affec9bf5df3ebbb51404d5d1745e74 (diff) | |
download | infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar.gz infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar.bz2 infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar.lz infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar.xz infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.tar.zst infinity-for-reddit-5e02a43ba7abacd484daf07e50ad26973fb83240.zip |
Fix notification interval not properly set for 15 and 30 mins.
Diffstat (limited to 'app/src/main/java')
3 files changed, 17 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 824a686d..1c840c63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -322,7 +322,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true); long notificationInterval = Long.parseLong(mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1")); - TimeUnit timeUnit = notificationInterval == 15 || notificationInterval == 30 ? TimeUnit.MINUTES : TimeUnit.HOURS; + TimeUnit timeUnit = (notificationInterval == 15 || notificationInterval == 30) ? TimeUnit.MINUTES : TimeUnit.HOURS; WorkManager workManager = WorkManager.getInstance(this); @@ -354,10 +354,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb .setConstraints(constraints) .build(); - workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, + workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME, ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest); } else { - workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME); } bindView(); @@ -380,10 +380,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb .setConstraints(constraints) .build(); - workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, + workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME, ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest); } else { - workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME); } bindView(); @@ -410,10 +410,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb .setConstraints(constraints) .build(); - workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, + workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME, ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest); } else { - workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME); } bindView(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java index 246f9119..ebabe07c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java @@ -42,7 +42,7 @@ import retrofit2.Response; import retrofit2.Retrofit; public class PullNotificationWorker extends Worker { - public static final String WORKER_TAG = "PNWT"; + public static final String UNIQUE_WORKER_NAME = "PNWT"; @Inject @Named("oauth_without_authenticator") Retrofit mOauthWithoutAuthenticatorRetrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java index f6644468..3060be41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java @@ -53,6 +53,7 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { enableNotification = sharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true); notificationInterval = Long.parseLong(sharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1")); + TimeUnit timeUnit = (notificationInterval == 15 || notificationInterval == 30) ? TimeUnit.MINUTES : TimeUnit.HOURS; if (enableNotification) { if (notificationIntervalListPreference != null) { @@ -74,15 +75,15 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { PeriodicWorkRequest pullNotificationRequest = new PeriodicWorkRequest.Builder(PullNotificationWorker.class, - notificationInterval, TimeUnit.HOURS) + notificationInterval, timeUnit) .setConstraints(constraints) - .setInitialDelay(notificationInterval, TimeUnit.HOURS) + .setInitialDelay(notificationInterval, timeUnit) .build(); - workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, + workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME, ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest); } else { - workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME); } return true; }); @@ -99,15 +100,15 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { PeriodicWorkRequest pullNotificationRequest = new PeriodicWorkRequest.Builder(PullNotificationWorker.class, - notificationInterval, TimeUnit.HOURS) + notificationInterval, timeUnit) .setConstraints(constraints) - .setInitialDelay(notificationInterval, TimeUnit.HOURS) + .setInitialDelay(notificationInterval, timeUnit) .build(); - workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG, + workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME, ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest); } else { - workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG); + workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME); } return true; |