Commit f2cbc07a authored by Aayush Gupta's avatar Aayush Gupta
Browse files

updates: UpdatesManager: Store and pass applicationContext to WorkManager

getInstance() method has been deprecated

References:
- [1]: https://developer.android.com/reference/androidx/work/WorkManager.html#getInstance()

Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent 68c5e07b
......@@ -26,7 +26,7 @@ import foundation.e.apps.updates.model.UpdatesWorker
import foundation.e.apps.utils.Constants
import java.util.concurrent.TimeUnit
class UpdatesManager(applicationContext: Context) {
class UpdatesManager(private val applicationContext: Context) {
private val TAG = "UpdatesManager"
private var automaticUpdateInterval: Int
......@@ -53,7 +53,7 @@ class UpdatesManager(applicationContext: Context) {
fun startWorker() {
Log.i(TAG, "UpdatesWorker interval: ${automaticUpdateInterval.toLong()} hours")
WorkManager.getInstance().enqueueUniquePeriodicWork(Constants.UPDATES_WORK_NAME,
WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(Constants.UPDATES_WORK_NAME,
ExistingPeriodicWorkPolicy.KEEP, getPeriodicWorkRequest())
Log.i(TAG, "UpdatesWorker started")
}
......@@ -61,7 +61,7 @@ class UpdatesManager(applicationContext: Context) {
fun replaceWorker(automaticUpdateInterval: Int) {
this.automaticUpdateInterval = automaticUpdateInterval
Log.i(TAG, "UpdatesWorker interval: ${automaticUpdateInterval.toLong()} hours")
WorkManager.getInstance().enqueueUniquePeriodicWork(Constants.UPDATES_WORK_NAME,
WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(Constants.UPDATES_WORK_NAME,
ExistingPeriodicWorkPolicy.REPLACE, getPeriodicWorkRequest())
Log.i(TAG, "UpdatesWorker started")
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment