fix: notification check on app launch

This commit is contained in:
rebelonion 2024-03-22 22:34:21 -05:00
parent dca6ffdbbe
commit a189802061
7 changed files with 50 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package ani.dantotsu.notifications
import android.content.Context
import androidx.work.OutOfQuotaPolicy
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
import ani.dantotsu.notifications.comment.CommentNotificationWorker
import ani.dantotsu.notifications.subscription.SubscriptionNotificationWorker
@ -31,6 +32,31 @@ interface TaskScheduler {
}
}
fun scheduleSingleWork(context: Context) {
val workManager = androidx.work.WorkManager.getInstance(context)
workManager.enqueueUniqueWork(
CommentNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(CommentNotificationWorker::class.java)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
)
workManager.enqueueUniqueWork(
AnilistNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(AnilistNotificationWorker::class.java)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
)
workManager.enqueueUniqueWork(
SubscriptionNotificationWorker.WORK_NAME,
androidx.work.ExistingWorkPolicy.REPLACE,
androidx.work.OneTimeWorkRequest.Builder(SubscriptionNotificationWorker::class.java)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
)
}
companion object {
fun create(context: Context, useAlarmManager: Boolean): TaskScheduler {
return if (useAlarmManager) {