fix: task system cleanup
This commit is contained in:
parent
ea48809d07
commit
8b582a9d32
3 changed files with 24 additions and 29 deletions
|
@ -135,7 +135,6 @@ class App : MultiDexApplication() {
|
||||||
val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager)
|
val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager)
|
||||||
val scheduler = TaskScheduler.create(this, useAlarmManager)
|
val scheduler = TaskScheduler.create(this, useAlarmManager)
|
||||||
scheduler.scheduleAllTasks(this)
|
scheduler.scheduleAllTasks(this)
|
||||||
scheduler.scheduleSingleWork(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNotificationChannels() {
|
private fun setupNotificationChannels() {
|
||||||
|
|
|
@ -48,6 +48,7 @@ import ani.dantotsu.home.LoginFragment
|
||||||
import ani.dantotsu.home.MangaFragment
|
import ani.dantotsu.home.MangaFragment
|
||||||
import ani.dantotsu.home.NoInternet
|
import ani.dantotsu.home.NoInternet
|
||||||
import ani.dantotsu.media.MediaDetailsActivity
|
import ani.dantotsu.media.MediaDetailsActivity
|
||||||
|
import ani.dantotsu.notifications.TaskScheduler
|
||||||
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
|
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
|
||||||
import ani.dantotsu.notifications.comment.CommentNotificationWorker
|
import ani.dantotsu.notifications.comment.CommentNotificationWorker
|
||||||
import ani.dantotsu.others.CustomBottomDialog
|
import ani.dantotsu.others.CustomBottomDialog
|
||||||
|
@ -102,12 +103,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
TaskScheduler.scheduleSingleWork(this)
|
||||||
androidx.work.WorkManager.getInstance(this)
|
|
||||||
.enqueue(OneTimeWorkRequest.Companion.from(CommentNotificationWorker::class.java))
|
|
||||||
|
|
||||||
androidx.work.WorkManager.getInstance(this)
|
|
||||||
.enqueue(OneTimeWorkRequest.Companion.from(AnilistNotificationWorker::class.java))
|
|
||||||
|
|
||||||
val action = intent.action
|
val action = intent.action
|
||||||
val type = intent.type
|
val type = intent.type
|
||||||
|
|
|
@ -36,28 +36,6 @@ 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)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
workManager.enqueueUniqueWork(
|
|
||||||
AnilistNotificationWorker.WORK_NAME,
|
|
||||||
androidx.work.ExistingWorkPolicy.REPLACE,
|
|
||||||
androidx.work.OneTimeWorkRequest.Builder(AnilistNotificationWorker::class.java)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
workManager.enqueueUniqueWork(
|
|
||||||
SubscriptionNotificationWorker.WORK_NAME,
|
|
||||||
androidx.work.ExistingWorkPolicy.REPLACE,
|
|
||||||
androidx.work.OneTimeWorkRequest.Builder(SubscriptionNotificationWorker::class.java)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun create(context: Context, useAlarmManager: Boolean): TaskScheduler {
|
fun create(context: Context, useAlarmManager: Boolean): TaskScheduler {
|
||||||
return if (useAlarmManager) {
|
return if (useAlarmManager) {
|
||||||
|
@ -66,6 +44,28 @@ interface TaskScheduler {
|
||||||
WorkManagerScheduler(context)
|
WorkManagerScheduler(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun scheduleSingleWork(context: Context) {
|
||||||
|
val workManager = androidx.work.WorkManager.getInstance(context)
|
||||||
|
workManager.enqueueUniqueWork(
|
||||||
|
CommentNotificationWorker.WORK_NAME + "_single",
|
||||||
|
androidx.work.ExistingWorkPolicy.REPLACE,
|
||||||
|
androidx.work.OneTimeWorkRequest.Builder(CommentNotificationWorker::class.java)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
workManager.enqueueUniqueWork(
|
||||||
|
AnilistNotificationWorker.WORK_NAME + "_single",
|
||||||
|
androidx.work.ExistingWorkPolicy.REPLACE,
|
||||||
|
androidx.work.OneTimeWorkRequest.Builder(AnilistNotificationWorker::class.java)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
workManager.enqueueUniqueWork(
|
||||||
|
SubscriptionNotificationWorker.WORK_NAME + "_single",
|
||||||
|
androidx.work.ExistingWorkPolicy.REPLACE,
|
||||||
|
androidx.work.OneTimeWorkRequest.Builder(SubscriptionNotificationWorker::class.java)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class TaskType {
|
enum class TaskType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue