From bb3168cdb14701d473c5ebe14d2c346d58c0d650 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 3 Jul 2021 20:13:50 -0400 Subject: [PATCH] Using context for workmanager been needing to --- .../java/eu/kanade/tachiyomi/Migrations.kt | 20 +++++++++---------- .../tachiyomi/data/backup/BackupCreatorJob.kt | 4 ++-- .../data/library/LibraryUpdateJob.kt | 6 +++--- .../DelayedLibrarySuggestionsJob.kt | 6 +++--- .../tachiyomi/data/updater/UpdaterJob.kt | 8 ++++---- .../tachiyomi/extension/ExtensionUpdateJob.kt | 6 +++--- .../ui/category/ManageCategoryDialog.kt | 2 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../ui/setting/SettingsBrowseController.kt | 2 +- .../ui/setting/SettingsLibraryController.kt | 8 ++++---- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 4b81a171c4..966b620644 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -34,19 +34,19 @@ object Migrations { if (oldVersion == 0) { if (BuildConfig.INCLUDE_UPDATER) { - UpdaterJob.setupTask() + UpdaterJob.setupTask(context) } - ExtensionUpdateJob.setupTask() - LibraryUpdateJob.setupTask() + ExtensionUpdateJob.setupTask(context) + LibraryUpdateJob.setupTask(context) return BuildConfig.DEBUG } if (oldVersion < 14) { // Restore jobs after upgrading to evernote's job scheduler. if (BuildConfig.INCLUDE_UPDATER) { - UpdaterJob.setupTask() + UpdaterJob.setupTask(context) } - LibraryUpdateJob.setupTask() + LibraryUpdateJob.setupTask(context) } if (oldVersion < 15) { // Delete internal chapter cache dir. @@ -81,11 +81,11 @@ object Migrations { LibraryPresenter.updateDB() // Restore jobs after migrating from Evernote's job scheduler to WorkManager. if (BuildConfig.INCLUDE_UPDATER) { - UpdaterJob.setupTask() + UpdaterJob.setupTask(context) } - LibraryUpdateJob.setupTask() + LibraryUpdateJob.setupTask(context) BackupCreatorJob.setupTask(context) - ExtensionUpdateJob.setupTask() + ExtensionUpdateJob.setupTask(context) } if (oldVersion < 66) { LibraryPresenter.updateCustoms() @@ -118,7 +118,7 @@ object Migrations { if (oldVersion < 74) { // Turn on auto updates for all users if (BuildConfig.INCLUDE_UPDATER) { - UpdaterJob.setupTask() + UpdaterJob.setupTask(context) } } if (oldVersion < 75) { @@ -138,7 +138,7 @@ object Migrations { val updateInterval = preferences.libraryUpdateInterval().get() if (updateInterval == 1 || updateInterval == 2) { preferences.libraryUpdateInterval().set(3) - LibraryUpdateJob.setupTask(3) + LibraryUpdateJob.setupTask(context, 3) } } return true 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 81df6a7601..cb726c5fbb 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 @@ -48,9 +48,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 3587ddc189..26189000c2 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 { private 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) { @@ -52,9 +52,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/preference/DelayedLibrarySuggestionsJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/DelayedLibrarySuggestionsJob.kt index 91c8f08b44..fb78e85319 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/DelayedLibrarySuggestionsJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/DelayedLibrarySuggestionsJob.kt @@ -26,16 +26,16 @@ class DelayedLibrarySuggestionsJob(context: Context, workerParams: WorkerParamet companion object { private const val TAG = "DelayedLibrarySuggestions" - fun setupTask(enabled: Boolean) { + fun setupTask(context: Context, enabled: Boolean) { if (enabled) { val request = OneTimeWorkRequestBuilder() .setInitialDelay(1, TimeUnit.DAYS) .addTag(TAG) .build() - WorkManager.getInstance().enqueueUniqueWork(TAG, ExistingWorkPolicy.KEEP, request) + WorkManager.getInstance(context).enqueueUniqueWork(TAG, ExistingWorkPolicy.KEEP, 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 0d59bb1c8a..41f9129081 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 @@ -41,7 +41,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) : companion object { private const val TAG = "UpdateChecker" - fun setupTask() { + fun setupTask(context: Context) { val constraints = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build() @@ -56,11 +56,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/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 795ac690d4..8075c1ca0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -75,7 +75,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam companion object { private const val TAG = "ExtensionUpdate" - fun setupTask(forceAutoUpdateJob: Boolean? = null) { + fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { val preferences = Injekt.get() val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().getOrDefault() if (autoUpdateJob) { @@ -93,9 +93,9 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam .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/ui/category/ManageCategoryDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt index b98e750660..fbf7c74672 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/ManageCategoryDialog.kt @@ -106,7 +106,7 @@ class ManageCategoryDialog(bundle: Bundle? = null) : updatePref(preferences.libraryUpdateCategories(), binding.includeGlobal) == false ) { preferences.libraryUpdateInterval().set(0) - LibraryUpdateJob.setupTask(0) + LibraryUpdateJob.setupTask(preferences.context, 0) } updateLibrary?.invoke(category.id) return true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 3030b3b8a1..320870a7a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -108,7 +108,7 @@ class LibraryPresenter( lastLibraryItems = null getLibrary() if (preferences.showLibrarySearchSuggestions().isNotSet()) { - DelayedLibrarySuggestionsJob.setupTask(true) + DelayedLibrarySuggestionsJob.setupTask(context, true) } else if (preferences.showLibrarySearchSuggestions().get() && Date().time >= preferences.lastLibrarySuggestion().get() + TimeUnit.HOURS.toMillis(2) ) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index 3a6bef597b..c89f55b6aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -30,7 +30,7 @@ class SettingsBrowseController : SettingsController() { onChange { it as Boolean - ExtensionUpdateJob.setupTask(it) + ExtensionUpdateJob.setupTask(context, it) 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 dd57eda4dd..6b19f4b09b 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 @@ -43,7 +43,7 @@ class SettingsLibraryController : SettingsController() { LibraryPresenter.setSearchSuggestion(preferences, db, Injekt.get()) } } else { - DelayedLibrarySuggestionsJob.setupTask(false) + DelayedLibrarySuggestionsJob.setupTask(context, false) preferences.librarySearchSuggestion().set("") } true @@ -115,11 +115,11 @@ class SettingsLibraryController : SettingsController() { onChange { newValue -> // Always cancel the previous task, it seems that sometimes they are not updated. - LibraryUpdateJob.setupTask(0) + LibraryUpdateJob.setupTask(context, 0) val interval = newValue as Int if (interval > 0) { - LibraryUpdateJob.setupTask(interval) + LibraryUpdateJob.setupTask(context, interval) } true } @@ -136,7 +136,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 } }