Skip to content

Commit eea9b1c

Browse files
authored
refactor: use PreferenceDataStore for notificationQuickDeleteBehaviour (#10422)
2 parents 99ab6fe + 891c0b5 commit eea9b1c

14 files changed

Lines changed: 92 additions & 41 deletions

File tree

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/GeneralSettings.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ enum class SplitViewMode {
6464
WHEN_IN_LANDSCAPE,
6565
WHEN_UNFOLDED,
6666
}
67+
68+
/**
69+
* Controls behaviour of delete button in notifications.
70+
*/
71+
enum class NotificationQuickDelete {
72+
ALWAYS,
73+
FOR_SINGLE_MSG,
74+
NEVER,
75+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package net.thunderbird.core.preference.notification
22

3+
import net.thunderbird.core.preference.NotificationQuickDelete
4+
35
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_QUIET_TIME_ENABLED = false
46
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_STARTS = "21:00"
57
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END = "7:00"
68
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED = true
9+
val NOTIFICATION_PREFERENCE_DEFAULT_QUICK_DELETE_BEHAVIOUR = NotificationQuickDelete.ALWAYS
710

811
data class NotificationPreference(
912
val isQuietTimeEnabled: Boolean = NOTIFICATION_PREFERENCE_DEFAULT_IS_QUIET_TIME_ENABLED,
1013
val quietTimeStarts: String = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_STARTS,
1114
val quietTimeEnds: String = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END,
1215
val isNotificationDuringQuietTimeEnabled: Boolean =
1316
NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
17+
val notificationQuickDeleteBehaviour: NotificationQuickDelete =
18+
NOTIFICATION_PREFERENCE_DEFAULT_QUICK_DELETE_BEHAVIOUR,
1419
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ const val KEY_QUIET_TIME_STARTS = "quietTimeStarts"
77
const val KEY_QUIET_TIME_ENABLED = "quietTimeEnabled"
88
const val KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED = "notificationDuringQuietTimeEnabled"
99

10+
const val KEY_NOTIFICATION_QUICK_DELETE_BEHAVIOUR = "notificationQuickDelete"
11+
1012
interface NotificationPreferenceManager : PreferenceManager<NotificationPreference>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import net.thunderbird.core.logging.Logger
1414
import net.thunderbird.core.preference.storage.Storage
1515
import net.thunderbird.core.preference.storage.StorageEditor
1616
import net.thunderbird.core.preference.storage.StoragePersister
17+
import net.thunderbird.core.preference.storage.getEnumOrDefault
18+
import net.thunderbird.core.preference.storage.putEnum
1719

1820
private const val TAG = "DefaultNotificationPreferenceManager"
1921

@@ -45,6 +47,10 @@ class DefaultNotificationPreferenceManager(
4547
key = KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
4648
defValue = NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
4749
),
50+
notificationQuickDeleteBehaviour = storage.getEnumOrDefault(
51+
key = KEY_NOTIFICATION_QUICK_DELETE_BEHAVIOUR,
52+
default = NOTIFICATION_PREFERENCE_DEFAULT_QUICK_DELETE_BEHAVIOUR,
53+
),
4854
),
4955
)
5056

@@ -65,6 +71,10 @@ class DefaultNotificationPreferenceManager(
6571
KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
6672
config.isNotificationDuringQuietTimeEnabled,
6773
)
74+
storageEditor.putEnum(
75+
KEY_NOTIFICATION_QUICK_DELETE_BEHAVIOUR,
76+
config.notificationQuickDeleteBehaviour,
77+
)
6878
storageEditor.commit().also { commited ->
6979
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
7080
}

feature/mail/message/list/internal/src/test/kotlin/net/thunderbird/feature/mail/message/list/internal/ui/state/sideeffect/LoadPreferencesSideEffectTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dev.mokkery.mock
88
import dev.mokkery.spy
99
import dev.mokkery.verify
1010
import dev.mokkery.verify.VerifyMode
11-
import kotlin.random.Random
1211
import kotlin.test.Test
1312
import kotlinx.collections.immutable.ImmutableSet
1413
import kotlinx.collections.immutable.persistentSetOf
@@ -112,14 +111,14 @@ class LoadPreferencesSideEffectTest {
112111

113112
// Act
114113
testSubject.handle(oldState, newState)
115-
repeat(times = 10) {
114+
repeat(times = 10) { index ->
116115
fakeGetMessageListPreferences.emit(
117116
preferences = createMessageListPreferences(
118-
density = UiDensity.entries.random(),
119-
showMessageAvatar = Random.nextBoolean(),
120-
showFavouriteButton = Random.nextBoolean(),
121-
senderAboveSubject = Random.nextBoolean(),
122-
colorizeBackgroundWhenRead = Random.nextBoolean(),
117+
density = UiDensity.entries[index % UiDensity.entries.size],
118+
showMessageAvatar = index % 2 == 0,
119+
showFavouriteButton = index % 3 == 0,
120+
senderAboveSubject = index % 4 == 0,
121+
colorizeBackgroundWhenRead = index % 5 == 0,
123122
),
124123
)
125124
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ object K9 : KoinComponent {
113113
@JvmStatic
114114
val fontSizes = FontSizes()
115115

116-
@JvmStatic
117-
var notificationQuickDeleteBehaviour = NotificationQuickDelete.ALWAYS
118-
119116
@JvmStatic
120117
var lockScreenNotificationVisibility = LockScreenNotificationVisibility.MESSAGE_COUNT
121118

@@ -205,8 +202,6 @@ object K9 : KoinComponent {
205202
val sortAscendingSetting = storage.getBoolean("sortAscending", AccountDefaultsProvider.DEFAULT_SORT_ASCENDING)
206203
sortAscending[sortType] = sortAscendingSetting
207204

208-
notificationQuickDeleteBehaviour = storage.getEnum("notificationQuickDelete", NotificationQuickDelete.ALWAYS)
209-
210205
lockScreenNotificationVisibility = storage.getEnum(
211206
"lockScreenNotificationVisibility",
212207
LockScreenNotificationVisibility.MESSAGE_COUNT,
@@ -241,8 +236,6 @@ object K9 : KoinComponent {
241236

242237
editor.putEnum("sortTypeEnum", sortType)
243238
editor.putBoolean("sortAscending", sortAscending[sortType] ?: false)
244-
245-
editor.putString("notificationQuickDelete", notificationQuickDeleteBehaviour.toString())
246239
editor.putString("lockScreenNotificationVisibility", lockScreenNotificationVisibility.toString())
247240

248241
editor.putBoolean("messageViewArchiveActionVisible", isMessageViewArchiveActionVisible)
@@ -302,15 +295,6 @@ object K9 : KoinComponent {
302295

303296
const val MANUAL_WAKE_LOCK_TIMEOUT = 120000
304297

305-
/**
306-
* Controls behaviour of delete button in notifications.
307-
*/
308-
enum class NotificationQuickDelete {
309-
ALWAYS,
310-
FOR_SINGLE_MSG,
311-
NEVER,
312-
}
313-
314298
enum class LockScreenNotificationVisibility {
315299
EVERYTHING,
316300
SENDERS,

legacy/core/src/main/java/com/fsck/k9/notification/CoreNotificationKoinModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ val coreNotificationModule = module {
9999
)
100100
}
101101
factory { BaseNotificationDataCreator() }
102-
factory { SingleMessageNotificationDataCreator(get()) }
102+
factory { SingleMessageNotificationDataCreator(interactionPreferences = get(), notificationPreference = get()) }
103103
factory {
104104
SummaryNotificationDataCreator(
105105
singleMessageNotificationDataCreator = get(),

legacy/core/src/main/java/com/fsck/k9/notification/SingleMessageNotificationDataCreator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.fsck.k9.notification
22

3-
import com.fsck.k9.K9
43
import net.thunderbird.core.android.account.LegacyAccountDto
4+
import net.thunderbird.core.preference.NotificationQuickDelete
55
import net.thunderbird.core.preference.interaction.InteractionSettingsPreferenceManager
6+
import net.thunderbird.core.preference.notification.NotificationPreferenceManager
67

78
internal class SingleMessageNotificationDataCreator(
89
private val interactionPreferences: InteractionSettingsPreferenceManager,
10+
private val notificationPreference: NotificationPreferenceManager,
911
) {
1012

1113
private val interactionSettings get() = interactionPreferences.getConfig()
14+
private val notificationSettings get() = notificationPreference.getConfig()
1215

1316
fun createSingleNotificationData(
1417
account: LegacyAccountDto,
@@ -77,7 +80,7 @@ internal class SingleMessageNotificationDataCreator(
7780
}
7881

7982
private fun isDeleteActionEnabled(): Boolean {
80-
return K9.notificationQuickDeleteBehaviour != K9.NotificationQuickDelete.NEVER
83+
return notificationSettings.notificationQuickDeleteBehaviour != NotificationQuickDelete.NEVER
8184
}
8285

8386
// We don't support confirming actions on Wear devices. So don't show the action when confirmation is enabled.

legacy/core/src/main/java/com/fsck/k9/notification/SummaryNotificationDataCreator.kt

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

3-
import com.fsck.k9.K9
43
import net.thunderbird.core.android.account.LegacyAccountDto
54
import net.thunderbird.core.preference.GeneralSettingsManager
5+
import net.thunderbird.core.preference.NotificationQuickDelete
66

77
private const val MAX_NUMBER_OF_MESSAGES_FOR_SUMMARY_NOTIFICATION = 5
88

@@ -72,7 +72,8 @@ internal class SummaryNotificationDataCreator(
7272
}
7373

7474
private fun isDeleteActionEnabled(): Boolean {
75-
return K9.notificationQuickDeleteBehaviour == K9.NotificationQuickDelete.ALWAYS
75+
return generalSettingsManager.getConfig().notification.notificationQuickDeleteBehaviour ==
76+
NotificationQuickDelete.ALWAYS
7677
}
7778

7879
// We don't support confirming actions on Wear devices. So don't show the action when confirmation is enabled.

legacy/core/src/main/java/com/fsck/k9/preferences/GeneralSettingsDescriptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import app.k9mail.feature.telemetry.api.TelemetryManager;
1313
import app.k9mail.legacy.di.DI;
1414
import com.fsck.k9.FontSizes;
15-
import com.fsck.k9.K9.NotificationQuickDelete;
1615
import com.fsck.k9.K9.PostMarkAsUnreadNavigation;
1716
import com.fsck.k9.core.R;
1817
import com.fsck.k9.preferences.Settings.BooleanSetting;
@@ -38,6 +37,7 @@
3837
import net.thunderbird.core.preference.BackgroundOps;
3938
import net.thunderbird.core.preference.GeneralSettingsManager;
4039
import net.thunderbird.core.preference.BodyContentType;
40+
import net.thunderbird.core.preference.NotificationQuickDelete;
4141
import net.thunderbird.core.preference.SplitViewMode;
4242
import net.thunderbird.core.preference.SubTheme;
4343
import net.thunderbird.core.preference.display.coreSettings.DisplayCoreSettingsKt;

0 commit comments

Comments
 (0)