Skip to content

Commit a247f26

Browse files
author
Kilian Hu
committed
Add sort by size feature
1 parent 39a6a6d commit a247f26

File tree

38 files changed

+311
-13
lines changed

38 files changed

+311
-13
lines changed

core/android/account/src/main/kotlin/net/thunderbird/core/android/account/SortType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ enum class SortType(val isDefaultAscending: Boolean) {
88
SORT_UNREAD(true),
99
SORT_FLAGGED(true),
1010
SORT_ATTACHMENT(true),
11+
SORT_SIZE(false),
1112
}

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/display/DisplaySettings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const val DISPLAY_SETTINGS_DEFAULT_SHOULD_SHOW_SETUP_ARCHIVE_FOLDER_DIALOG = tru
1818
const val DISPLAY_SETTINGS_DEFAULT_IS_MESSAGE_LIST_SENDER_ABOVE_SUBJECT = false
1919
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_NAME = false
2020
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE = true
21+
const val DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE = false
2122
const val DISPLAY_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR = true
2223
const val DISPLAY_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE = false
2324
const val DISPLAY_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR = false
@@ -44,6 +45,7 @@ data class DisplaySettings(
4445
val isMessageListSenderAboveSubject: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_MESSAGE_LIST_SENDER_ABOVE_SUBJECT,
4546
val isShowContactName: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_NAME,
4647
val isShowContactPicture: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE,
48+
val isShowMessageSize: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE,
4749
val isChangeContactNameColor: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_CHANGE_CONTACT_NAME_COLOR,
4850
val isColorizeMissingContactPictures: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_COLORIZE_MISSING_CONTACT_PICTURE,
4951
val isUseBackgroundAsUnreadIndicator: Boolean = DISPLAY_SETTINGS_DEFAULT_IS_USE_BACKGROUND_AS_INDICATOR,

core/preference/api/src/commonMain/kotlin/net/thunderbird/core/preference/display/DisplaySettingsPreferenceManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const val KEY_MESSAGE_VIEW_FIXED_WIDTH_FONT = "messageViewFixedWidthFont"
2323
const val KEY_AUTO_FIT_WIDTH = "autofitWidth"
2424
const val KEY_MESSAGE_LIST_SENDER_ABOVE_SUBJECT = "messageListSenderAboveSubject"
2525
const val KEY_SHOW_CONTACT_PICTURE = "showContactPicture"
26+
const val KEY_SHOW_MESSAGE_SIZE = "showMessageSize"
2627
const val KEY_APP_LANGUAGE = "language"
2728
const val KEY_SPLIT_VIEW_MODE = "splitViewMode"
2829

core/preference/impl/src/commonMain/kotlin/net/thunderbird/core/preference/display/DefaultDisplaySettingsPreferenceManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class DefaultDisplaySettingsPreferenceManager(
119119
KEY_SHOW_CONTACT_PICTURE,
120120
DISPLAY_SETTINGS_DEFAULT_IS_SHOW_CONTACT_PICTURE,
121121
),
122+
isShowMessageSize = storage.getBoolean(
123+
KEY_SHOW_MESSAGE_SIZE,
124+
DISPLAY_SETTINGS_DEFAULT_IS_SHOW_MESSAGE_SIZE,
125+
),
122126
appLanguage = storage.getStringOrDefault(
123127
KEY_APP_LANGUAGE,
124128
DISPLAY_SETTINGS_DEFAULT_APP_LANGUAGE,
@@ -176,6 +180,10 @@ class DefaultDisplaySettingsPreferenceManager(
176180
KEY_SHOW_CONTACT_PICTURE,
177181
config.isShowContactPicture,
178182
)
183+
storageEditor.putBoolean(
184+
KEY_SHOW_MESSAGE_SIZE,
185+
config.isShowMessageSize,
186+
)
179187
storageEditor.putBoolean(
180188
KEY_USE_BACKGROUND_AS_UNREAD_INDICATOR,
181189
config.isUseBackgroundAsUnreadIndicator,

feature/widget/message-list-glance/src/debug/kotlin/net/thunderbird/feature/widget/message/list/ui/MessageListWidgetContentPreview.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
3838
preview = "Preview 1",
3939
color = Color.BLUE,
4040
isRead = false,
41+
size = 1L,
4142
),
4243
generateMessageListItem(
4344
displayName = "Bob",
@@ -46,6 +47,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
4647
preview = "Preview 2",
4748
color = Color.RED,
4849
isRead = true,
50+
size = 2L * 1024L,
4951
),
5052
generateMessageListItem(
5153
displayName = "Charlie",
@@ -54,6 +56,7 @@ private fun generateMessageListItems(): ImmutableList<MessageListItem> {
5456
preview = "Preview 3",
5557
color = Color.RED,
5658
isRead = false,
59+
size = 3L * 1024L * 1024L,
5760
),
5861
)
5962
}
@@ -65,6 +68,7 @@ private fun generateMessageListItem(
6568
preview: String,
6669
color: Int,
6770
isRead: Boolean,
71+
size: Long,
6872
): MessageListItem {
6973
return MessageListItem(
7074
displayName = displayName,
@@ -82,5 +86,6 @@ private fun generateMessageListItem(
8286
sortInternalDate = 0,
8387
sortIsStarred = false,
8488
sortDatabaseId = 0,
89+
sortSize = size,
8590
)
8691
}

feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ internal data class MessageListItem(
1919
val sortInternalDate: Long,
2020
val sortIsStarred: Boolean,
2121
val sortDatabaseId: Long,
22+
val sortSize: Long,
2223
)

feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItemMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal class MessageListItemMapper(
5151
sortInternalDate = message.internalDate,
5252
sortIsStarred = message.isStarred,
5353
sortDatabaseId = message.id,
54+
sortSize = message.size,
5455
)
5556
}
5657

feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListLoader.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ internal class MessageListLoader(
7272
SortType.SORT_SUBJECT -> "${MessageColumns.SUBJECT} COLLATE NOCASE"
7373
SortType.SORT_UNREAD -> MessageColumns.READ
7474
SortType.SORT_DATE -> MessageColumns.DATE
75+
SortType.SORT_SIZE -> MessageColumns.SIZE
7576
}
7677

7778
val sortDirection = if (config.sortAscending) " ASC" else " DESC"
@@ -122,6 +123,11 @@ internal class MessageListLoader(
122123
compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
123124
.thenByDate(config)
124125
}
126+
127+
SortType.SORT_SIZE -> {
128+
compareBy<MessageListItem>(config.sortAscending) { it.sortSize }
129+
.thenByDate(config)
130+
}
125131
}.thenByDescending { it.sortDatabaseId }
126132

127133
return this.sortedWith(comparator)

feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ internal data class MessageListItem(
1919
val sortInternalDate: Long,
2020
val sortIsStarred: Boolean,
2121
val sortDatabaseId: Long,
22+
val sortSize: Long,
2223
)

feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItemMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal class MessageListItemMapper(
5151
sortInternalDate = message.internalDate,
5252
sortIsStarred = message.isStarred,
5353
sortDatabaseId = message.id,
54+
sortSize = message.size,
5455
)
5556
}
5657

0 commit comments

Comments
 (0)