42 lines
1.7 KiB
Kotlin
42 lines
1.7 KiB
Kotlin
package com.adlerosn.brasilfurfest.notification
|
|
|
|
import android.app.job.JobInfo
|
|
import android.app.job.JobScheduler
|
|
import android.content.ComponentName
|
|
import android.content.Context
|
|
import com.adlerosn.brasilfurfest.helper.getPendingJobCompat
|
|
import com.adlerosn.brasilfurfest.helper.setPeriodicCompat
|
|
import com.adlerosn.brasilfurfest.helper.setRequiresBatteryNotLowCompat
|
|
|
|
class AppJobScheduler(context: Context) {
|
|
init {
|
|
val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
|
|
// notification
|
|
if (jobScheduler.getPendingJobCompat(1) == null) {
|
|
jobScheduler.schedule(
|
|
JobInfo.Builder(
|
|
1,
|
|
ComponentName(context, NotificationJobService::class.java)
|
|
)
|
|
.setPeriodicCompat(60*1000L, 30*1000L)
|
|
.setRequiresBatteryNotLowCompat(false)
|
|
.setPersisted(true)
|
|
.build()
|
|
)
|
|
}
|
|
// schedule updater
|
|
if (jobScheduler.getPendingJobCompat(2) == null) {
|
|
jobScheduler.schedule(
|
|
JobInfo.Builder(
|
|
2,
|
|
ComponentName(context, ScheduleUpdaterJobService::class.java)
|
|
)
|
|
.setPeriodicCompat(5*60*1000L, 180*1000L)
|
|
.setRequiresBatteryNotLowCompat(false)
|
|
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
|
.setPersisted(true)
|
|
.build()
|
|
)
|
|
}
|
|
}
|
|
} |