mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 11:01:52 +01:00
Tweak WorkManager task cancellation, add flex times
This commit is contained in:
parent
d873d653d0
commit
a3dd5c1e92
@ -163,7 +163,9 @@ dependencies {
|
||||
implementation 'org.jsoup:jsoup:1.12.1'
|
||||
|
||||
// Job scheduling
|
||||
implementation 'android.arch.work:work-runtime:2.3.2'
|
||||
final workManagerVersion = '2.3.2'
|
||||
implementation "android.arch.work:work-runtime:$workManagerVersion"
|
||||
implementation "android.arch.work:work-runtime-ktx:$workManagerVersion"
|
||||
|
||||
// Changelog
|
||||
implementation 'com.github.gabrielemariotti.changeloglib:changelog:2.1.0'
|
||||
|
@ -32,16 +32,16 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
||||
val preferences = Injekt.get<PreferencesHelper>()
|
||||
val interval = prefInterval ?: preferences.backupInterval().getOrDefault()
|
||||
if (interval > 0) {
|
||||
val request = PeriodicWorkRequestBuilder<BackupCreatorJob>(interval.toLong(), TimeUnit.HOURS)
|
||||
val request = PeriodicWorkRequestBuilder<BackupCreatorJob>(
|
||||
interval.toLong(), TimeUnit.HOURS,
|
||||
10, TimeUnit.MINUTES)
|
||||
.addTag(TAG)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
} else {
|
||||
WorkManager.getInstance().cancelAllWorkByTag(TAG)
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelTask() {
|
||||
WorkManager.getInstance().cancelAllWorkByTag(TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,17 +41,17 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
||||
.setRequiresCharging(acRestriction)
|
||||
.build()
|
||||
|
||||
val request = PeriodicWorkRequestBuilder<LibraryUpdateJob>(interval.toLong(), TimeUnit.HOURS)
|
||||
val request = PeriodicWorkRequestBuilder<LibraryUpdateJob>(
|
||||
interval.toLong(), TimeUnit.HOURS,
|
||||
10, TimeUnit.MINUTES)
|
||||
.addTag(TAG)
|
||||
.setConstraints(constraints)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
|
||||
} else {
|
||||
WorkManager.getInstance().cancelAllWorkByTag(TAG)
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelTask() {
|
||||
WorkManager.getInstance().cancelAllWorkByTag(TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,9 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.build()
|
||||
|
||||
val request = PeriodicWorkRequestBuilder<UpdaterJob>(1, TimeUnit.DAYS)
|
||||
val request = PeriodicWorkRequestBuilder<UpdaterJob>(
|
||||
1, TimeUnit.DAYS,
|
||||
1, TimeUnit.HOURS)
|
||||
.addTag(TAG)
|
||||
.setConstraints(constraints)
|
||||
.build()
|
||||
|
@ -105,13 +105,8 @@ class SettingsBackupController : SettingsController() {
|
||||
summary = "%s"
|
||||
|
||||
onChange { newValue ->
|
||||
// Always cancel the previous task, it seems that sometimes they are not updated
|
||||
BackupCreatorJob.cancelTask()
|
||||
|
||||
val interval = (newValue as String).toInt()
|
||||
if (interval > 0) {
|
||||
BackupCreatorJob.setupTask(interval)
|
||||
}
|
||||
BackupCreatorJob.setupTask(interval)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -86,13 +86,8 @@ class SettingsLibraryController : SettingsController() {
|
||||
summary = "%s"
|
||||
|
||||
onChange { newValue ->
|
||||
// Always cancel the previous task, it seems that sometimes they are not updated.
|
||||
LibraryUpdateJob.cancelTask()
|
||||
|
||||
val interval = (newValue as String).toInt()
|
||||
if (interval > 0) {
|
||||
LibraryUpdateJob.setupTask(interval)
|
||||
}
|
||||
LibraryUpdateJob.setupTask(interval)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user