mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +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 -> {
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
||||||
long notificationInterval = Long.parseLong(mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
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);
|
WorkManager workManager = WorkManager.getInstance(this);
|
||||||
|
|
||||||
@ -354,10 +354,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -380,10 +380,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -410,10 +410,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
|
@ -42,7 +42,7 @@ import retrofit2.Response;
|
|||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class PullNotificationWorker extends Worker {
|
public class PullNotificationWorker extends Worker {
|
||||||
public static final String WORKER_TAG = "PNWT";
|
public static final String UNIQUE_WORKER_NAME = "PNWT";
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth_without_authenticator")
|
@Named("oauth_without_authenticator")
|
||||||
Retrofit mOauthWithoutAuthenticatorRetrofit;
|
Retrofit mOauthWithoutAuthenticatorRetrofit;
|
||||||
|
@ -53,6 +53,7 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
enableNotification = sharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
enableNotification = sharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
||||||
notificationInterval = Long.parseLong(sharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
notificationInterval = Long.parseLong(sharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
||||||
|
TimeUnit timeUnit = (notificationInterval == 15 || notificationInterval == 30) ? TimeUnit.MINUTES : TimeUnit.HOURS;
|
||||||
|
|
||||||
if (enableNotification) {
|
if (enableNotification) {
|
||||||
if (notificationIntervalListPreference != null) {
|
if (notificationIntervalListPreference != null) {
|
||||||
@ -74,15 +75,15 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
notificationInterval, TimeUnit.HOURS)
|
notificationInterval, timeUnit)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.setInitialDelay(notificationInterval, TimeUnit.HOURS)
|
.setInitialDelay(notificationInterval, timeUnit)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -99,15 +100,15 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
notificationInterval, TimeUnit.HOURS)
|
notificationInterval, timeUnit)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.setInitialDelay(notificationInterval, TimeUnit.HOURS)
|
.setInitialDelay(notificationInterval, timeUnit)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user