Skip to content

Commit b69b273

Browse files
committed
multiple message delete option re-added
1 parent 8f27f4d commit b69b273

File tree

7 files changed

+151
-22
lines changed

7 files changed

+151
-22
lines changed

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

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

33
import net.thunderbird.core.android.account.LegacyAccountDto
44
import net.thunderbird.core.preference.GeneralSettingsManager
5-
import net.thunderbird.core.preference.NotificationQuickDelete
65

76
private const val MAX_NUMBER_OF_MESSAGES_FOR_SUMMARY_NOTIFICATION = 5
87

@@ -72,8 +71,7 @@ internal class SummaryNotificationDataCreator(
7271
}
7372

7473
private fun isSummaryDeleteActionEnabled(): Boolean {
75-
return generalSettingsManager.getConfig().notification.notificationQuickDeleteBehaviour ==
76-
NotificationQuickDelete.ALWAYS
74+
return generalSettingsManager.getConfig().notification.isSummaryDeleteActionEnabled
7775
}
7876

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

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import net.thunderbird.core.preference.AppTheme
1212
import net.thunderbird.core.preference.BackgroundOps
1313
import net.thunderbird.core.preference.BodyContentType
1414
import net.thunderbird.core.preference.GeneralSettingsManager
15-
import net.thunderbird.core.preference.NotificationQuickDelete
1615
import net.thunderbird.core.preference.SplitViewMode
1716
import net.thunderbird.core.preference.SubTheme
1817
import net.thunderbird.core.preference.display.visualSettings.message.list.MessageListDateTimeFormat
@@ -60,6 +59,7 @@ class GeneralSettingsDataStore(
6059
"drawerExpandAllFolder" -> visualSettings.drawerExpandAllFolder
6160
"quiet_time_enabled" -> notificationSettings.isQuietTimeEnabled
6261
"disable_notifications_during_quiet_time" -> !notificationSettings.isNotificationDuringQuietTimeEnabled
62+
"notification_summary_delete" -> notificationSettings.isSummaryDeleteActionEnabled
6363
"privacy_hide_useragent" -> privacySettings.isHideUserAgent
6464
"privacy_hide_timezone" -> privacySettings.isHideTimeZone
6565
"debug_logging" -> debuggingSettings.isDebugLoggingEnabled
@@ -101,6 +101,7 @@ class GeneralSettingsDataStore(
101101
"messageview_autofit_width" -> setIsAutoFitWidth(isAutoFitWidth = value)
102102
"quiet_time_enabled" -> setIsQuietTimeEnabled(isQuietTimeEnabled = value)
103103
"disable_notifications_during_quiet_time" -> setIsNotificationDuringQuietTimeEnabled(!value)
104+
"notification_summary_delete" -> setIsSummaryDeleteActionEnabled(isSummaryDeleteActionEnabled = value)
104105
"privacy_hide_useragent" -> setIsHideUserAgent(isHideUserAgent = value)
105106
"privacy_hide_timezone" -> setIsHideTimeZone(isHideTimeZone = value)
106107
"debug_logging" -> setIsDebugLoggingEnabled(isDebugLoggingEnabled = value)
@@ -151,7 +152,6 @@ class GeneralSettingsDataStore(
151152
"messagelist_preview_lines" -> messageListSettings.previewLines.toString()
152153
"message_list_date_time_format" -> messageListSettings.dateTimeFormat.toString()
153154
"splitview_mode" -> coreSettings.splitViewMode.name
154-
"notification_quick_delete" -> notificationSettings.notificationQuickDeleteBehaviour.name
155155
"lock_screen_notification_visibility" -> K9.lockScreenNotificationVisibility.name
156156
"background_ops" -> networkSettings.backgroundOps.name
157157
"quiet_time_starts" -> notificationSettings.quietTimeStarts
@@ -191,11 +191,6 @@ class GeneralSettingsDataStore(
191191
"messagelist_preview_lines" -> setMessageListPreviewLines(value.toInt())
192192
"message_list_date_time_format" -> updateMessageListDateTimeFormat(value)
193193
"splitview_mode" -> setSplitViewModel(SplitViewMode.valueOf(value.uppercase()))
194-
"notification_quick_delete" -> {
195-
setNotificationQuickDeleteBehaviour(
196-
behaviour = NotificationQuickDelete.valueOf(value),
197-
)
198-
}
199194
"lock_screen_notification_visibility" -> {
200195
K9.lockScreenNotificationVisibility = K9.LockScreenNotificationVisibility.valueOf(value)
201196
}
@@ -369,13 +364,6 @@ class GeneralSettingsDataStore(
369364
}
370365
}
371366

372-
private fun setNotificationQuickDeleteBehaviour(behaviour: NotificationQuickDelete) {
373-
skipSaveSettings = true
374-
generalSettingsManager.update { settings ->
375-
settings.copy(notification = settings.notification.copy(notificationQuickDeleteBehaviour = behaviour))
376-
}
377-
}
378-
379367
private fun setFixedMessageViewTheme(fixedMessageViewTheme: Boolean) {
380368
skipSaveSettings = true
381369
generalSettingsManager.update { settings ->
@@ -659,6 +647,17 @@ class GeneralSettingsDataStore(
659647
}
660648
}
661649

650+
private fun setIsSummaryDeleteActionEnabled(isSummaryDeleteActionEnabled: Boolean) {
651+
skipSaveSettings = true
652+
generalSettingsManager.update { settings ->
653+
settings.copy(
654+
notification = settings.notification.copy(
655+
isSummaryDeleteActionEnabled = isSummaryDeleteActionEnabled,
656+
),
657+
)
658+
}
659+
}
660+
662661
private fun setIsHideTimeZone(isHideTimeZone: Boolean) {
663662
skipSaveSettings = true
664663
generalSettingsManager.update { settings ->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.fsck.k9.ui.settings.notificationactions
2+
3+
internal sealed interface NotificationListItem {
4+
data class Action(
5+
val action: MessageNotificationAction,
6+
) : NotificationListItem
7+
8+
data object Cutoff : NotificationListItem
9+
}
10+
11+
internal val NotificationListItem.key: String
12+
get() = when (this) {
13+
is NotificationListItem.Action -> "action:${action.token}"
14+
NotificationListItem.Cutoff -> "cutoff"
15+
}

legacy/ui/legacy/src/main/res/values/ids.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
<item type="id" name="settings_list_url_item" />
2121
<item type="id" name="settings_list_intent_item" />
2222

23-
<item type="id" name="accessibility_action_move_up" />
24-
<item type="id" name="accessibility_action_move_down" />
25-
2623
<item type="id" name="message_list_swipe_tag" />
2724
</resources>

legacy/ui/legacy/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@
143143
<string name="notification_action_mark_all_as_read">Mark All Read</string>
144144
<string name="notification_actions_settings_title">Notification actions</string>
145145
<string name="notification_actions_settings_summary">Choose which actions appear in email notifications</string>
146+
<string name="notification_summary_delete_title">Show Delete on multi-message notifications</string>
147+
<string name="notification_summary_delete_summary">Adds a Delete action to notifications that summarize multiple new messages</string>
146148
<string name="notification_actions_settings_description">Drag to reorder actions. Actions above the bar will be shown (up to 3).</string>
147-
<string name="notification_actions_cutoff_label">Shown actions</string>
148149
<string name="notification_actions_cutoff_description">Shown actions cutoff</string>
149-
<string name="notification_actions_drag_handle_description">Reorder action</string>
150150
<string name="accessibility_move_up">Move up</string>
151151
<string name="accessibility_move_down">Move down</string>
152152
<string name="notification_action_delete">Delete</string>

legacy/ui/legacy/src/main/res/xml/general_settings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@
499499
android:summary="@string/notification_actions_settings_summary"
500500
/>
501501

502+
<CheckBoxPreference
503+
android:key="notification_summary_delete"
504+
android:title="@string/notification_summary_delete_title"
505+
android:summary="@string/notification_summary_delete_summary"
506+
/>
507+
502508
</PreferenceScreen>
503509

504510
<PreferenceScreen
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.fsck.k9.ui.settings.notificationactions
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertEquals
5+
import kotlin.test.assertTrue
6+
7+
class NotificationActionsReorderControllerTest {
8+
private val initialActions = listOf(
9+
MessageNotificationAction.Reply,
10+
MessageNotificationAction.Archive,
11+
MessageNotificationAction.MarkAsRead,
12+
MessageNotificationAction.Spam,
13+
MessageNotificationAction.Star,
14+
MessageNotificationAction.Delete,
15+
)
16+
17+
@Test
18+
fun `moveByStep crossing into full visible section kicks previous last visible below cutoff`() {
19+
val controller = createController()
20+
21+
val moved = controller.moveByStep(
22+
itemKey = controller.keyForAction(MessageNotificationAction.Spam),
23+
delta = -1,
24+
)
25+
26+
assertTrue(moved)
27+
assertEquals(3, controller.cutoffIndex)
28+
assertEquals(
29+
listOf(
30+
MessageNotificationAction.Reply,
31+
MessageNotificationAction.Archive,
32+
MessageNotificationAction.Spam,
33+
MessageNotificationAction.MarkAsRead,
34+
MessageNotificationAction.Star,
35+
MessageNotificationAction.Delete,
36+
),
37+
controller.actionOrder(),
38+
)
39+
}
40+
41+
@Test
42+
fun `dragBy crossing from below when full requires last-above threshold before swap`() {
43+
val controller = createController()
44+
val draggedAction = MessageNotificationAction.Spam
45+
controller.startDrag(controller.keyForAction(draggedAction))
46+
47+
controller.dragBy(
48+
deltaY = -120f,
49+
visibleItems = controller.visibleItemsForTest(),
50+
)
51+
52+
assertEquals(
53+
listOf(
54+
MessageNotificationAction.Reply,
55+
MessageNotificationAction.Archive,
56+
MessageNotificationAction.MarkAsRead,
57+
MessageNotificationAction.Spam,
58+
MessageNotificationAction.Star,
59+
MessageNotificationAction.Delete,
60+
),
61+
controller.actionOrder(),
62+
)
63+
assertEquals(3, controller.cutoffIndex)
64+
65+
controller.dragBy(
66+
deltaY = -50f,
67+
visibleItems = controller.visibleItemsForTest(),
68+
)
69+
70+
assertEquals(
71+
listOf(
72+
MessageNotificationAction.Reply,
73+
MessageNotificationAction.Archive,
74+
MessageNotificationAction.Spam,
75+
MessageNotificationAction.MarkAsRead,
76+
MessageNotificationAction.Star,
77+
MessageNotificationAction.Delete,
78+
),
79+
controller.actionOrder(),
80+
)
81+
assertEquals(3, controller.cutoffIndex)
82+
}
83+
84+
private fun createController(): NotificationActionsReorderController {
85+
return NotificationActionsReorderController(
86+
initialActions = initialActions,
87+
initialCutoff = 3,
88+
onStateChanged = { _, _ -> },
89+
)
90+
}
91+
92+
private fun NotificationActionsReorderController.actionOrder(): List<MessageNotificationAction> {
93+
return items
94+
.filterIsInstance<NotificationListItem.Action>()
95+
.map { it.action }
96+
}
97+
98+
private fun NotificationActionsReorderController.keyForAction(action: MessageNotificationAction): String {
99+
return items
100+
.filterIsInstance<NotificationListItem.Action>()
101+
.first { it.action == action }
102+
.key
103+
}
104+
105+
private fun NotificationActionsReorderController.visibleItemsForTest(): List<ReorderVisibleItem> {
106+
return items.mapIndexed { index, item ->
107+
ReorderVisibleItem(
108+
key = item.key,
109+
offset = index * 100,
110+
size = 100,
111+
)
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)