diff --git a/app/core/src/main/java/com/fsck/k9/K9.kt b/app/core/src/main/java/com/fsck/k9/K9.kt index ec786aacd..533819244 100644 --- a/app/core/src/main/java/com/fsck/k9/K9.kt +++ b/app/core/src/main/java/com/fsck/k9/K9.kt @@ -178,7 +178,8 @@ object K9 : KoinComponent { @JvmStatic val fontSizes = FontSizes() - private var backgroundOps = BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC + @JvmStatic + var backgroundOps = BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC private var animations = true @@ -301,22 +302,6 @@ object K9 : KoinComponent { updateLoggingStatus() } - @JvmStatic - fun getBackgroundOps(): BACKGROUND_OPS { - return backgroundOps - } - - @JvmStatic - fun setBackgroundOps(backgroundOps: BACKGROUND_OPS): Boolean { - val oldBackgroundOps = K9.backgroundOps - K9.backgroundOps = backgroundOps - return backgroundOps != oldBackgroundOps - } - - fun setBackgroundOps(backgroundOps: String): Boolean { - return setBackgroundOps(BACKGROUND_OPS.valueOf(backgroundOps)) - } - fun gesturesEnabled(): Boolean { return gesturesEnabled } @@ -703,12 +688,11 @@ object K9 : KoinComponent { isThreadedViewEnabled = storage.getBoolean("threadedView", true) fontSizes.load(storage) - try { - setBackgroundOps(BACKGROUND_OPS.valueOf( - storage.getString("backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name) - )) + backgroundOps = try { + val settingValue = storage.getString("backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name) + BACKGROUND_OPS.valueOf(settingValue) } catch (e: Exception) { - setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) + BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC } isColorizeMissingContactPictures = storage.getBoolean("colorizeMissingContactPictures", true) diff --git a/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt b/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt index 18b7c4396..5198f737c 100644 --- a/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt +++ b/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt @@ -26,7 +26,7 @@ class BootReceiver : CoreReceiver(), KoinComponent { //K9.setServicesEnabled(context, tmpWakeLockId); //tmpWakeLockId = null; } else if ("com.android.sync.SYNC_CONN_STATUS_CHANGED" == action) { - val bOps = K9.getBackgroundOps() + val bOps = K9.backgroundOps if (bOps == K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) { jobManager.scheduleAllMailJobs() } diff --git a/app/k9mail/src/main/java/com/fsck/k9/external/remotecontrol/RemoteControlService.java b/app/k9mail/src/main/java/com/fsck/k9/external/remotecontrol/RemoteControlService.java index 146277dce..0117a5d42 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/external/remotecontrol/RemoteControlService.java +++ b/app/k9mail/src/main/java/com/fsck/k9/external/remotecontrol/RemoteControlService.java @@ -13,7 +13,6 @@ import com.fsck.k9.K9.BACKGROUND_OPS; import com.fsck.k9.Preferences; import com.fsck.k9.R; import com.fsck.k9.job.K9JobManager; -import com.fsck.k9.preferences.Storage; import com.fsck.k9.preferences.StorageEditor; import com.fsck.k9.service.BootReceiver; import com.fsck.k9.service.CoreService; @@ -129,9 +128,12 @@ public class RemoteControlService extends CoreService { || K9RemoteControl.K9_BACKGROUND_OPERATIONS_NEVER.equals(backgroundOps) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_WHEN_CHECKED_AUTO_SYNC.equals(backgroundOps)) { BACKGROUND_OPS newBackgroundOps = BACKGROUND_OPS.valueOf(backgroundOps); - boolean needsReset = K9.setBackgroundOps(newBackgroundOps); - needsPushRestart |= needsReset; - needsReschedule |= needsReset; + BACKGROUND_OPS currentBackgroundOps = K9.getBackgroundOps(); + if (newBackgroundOps != currentBackgroundOps) { + K9.setBackgroundOps(newBackgroundOps); + needsPushRestart = true; + needsReschedule = true; + } } String theme = intent.getStringExtra(K9_THEME); diff --git a/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt b/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt index fdd7fd120..ad8f4330b 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt +++ b/app/ui/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt @@ -112,7 +112,7 @@ class GeneralSettingsDataStore( "splitview_mode" -> K9.splitViewMode.name "notification_quick_delete" -> K9.notificationQuickDeleteBehaviour.name "lock_screen_notification_visibility" -> K9.lockScreenNotificationVisibility.name - "background_ops" -> K9.getBackgroundOps().name + "background_ops" -> K9.backgroundOps.name "notification_hide_subject" -> K9.notificationHideSubject.name "quiet_time_starts" -> K9.quietTimeStarts "quiet_time_ends" -> K9.quietTimeEnds @@ -240,8 +240,8 @@ class GeneralSettingsDataStore( private fun setBackgroundOps(value: String) { val newBackgroundOps = K9.BACKGROUND_OPS.valueOf(value) - if (newBackgroundOps != K9.getBackgroundOps()) { - K9.setBackgroundOps(value) + if (newBackgroundOps != K9.backgroundOps) { + K9.backgroundOps = newBackgroundOps jobManager.scheduleAllMailJobs() } }