mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 03:39:19 +01:00
Using context for workmanager
been needing to
This commit is contained in:
parent
a3a4edbde0
commit
bb3168cdb1
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<PreferencesHelper>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<DelayedLibrarySuggestionsJob>()
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<PreferencesHelper>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
) {
|
||||
|
@ -30,7 +30,7 @@ class SettingsBrowseController : SettingsController() {
|
||||
|
||||
onChange {
|
||||
it as Boolean
|
||||
ExtensionUpdateJob.setupTask(it)
|
||||
ExtensionUpdateJob.setupTask(context, it)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user