mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-26 02:48:23 +01:00
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.
This commit is contained in:
parent
d864ec6d7f
commit
23c76a86cb
@ -76,12 +76,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
notificationInterval, TimeUnit.HOURS)
|
notificationInterval, TimeUnit.HOURS)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
|
.setInitialDelay(notificationInterval, TimeUnit.HOURS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -100,12 +101,13 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
notificationInterval, TimeUnit.HOURS)
|
notificationInterval, TimeUnit.HOURS)
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
|
.setInitialDelay(notificationInterval, TimeUnit.HOURS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -319,7 +319,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -345,7 +345,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
@ -375,7 +375,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
} else {
|
} else {
|
||||||
workManager.cancelAllWorkByTag(PullNotificationWorker.WORKER_TAG);
|
workManager.cancelUniqueWork(PullNotificationWorker.WORKER_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
|
Loading…
Reference in New Issue
Block a user