Skip to content

Commit 72b99a7

Browse files
committed
refactor: migrate K9.isNotificationDuringQuietTimeEnabled to PreferenceDataStore
1 parent 6804c60 commit 72b99a7

6 files changed

Lines changed: 29 additions & 9 deletions

File tree

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/notification/NotificationPreference.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package net.thunderbird.core.preference.notification
33
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_QUIET_TIME_ENABLED = false
44
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_STARTS = "21:00"
55
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END = "7:00"
6+
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED = true
67

78
data class NotificationPreference(
89
val isQuietTimeEnabled: Boolean = NOTIFICATION_PREFERENCE_DEFAULT_IS_QUIET_TIME_ENABLED,
910
val quietTimeStarts: String = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_STARTS,
1011
val quietTimeEnds: String = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END,
12+
val isNotificationDuringQuietTimeEnabled: Boolean =
13+
NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
1114
)

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/notification/NotificationPreferenceManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import net.thunderbird.core.preference.PreferenceManager
55
const val KEY_QUIET_TIME_ENDS = "quietTimeEnds"
66
const val KEY_QUIET_TIME_STARTS = "quietTimeStarts"
77
const val KEY_QUIET_TIME_ENABLED = "quietTimeEnabled"
8+
const val KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED = "notificationDuringQuietTimeEnabled"
89

910
interface NotificationPreferenceManager : PreferenceManager<NotificationPreference>

core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/notification/DefaultNotificationPreferenceManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class DefaultNotificationPreferenceManager(
3838
key = KEY_QUIET_TIME_ENDS,
3939
defValue = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END,
4040
),
41+
isNotificationDuringQuietTimeEnabled = storage.getBoolean(
42+
key = KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
43+
defValue = NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
44+
),
4145
),
4246
)
4347

@@ -54,6 +58,10 @@ class DefaultNotificationPreferenceManager(
5458
KEY_QUIET_TIME_ENABLED,
5559
config.isQuietTimeEnabled,
5660
)
61+
storageEditor.putBoolean(
62+
KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
63+
config.isNotificationDuringQuietTimeEnabled,
64+
)
5765
storageEditor.commit().also { commited ->
5866
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
5967
}

legacy/common/src/main/java/com/fsck/k9/notification/K9NotificationStrategy.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.fsck.k9.notification
22

33
import app.k9mail.core.android.common.contact.ContactRepository
44
import app.k9mail.legacy.di.DI
5-
import com.fsck.k9.K9
65
import com.fsck.k9.QuietTimeChecker
76
import com.fsck.k9.mail.Flag
87
import com.fsck.k9.mail.K9MailLib
@@ -29,7 +28,9 @@ class K9NotificationStrategy(
2928
message: LocalMessage,
3029
isOldMessage: Boolean,
3130
): Boolean {
32-
if (!K9.isNotificationDuringQuietTimeEnabled && generalSettingsManager.getConfig().notification.isQuietTime) {
31+
if (!generalSettingsManager.getConfig().notification.isNotificationDuringQuietTimeEnabled &&
32+
generalSettingsManager.getConfig().notification.isQuietTime
33+
) {
3334
Log.v("No notification: Quiet time is active")
3435
return false
3536
}

legacy/core/src/main/java/com/fsck/k9/K9.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ object K9 : KoinComponent {
155155
@JvmStatic
156156
var isShowAccountSelector = true
157157

158-
var isNotificationDuringQuietTimeEnabled = true
159-
160158
@get:Synchronized
161159
@set:Synchronized
162160
@JvmStatic
@@ -237,8 +235,6 @@ object K9 : KoinComponent {
237235
isShowAccountSelector = storage.getBoolean("showAccountSelector", true)
238236
messageListPreviewLines = storage.getInt("messageListPreviewLines", 2)
239237

240-
isNotificationDuringQuietTimeEnabled = storage.getBoolean("notificationDuringQuietTimeEnabled", true)
241-
242238
messageListDensity = storage.getEnum("messageListDensity", UiDensity.Default)
243239
contactNameColor = storage.getInt("registeredNameColor", 0xFF1093F5.toInt())
244240
messageViewPostMarkAsUnreadNavigation =
@@ -296,7 +292,6 @@ object K9 : KoinComponent {
296292

297293
@Suppress("LongMethod")
298294
internal fun save(editor: StorageEditor) {
299-
editor.putBoolean("notificationDuringQuietTimeEnabled", isNotificationDuringQuietTimeEnabled)
300295
editor.putEnum("messageListDensity", messageListDensity)
301296
editor.putBoolean("showAccountSelector", isShowAccountSelector)
302297
editor.putInt("messageListPreviewLines", messageListPreviewLines)

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class GeneralSettingsDataStore(
6868
"quiet_time_enabled" -> generalSettingsManager.getConfig()
6969
.notification.isQuietTimeEnabled
7070

71-
"disable_notifications_during_quiet_time" -> !K9.isNotificationDuringQuietTimeEnabled
71+
"disable_notifications_during_quiet_time" -> !generalSettingsManager.getConfig()
72+
.notification.isNotificationDuringQuietTimeEnabled
7273
"privacy_hide_useragent" -> generalSettingsManager.getConfig().privacy.isHideUserAgent
7374
"privacy_hide_timezone" -> generalSettingsManager.getConfig().privacy.isHideTimeZone
7475
"debug_logging" -> generalSettingsManager.getConfig().debugging.isDebugLoggingEnabled
@@ -108,7 +109,7 @@ class GeneralSettingsDataStore(
108109
"messageview_fixedwidth_font" -> setIsUseMessageViewFixedWidthFont(isUseMessageViewFixedWidthFont = value)
109110
"messageview_autofit_width" -> setIsAutoFitWidth(isAutoFitWidth = value)
110111
"quiet_time_enabled" -> setIsQuietTimeEnabled(isQuietTimeEnabled = value)
111-
"disable_notifications_during_quiet_time" -> K9.isNotificationDuringQuietTimeEnabled = !value
112+
"disable_notifications_during_quiet_time" -> setIsNotificationDuringQuietTimeEnabled(!value)
112113
"privacy_hide_useragent" -> setIsHideUserAgent(isHideUserAgent = value)
113114
"privacy_hide_timezone" -> setIsHideTimeZone(isHideTimeZone = value)
114115
"debug_logging" -> setIsDebugLoggingEnabled(isDebugLoggingEnabled = value)
@@ -585,6 +586,17 @@ class GeneralSettingsDataStore(
585586
}
586587
}
587588

589+
private fun setIsNotificationDuringQuietTimeEnabled(isNotificationDuringQuietTimeEnabled: Boolean) {
590+
skipSaveSettings = true
591+
generalSettingsManager.update { settings ->
592+
settings.copy(
593+
notification = settings.notification.copy(
594+
isNotificationDuringQuietTimeEnabled = isNotificationDuringQuietTimeEnabled,
595+
),
596+
)
597+
}
598+
}
599+
588600
private fun setIsHideTimeZone(isHideTimeZone: Boolean) {
589601
skipSaveSettings = true
590602
generalSettingsManager.update { settings ->

0 commit comments

Comments
 (0)