feat: AlarmManager option for notifications

This commit is contained in:
rebelonion 2024-03-18 23:51:00 -05:00
parent deeefb8e35
commit 9471683501
17 changed files with 822 additions and 432 deletions

View file

@ -0,0 +1,48 @@
package ani.dantotsu.notifications
import android.content.Context
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
import ani.dantotsu.notifications.comment.CommentNotificationWorker
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
interface TaskScheduler {
fun scheduleRepeatingTask(taskType: TaskType, interval: Long)
fun cancelTask(taskType: TaskType)
fun cancelAllTasks() {
for (taskType in TaskType.entries) {
cancelTask(taskType)
}
}
fun scheduleAllTasks(context: Context) {
for (taskType in TaskType.entries) {
val interval = when (taskType) {
TaskType.COMMENT_NOTIFICATION -> CommentNotificationWorker.checkIntervals[PrefManager.getVal(
PrefName.CommentNotificationInterval)]
TaskType.ANILIST_NOTIFICATION -> AnilistNotificationWorker.checkIntervals[PrefManager.getVal(
PrefName.AnilistNotificationInterval)]
}
scheduleRepeatingTask(taskType, interval)
}
}
companion object {
fun create(context: Context, useAlarmManager: Boolean): TaskScheduler {
return if (useAlarmManager) {
AlarmManagerScheduler(context)
} else {
WorkManagerScheduler(context)
}
}
}
enum class TaskType {
COMMENT_NOTIFICATION,
ANILIST_NOTIFICATION
}
}
interface Task {
suspend fun execute(context: Context): Boolean
}