Albirew/tachiyomi
Archivé
1
0
Bifurcation 0

Pass context to get WorkManager instance

Cette révision appartient à :
arkon 2020-03-07 13:00:58 -05:00
Parent 52434819c3
révision 8b6268966e
7 fichiers modifiés avec 19 ajouts et 19 suppressions

Voir le fichier

@ -23,11 +23,11 @@ object Migrations {
if (oldVersion == 0) return false
if (oldVersion < 14) {
// Restore jobs after upgrading to evernote's job scheduler.
// Restore jobs after upgrading to Evernote's job scheduler.
if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) {
UpdaterJob.setupTask()
UpdaterJob.setupTask(context)
}
LibraryUpdateJob.setupTask()
LibraryUpdateJob.setupTask(context)
}
if (oldVersion < 15) {
// Delete internal chapter cache dir.
@ -39,7 +39,7 @@ object Migrations {
if (oldDir.exists()) {
val destDir = context.getExternalFilesDir("covers")
if (destDir != null) {
oldDir.listFiles().forEach {
oldDir.listFiles()?.forEach {
it.renameTo(File(destDir, it.name))
}
}

Voir le fichier

@ -28,7 +28,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
companion object {
const val TAG = "BackupCreator"
fun setupTask(prefInterval: Int? = null) {
fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.backupInterval().getOrDefault()
if (interval > 0) {
@ -38,9 +38,9 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
.addTag(TAG)
.build()
WorkManager.getInstance().enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
} else {
WorkManager.getInstance().cancelAllWorkByTag(TAG)
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
}
}
}

Voir le fichier

@ -25,7 +25,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
companion object {
const val TAG = "LibraryUpdate"
fun setupTask(prefInterval: Int? = null) {
fun setupTask(context: Context, prefInterval: Int? = null) {
val preferences = Injekt.get<PreferencesHelper>()
val interval = prefInterval ?: preferences.libraryUpdateInterval().getOrDefault()
if (interval > 0) {
@ -48,9 +48,9 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
.setConstraints(constraints)
.build()
WorkManager.getInstance().enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
} else {
WorkManager.getInstance().cancelAllWorkByTag(TAG)
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
}
}
}

Voir le fichier

@ -57,7 +57,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
companion object {
const val TAG = "UpdateChecker"
fun setupTask() {
fun setupTask(context: Context) {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
@ -69,11 +69,11 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
.setConstraints(constraints)
.build()
WorkManager.getInstance().enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
WorkManager.getInstance(context).enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
}
fun cancelTask() {
WorkManager.getInstance().cancelAllWorkByTag(TAG)
fun cancelTask(context: Context) {
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
}
}
}

Voir le fichier

@ -62,9 +62,9 @@ class AboutController : SettingsController() {
onChange { newValue ->
val checked = newValue as Boolean
if (checked) {
UpdaterJob.setupTask()
UpdaterJob.setupTask(context)
} else {
UpdaterJob.cancelTask()
UpdaterJob.cancelTask(context)
}
true
}

Voir le fichier

@ -106,7 +106,7 @@ class SettingsBackupController : SettingsController() {
onChange { newValue ->
val interval = (newValue as String).toInt()
BackupCreatorJob.setupTask(interval)
BackupCreatorJob.setupTask(context, interval)
true
}
}

Voir le fichier

@ -87,7 +87,7 @@ class SettingsLibraryController : SettingsController() {
onChange { newValue ->
val interval = (newValue as String).toInt()
LibraryUpdateJob.setupTask(interval)
LibraryUpdateJob.setupTask(context, interval)
true
}
}
@ -103,7 +103,7 @@ class SettingsLibraryController : SettingsController() {
onChange {
// Post to event looper to allow the preference to be updated.
Handler().post { LibraryUpdateJob.setupTask() }
Handler().post { LibraryUpdateJob.setupTask(context) }
true
}
}