mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 17:31:52 +01:00
Pass context to get WorkManager instance
This commit is contained in:
parent
52434819c3
commit
8b6268966e
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class SettingsBackupController : SettingsController() {
|
||||
|
||||
onChange { newValue ->
|
||||
val interval = (newValue as String).toInt()
|
||||
BackupCreatorJob.setupTask(interval)
|
||||
BackupCreatorJob.setupTask(context, interval)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user