mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Fix notification interval not properly set for 15 and 30 mins.
This commit is contained in:
parent
845e016f0a
commit
5e02a43ba7
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user