Skip to content

Commit f1c6358

Browse files
committed
Unified to list handling directly
1 parent dd3de9d commit f1c6358

File tree

8 files changed

+40
-41
lines changed

8 files changed

+40
-41
lines changed

core/common/src/commonMain/kotlin/net/thunderbird/core/common/notification/NotificationActionTokens.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@ object NotificationActionTokens {
1111
const val ARCHIVE = "archive"
1212
const val SPAM = "spam"
1313

14-
const val DEFAULT_ORDER = "$REPLY,$MARK_AS_READ,$DELETE,$STAR,$ARCHIVE,$SPAM"
14+
val DEFAULT_ORDER: List<String> = listOf(REPLY, MARK_AS_READ, DELETE, STAR, ARCHIVE, SPAM)
15+
16+
fun parseOrder(raw: String): List<String> {
17+
return raw
18+
.split(',')
19+
.map { it.trim() }
20+
.filter { it.isNotEmpty() }
21+
}
22+
23+
fun serializeOrder(tokens: List<String>): String = tokens.joinToString(separator = ",")
1524
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const val NOTIFICATION_PREFERENCE_DEFAULT_IS_QUIET_TIME_ENABLED = false
77
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_STARTS = "21:00"
88
const val NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END = "7:00"
99
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED = true
10-
const val NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER = NotificationActionTokens.DEFAULT_ORDER
10+
val NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER = NotificationActionTokens.DEFAULT_ORDER
1111
const val NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_CUTOFF = 3
1212
const val NOTIFICATION_PREFERENCE_MAX_MESSAGE_ACTIONS_SHOWN = 3
1313
const val NOTIFICATION_PREFERENCE_DEFAULT_IS_SUMMARY_DELETE_ACTION_ENABLED = true
@@ -19,7 +19,7 @@ data class NotificationPreference(
1919
val quietTimeEnds: String = NOTIFICATION_PREFERENCE_DEFAULT_QUIET_TIME_END,
2020
val isNotificationDuringQuietTimeEnabled: Boolean =
2121
NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
22-
val messageActionsOrder: String = NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER,
22+
val messageActionsOrder: List<String> = NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER,
2323
val messageActionsCutoff: Int = NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_CUTOFF,
2424
val isSummaryDeleteActionEnabled: Boolean = NOTIFICATION_PREFERENCE_DEFAULT_IS_SUMMARY_DELETE_ACTION_ENABLED,
2525
val notificationQuickDeleteBehaviour: NotificationQuickDelete =

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.update
1010
import kotlinx.coroutines.launch
1111
import kotlinx.coroutines.sync.Mutex
1212
import kotlinx.coroutines.sync.withLock
13+
import net.thunderbird.core.common.notification.NotificationActionTokens
1314
import net.thunderbird.core.logging.Logger
1415
import net.thunderbird.core.preference.storage.Storage
1516
import net.thunderbird.core.preference.storage.StorageEditor
@@ -47,9 +48,13 @@ class DefaultNotificationPreferenceManager(
4748
key = KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
4849
defValue = NOTIFICATION_PREFERENCE_DEFAULT_IS_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
4950
),
50-
messageActionsOrder = storage.getStringOrDefault(
51-
key = KEY_MESSAGE_ACTIONS_ORDER,
52-
defValue = NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER,
51+
messageActionsOrder = NotificationActionTokens.parseOrder(
52+
storage.getStringOrDefault(
53+
key = KEY_MESSAGE_ACTIONS_ORDER,
54+
defValue = NotificationActionTokens.serializeOrder(
55+
NOTIFICATION_PREFERENCE_DEFAULT_MESSAGE_ACTIONS_ORDER,
56+
),
57+
),
5358
),
5459
messageActionsCutoff = storage.getInt(
5560
key = KEY_MESSAGE_ACTIONS_CUTOFF,
@@ -83,7 +88,10 @@ class DefaultNotificationPreferenceManager(
8388
KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED,
8489
config.isNotificationDuringQuietTimeEnabled,
8590
)
86-
storageEditor.putString(KEY_MESSAGE_ACTIONS_ORDER, config.messageActionsOrder)
91+
storageEditor.putString(
92+
KEY_MESSAGE_ACTIONS_ORDER,
93+
NotificationActionTokens.serializeOrder(config.messageActionsOrder),
94+
)
8795
storageEditor.putInt(KEY_MESSAGE_ACTIONS_CUTOFF, config.messageActionsCutoff)
8896
storageEditor.putBoolean(KEY_IS_SUMMARY_DELETE_ACTION_ENABLED, config.isSummaryDeleteActionEnabled)
8997
storageEditor.putEnum(

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ internal class SingleMessageNotificationDataCreator(
119119
return filled
120120
}
121121

122-
private fun parseActionsOrder(raw: String): List<NotificationAction> {
123-
val tokens = raw
124-
.split(',')
125-
.map { it.trim() }
126-
.filter { it.isNotEmpty() }
127-
122+
private fun parseActionsOrder(tokens: List<String>): List<NotificationAction> {
128123
val seen = LinkedHashSet<NotificationAction>()
129124
for (token in tokens) {
130125
tokenToAction(token)?.let { seen.add(it) }

legacy/core/src/test/java/com/fsck/k9/notification/SingleMessageNotificationDataCreatorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class SingleMessageNotificationDataCreatorTest {
224224

225225
private fun setMessageActions(cutoff: Int) {
226226
fakeNotificationPreferences.setMessageActions(
227-
order = "reply,mark_as_read,delete,archive,spam",
227+
order = listOf("reply", "mark_as_read", "delete", "archive", "spam"),
228228
cutoff = cutoff,
229229
)
230230
}
@@ -291,7 +291,7 @@ class SingleMessageNotificationDataCreatorTest {
291291
prefs.update { it.copy(notificationQuickDeleteBehaviour = behaviour) }
292292
}
293293

294-
fun setMessageActions(order: String, cutoff: Int) {
294+
fun setMessageActions(order: List<String>, cutoff: Int) {
295295
prefs.update { it.copy(messageActionsOrder = order, messageActionsCutoff = cutoff) }
296296
}
297297
}

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/notificationactions/MessageNotificationAction.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ internal enum class MessageNotificationAction(
5353
}
5454

5555
fun defaultOrder(): List<MessageNotificationAction> {
56-
val seen = LinkedHashSet<MessageNotificationAction>()
57-
for (token in NotificationActionTokens.DEFAULT_ORDER.split(',')) {
58-
val trimmed = token.trim()
59-
if (trimmed.isNotEmpty()) {
60-
fromToken(trimmed)?.let { seen.add(it) }
61-
}
62-
}
63-
return seen.toList()
64-
}
56+
val seen = LinkedHashSet<MessageNotificationAction>()
57+
for (token in NotificationActionTokens.DEFAULT_ORDER) {
58+
fromToken(token)?.let { seen.add(it) }
59+
}
60+
for (action in entries) {
61+
seen.add(action)
62+
}
63+
return seen.toList()
64+
}
6565
}
6666
}

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/notificationactions/NotificationActionsAdapter.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,13 @@ internal class NotificationActionsAdapter(
148148
val actionHolder = holder as ActionViewHolder
149149
actionHolder.bind(
150150
item = item,
151-
minHeight = android.R.attr.listPreferredItemHeightSmall.dp,
152151
onStartDrag = { itemTouchHelper.startDrag(actionHolder) },
153152
onMove = ::moveItem,
154153
)
155154
}
156155
is NotificationListItem.Cutoff -> {
157156
val cutoffHolder = holder as CutoffViewHolder
158157
cutoffHolder.bind(
159-
minHeight = android.R.attr.listPreferredItemHeightSmall.dp,
160158
onStartDrag = { itemTouchHelper.startDrag(cutoffHolder) },
161159
onMove = ::moveItem,
162160
)
@@ -199,7 +197,6 @@ internal class NotificationActionsAdapter(
199197

200198
fun bind(
201199
item: NotificationListItem.Action,
202-
minHeight: Dp,
203200
onStartDrag: () -> Unit,
204201
onMove: (Int, Int) -> Boolean,
205202
) {
@@ -209,7 +206,6 @@ internal class NotificationActionsAdapter(
209206
NotificationActionRow(
210207
action = item.action,
211208
isDimmed = item.isDimmed,
212-
minHeight = minHeight,
213209
onStartDrag = onStartDrag,
214210
)
215211
}
@@ -262,15 +258,13 @@ internal class NotificationActionsAdapter(
262258
}
263259

264260
fun bind(
265-
minHeight: Dp,
266261
onStartDrag: () -> Unit,
267262
onMove: (Int, Int) -> Boolean,
268263
) {
269264
setReorderActions(onMove)
270265
composeView.setContent {
271266
themeProvider.WithTheme {
272267
NotificationCutoffRow(
273-
minHeight = minHeight,
274268
onStartDrag = onStartDrag,
275269
)
276270
}
@@ -310,10 +304,10 @@ internal class NotificationActionsAdapter(
310304
private fun NotificationActionRow(
311305
action: MessageNotificationAction,
312306
isDimmed: Boolean,
313-
minHeight: Dp,
314307
onStartDrag: () -> Unit,
315308
modifier: Modifier = Modifier,
316309
) {
310+
val minHeight = MainTheme.sizes.iconAvatar
317311
Row(
318312
modifier = modifier
319313
.fillMaxWidth()
@@ -351,10 +345,10 @@ private fun NotificationActionRow(
351345

352346
@Composable
353347
private fun NotificationCutoffRow(
354-
minHeight: Dp,
355348
onStartDrag: () -> Unit,
356349
modifier: Modifier = Modifier,
357350
) {
351+
val minHeight = MainTheme.sizes.iconAvatar
358352
Row(
359353
modifier = modifier
360354
.fillMaxWidth()

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/notificationactions/NotificationActionsSettingsFragment.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ class NotificationActionsSettingsFragment : androidx.fragment.app.Fragment() {
8585

8686
private fun persist() {
8787
val sanitizedCutoff = cutoff.coerceIn(0, NOTIFICATION_PREFERENCE_MAX_MESSAGE_ACTIONS_SHOWN)
88-
val orderString = actionOrder.joinToString(separator = ",") { it.token }
89-
9088
generalSettingsManager.update { settings ->
9189
settings.copy(
9290
notification = settings.notification.copy(
93-
messageActionsOrder = orderString,
91+
messageActionsOrder = actionOrder.map { it.token },
9492
messageActionsCutoff = sanitizedCutoff,
9593
),
9694
)
@@ -129,12 +127,7 @@ class NotificationActionsSettingsFragment : androidx.fragment.app.Fragment() {
129127
persist()
130128
}
131129

132-
private fun parseOrder(raw: String): List<MessageNotificationAction> {
133-
val tokens = raw
134-
.split(',')
135-
.map { it.trim() }
136-
.filter { it.isNotEmpty() }
137-
130+
private fun parseOrder(tokens: List<String>): List<MessageNotificationAction> {
138131
val seen = LinkedHashSet<MessageNotificationAction>()
139132
for (token in tokens) {
140133
MessageNotificationAction.fromToken(token)?.let { seen.add(it) }

0 commit comments

Comments
 (0)