From 8b6268966efc7ff2c24e3d7e6176ea524a02d206 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 Mar 2020 13:00:58 -0500 Subject: [PATCH] Pass context to get WorkManager instance --- app/src/main/java/eu/kanade/tachiyomi/Migrations.kt | 8 ++++---- .../eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt | 6 +++--- .../eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt | 6 +++--- .../java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt | 8 ++++---- .../java/eu/kanade/tachiyomi/ui/more/AboutController.kt | 4 ++-- .../tachiyomi/ui/setting/SettingsBackupController.kt | 2 +- .../tachiyomi/ui/setting/SettingsLibraryController.kt | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index a965abba6..6b7f30fd7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -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)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt index 81a5c16cc..512c3fb69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt @@ -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() 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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index e1dced1ef..869d8f20f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -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() 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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt index b0c6e9e07..deb37f2bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt @@ -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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 6fc24d73a..257332970 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index a5e738ef8..a683895a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -106,7 +106,7 @@ class SettingsBackupController : SettingsController() { onChange { newValue -> val interval = (newValue as String).toInt() - BackupCreatorJob.setupTask(interval) + BackupCreatorJob.setupTask(context, interval) true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 6f7876292..42230a02a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -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 } }