diff --git a/app/src/main/java/io/timelimit/android/logic/AppSetupLogic.kt b/app/src/main/java/io/timelimit/android/logic/AppSetupLogic.kt index 696049a..034943c 100644 --- a/app/src/main/java/io/timelimit/android/logic/AppSetupLogic.kt +++ b/app/src/main/java/io/timelimit/android/logic/AppSetupLogic.kt @@ -251,7 +251,8 @@ class AppSetupLogic(private val appLogic: AppLogic) { if (server.hasAuthToken) { ReportUninstallWorker.enqueue( deviceAuthToken = server.deviceAuthToken, - customServerUrl = server.customServerUrl + customServerUrl = server.customServerUrl, + context = appLogic.context ) } @@ -267,8 +268,8 @@ class AppSetupLogic(private val appLogic: AppLogic) { // delete the old config DatabaseBackup.with(appLogic.context).tryCreateDatabaseBackupAsync() - PeriodicSyncInBackgroundWorker.disable() - CheckUpdateWorker.deschedule() + PeriodicSyncInBackgroundWorker.disable(appLogic.context) + CheckUpdateWorker.deschedule(appLogic.context) } suspend fun dangerousRemoteReset() { diff --git a/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt b/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt index 35c04ae..fb139e6 100644 --- a/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt +++ b/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt @@ -99,9 +99,9 @@ class BackgroundTaskLogic(val appLogic: AppLogic) { appLogic.database.config().getEnableBackgroundSyncAsync().ignoreUnchanged().observeForever { if (it) { - PeriodicSyncInBackgroundWorker.enable() + PeriodicSyncInBackgroundWorker.enable(appLogic.context) } else { - PeriodicSyncInBackgroundWorker.disable() + PeriodicSyncInBackgroundWorker.disable(appLogic.context) } } diff --git a/app/src/main/java/io/timelimit/android/sync/SyncUtil.kt b/app/src/main/java/io/timelimit/android/sync/SyncUtil.kt index b9feea9..5ca4833 100644 --- a/app/src/main/java/io/timelimit/android/sync/SyncUtil.kt +++ b/app/src/main/java/io/timelimit/android/sync/SyncUtil.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2021 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -121,7 +121,7 @@ class SyncUtil (private val logic: AppLogic) { lastSync.value = logic.timeApi.getCurrentUptimeInMillis() - SyncInBackgroundWorker.deschedule() + SyncInBackgroundWorker.deschedule(logic.context) lastSyncExceptionInternal.postValue(null) // wait 2 to 3 seconds before any next sync (debounce) @@ -150,7 +150,7 @@ class SyncUtil (private val logic: AppLogic) { importantSyncRequested.postValue(true) if (enqueueIfOffline) { - SyncInBackgroundWorker.enqueueDelayed() + SyncInBackgroundWorker.enqueueDelayed(logic.context) } } diff --git a/app/src/main/java/io/timelimit/android/ui/manage/device/manage/advanced/ManageDeviceBackgroundSync.kt b/app/src/main/java/io/timelimit/android/ui/manage/device/manage/advanced/ManageDeviceBackgroundSync.kt index e3bd850..ed7a005 100644 --- a/app/src/main/java/io/timelimit/android/ui/manage/device/manage/advanced/ManageDeviceBackgroundSync.kt +++ b/app/src/main/java/io/timelimit/android/ui/manage/device/manage/advanced/ManageDeviceBackgroundSync.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2020 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,8 @@ object ManageDeviceBackgroundSync { activityViewModel: ActivityViewModel, fragmentManager: FragmentManager ) { + val context = view.root.context + view.titleView.setOnClickListener { HelpDialogFragment.newInstance( title = R.string.device_background_sync_title, @@ -56,9 +58,9 @@ object ManageDeviceBackgroundSync { // for some reason, the observing of the config value does not work correctly -> do it manually here if (isChecked) { - PeriodicSyncInBackgroundWorker.enable() + PeriodicSyncInBackgroundWorker.enable(context) } else { - PeriodicSyncInBackgroundWorker.disable() + PeriodicSyncInBackgroundWorker.disable(context) } } else { view.checkbox.isChecked = enable diff --git a/app/src/main/java/io/timelimit/android/ui/setup/parent/SetupParentModeModel.kt b/app/src/main/java/io/timelimit/android/ui/setup/parent/SetupParentModeModel.kt index 3747221..57038c8 100644 --- a/app/src/main/java/io/timelimit/android/ui/setup/parent/SetupParentModeModel.kt +++ b/app/src/main/java/io/timelimit/android/ui/setup/parent/SetupParentModeModel.kt @@ -123,7 +123,7 @@ class SetupParentModeModel(application: Application): AndroidViewModel(applicati DatabaseBackup.with(getApplication()).tryCreateDatabaseBackupAsync() if (enableBackgroundSync) { - PeriodicSyncInBackgroundWorker.enable() + PeriodicSyncInBackgroundWorker.enable(getApplication()) } UpdateUtil.setEnableChecks(getApplication(), enableUpdateChecks) @@ -194,7 +194,7 @@ class SetupParentModeModel(application: Application): AndroidViewModel(applicati DatabaseBackup.with(getApplication()).tryCreateDatabaseBackupAsync() if (enableBackgroundSync) { - PeriodicSyncInBackgroundWorker.enable() + PeriodicSyncInBackgroundWorker.enable(getApplication()) } UpdateUtil.setEnableChecks(getApplication(), enableUpdateChecks) diff --git a/app/src/main/java/io/timelimit/android/update/UpdateUtil.kt b/app/src/main/java/io/timelimit/android/update/UpdateUtil.kt index fb23510..3bf991b 100644 --- a/app/src/main/java/io/timelimit/android/update/UpdateUtil.kt +++ b/app/src/main/java/io/timelimit/android/update/UpdateUtil.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2020 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +48,7 @@ object UpdateUtil { database.config().setUpdatesEnabledSync(true) } - CheckUpdateWorker.schedule() + CheckUpdateWorker.schedule(context) } fun disableChecks(context: Context) { @@ -58,7 +58,7 @@ object UpdateUtil { database.config().setUpdatesEnabledSync(false) } - CheckUpdateWorker.deschedule() + CheckUpdateWorker.deschedule(context) } suspend fun doUpdateCheck(context: Context, database: Database, enableNotifications: Boolean): Boolean { diff --git a/app/src/main/java/io/timelimit/android/work/CheckUpdateWorker.kt b/app/src/main/java/io/timelimit/android/work/CheckUpdateWorker.kt index be11766..ff560db 100644 --- a/app/src/main/java/io/timelimit/android/work/CheckUpdateWorker.kt +++ b/app/src/main/java/io/timelimit/android/work/CheckUpdateWorker.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2020 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,8 +27,8 @@ class CheckUpdateWorker(private val context: Context, workerParameters: WorkerPa companion object { private const val UNIQUE_WORK_NAME = "CheckUpdateWorker" - fun schedule() { - WorkManager.getInstance().enqueueUniquePeriodicWork( + fun schedule(context: Context) { + WorkManager.getInstance(context).enqueueUniquePeriodicWork( UNIQUE_WORK_NAME, ExistingPeriodicWorkPolicy.KEEP, PeriodicWorkRequestBuilder(1, TimeUnit.DAYS) @@ -42,8 +42,8 @@ class CheckUpdateWorker(private val context: Context, workerParameters: WorkerPa ) } - fun deschedule() { - WorkManager.getInstance().cancelUniqueWork(UNIQUE_WORK_NAME) + fun deschedule(context: Context) { + WorkManager.getInstance(context).cancelUniqueWork(UNIQUE_WORK_NAME) } } diff --git a/app/src/main/java/io/timelimit/android/work/PeriodicSyncInBackgroundWorker.kt b/app/src/main/java/io/timelimit/android/work/PeriodicSyncInBackgroundWorker.kt index b3df3ff..2b40158 100644 --- a/app/src/main/java/io/timelimit/android/work/PeriodicSyncInBackgroundWorker.kt +++ b/app/src/main/java/io/timelimit/android/work/PeriodicSyncInBackgroundWorker.kt @@ -1,3 +1,18 @@ +/* + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package io.timelimit.android.work import android.content.Context @@ -15,12 +30,12 @@ class PeriodicSyncInBackgroundWorker(private val context: Context, workerParamet private const val LOG_TAG = "PeriodicBackgroundSync" private const val UNIQUE_WORK_NAME = "PeriodicSyncInBackgroundWorker" - fun enable() { + fun enable(context: Context) { if (BuildConfig.DEBUG) { Log.d(LOG_TAG, "enable()") } - WorkManager.getInstance().enqueueUniquePeriodicWork( + WorkManager.getInstance(context).enqueueUniquePeriodicWork( UNIQUE_WORK_NAME, ExistingPeriodicWorkPolicy.KEEP, PeriodicWorkRequestBuilder(1, TimeUnit.HOURS) @@ -34,12 +49,12 @@ class PeriodicSyncInBackgroundWorker(private val context: Context, workerParamet ) } - fun disable() { + fun disable(context: Context) { if (BuildConfig.DEBUG) { Log.d(LOG_TAG, "disable()") } - WorkManager.getInstance().cancelUniqueWork(UNIQUE_WORK_NAME) + WorkManager.getInstance(context).cancelUniqueWork(UNIQUE_WORK_NAME) } } diff --git a/app/src/main/java/io/timelimit/android/work/ReportUninstallWorker.kt b/app/src/main/java/io/timelimit/android/work/ReportUninstallWorker.kt index 7d9f9ff..a435eb2 100644 --- a/app/src/main/java/io/timelimit/android/work/ReportUninstallWorker.kt +++ b/app/src/main/java/io/timelimit/android/work/ReportUninstallWorker.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2021 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ class ReportUninstallWorker(val context: Context, workerParameters: WorkerParame private const val DATA_CUSTOM_SERVER_URL = "customServerUrl" private const val LOG_TAG = "ReportUninstallWorker" - fun enqueue(deviceAuthToken: String, customServerUrl: String) { + fun enqueue(deviceAuthToken: String, customServerUrl: String, context: Context) { if (deviceAuthToken.isEmpty()) { return } @@ -40,7 +40,7 @@ class ReportUninstallWorker(val context: Context, workerParameters: WorkerParame Log.d(LOG_TAG, "enqueue()") } - WorkManager.getInstance().enqueue( + WorkManager.getInstance(context).enqueue( OneTimeWorkRequest.Builder(ReportUninstallWorker::class.java) .setConstraints( Constraints.Builder() diff --git a/app/src/main/java/io/timelimit/android/work/SyncInBackgroundWorker.kt b/app/src/main/java/io/timelimit/android/work/SyncInBackgroundWorker.kt index cb26855..7036b0e 100644 --- a/app/src/main/java/io/timelimit/android/work/SyncInBackgroundWorker.kt +++ b/app/src/main/java/io/timelimit/android/work/SyncInBackgroundWorker.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2021 Jonas Lochmann + * TimeLimit Copyright 2019 - 2022 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,12 +34,12 @@ class SyncInBackgroundWorker(val context: Context, workerParameters: WorkerParam private const val LOG_TAG = "SyncInBackground" private const val UNIQUE_WORK_NAME = "SyncInBackgroundWork" - fun enqueueDelayed() { + fun enqueueDelayed(context: Context) { if (BuildConfig.DEBUG) { Log.d(LOG_TAG, "enqueueDelayed") } - WorkManager.getInstance().beginUniqueWork( + WorkManager.getInstance(context).beginUniqueWork( UNIQUE_WORK_NAME, ExistingWorkPolicy.KEEP, OneTimeWorkRequest.Builder(SyncInBackgroundWorker::class.java) @@ -54,8 +54,8 @@ class SyncInBackgroundWorker(val context: Context, workerParameters: WorkerParam ).enqueue() } - fun deschedule() { - WorkManager.getInstance().cancelUniqueWork(UNIQUE_WORK_NAME) + fun deschedule(context: Context) { + WorkManager.getInstance(context).cancelUniqueWork(UNIQUE_WORK_NAME) } }