Skip to content

Commit cb1d9a3

Browse files
author
Kilian Hu
committed
Add sort by size feature
1 parent cb47e0a commit cb1d9a3

File tree

35 files changed

+372
-12
lines changed

35 files changed

+372
-12
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
}

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
@@ -45,6 +45,7 @@ internal class MessageListItemMapper(
4545
sortInternalDate = message.internalDate,
4646
sortIsStarred = message.isStarred,
4747
sortDatabaseId = message.id,
48+
sortSize = message.size,
4849
)
4950
}
5051

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
@@ -74,6 +74,7 @@ internal class MessageListLoader(
7474
SortType.SORT_SUBJECT -> "${MessageColumns.SUBJECT} COLLATE NOCASE"
7575
SortType.SORT_UNREAD -> MessageColumns.READ
7676
SortType.SORT_DATE -> MessageColumns.DATE
77+
SortType.SORT_SIZE -> MessageColumns.SIZE
7778
else -> MessageColumns.DATE
7879
}
7980

@@ -125,6 +126,11 @@ internal class MessageListLoader(
125126
compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
126127
.thenByDate(config)
127128
}
129+
130+
SortType.SORT_SIZE -> {
131+
compareBy<MessageListItem>(config.sortAscending) { it.sortSize }
132+
.thenByDate(config)
133+
}
128134
}.thenByDescending { it.sortDatabaseId }
129135

130136
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
@@ -45,6 +45,7 @@ internal class MessageListItemMapper(
4545
sortInternalDate = message.internalDate,
4646
sortIsStarred = message.isStarred,
4747
sortDatabaseId = message.id,
48+
sortSize = message.size,
4849
)
4950
}
5051

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal class MessageListLoader(
7474
SortType.SORT_SUBJECT -> "${MessageColumns.SUBJECT} COLLATE NOCASE"
7575
SortType.SORT_UNREAD -> MessageColumns.READ
7676
SortType.SORT_DATE -> MessageColumns.DATE
77+
SortType.SORT_SIZE -> MessageColumns.SIZE
7778
else -> MessageColumns.DATE
7879
}
7980

@@ -125,6 +126,11 @@ internal class MessageListLoader(
125126
compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
126127
.thenByDate(config)
127128
}
129+
130+
SortType.SORT_SIZE -> {
131+
compareBy<MessageListItem>(config.sortAscending) { it.sortSize }
132+
.thenByDate(config)
133+
}
128134
}.thenByDescending { it.sortDatabaseId }
129135

130136
return this.sortedWith(comparator)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ object K9 : KoinComponent {
198198
@JvmStatic
199199
var isShowContactPicture = true
200200

201+
@JvmStatic
202+
var isShowMessageSize = true
203+
201204
@JvmStatic
202205
var isUseMessageViewFixedWidthFont = false
203206

@@ -352,6 +355,7 @@ object K9 : KoinComponent {
352355
isShowCorrespondentNames = storage.getBoolean("showCorrespondentNames", true)
353356
isShowContactName = storage.getBoolean("showContactName", false)
354357
isShowContactPicture = storage.getBoolean("showContactPicture", true)
358+
isShowMessageSize = storage.getBoolean("showMessageSize", true)
355359
isChangeContactNameColor = storage.getBoolean("changeRegisteredNameColor", false)
356360
contactNameColor = storage.getInt("registeredNameColor", 0xFF1093F5.toInt())
357361
isUseMessageViewFixedWidthFont = storage.getBoolean("messageViewFixedWidthFont", false)
@@ -441,6 +445,7 @@ object K9 : KoinComponent {
441445
editor.putBoolean("showCorrespondentNames", isShowCorrespondentNames)
442446
editor.putBoolean("showContactName", isShowContactName)
443447
editor.putBoolean("showContactPicture", isShowContactPicture)
448+
editor.putBoolean("showMessageSize", isShowMessageSize)
444449
editor.putBoolean("changeRegisteredNameColor", isChangeContactNameColor)
445450
editor.putInt("registeredNameColor", contactNameColor)
446451
editor.putBoolean("messageViewFixedWidthFont", isUseMessageViewFixedWidthFont)

legacy/core/src/main/java/com/fsck/k9/mailstore/LocalMessage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class LocalMessage extends MimeMessage {
4040
private PreviewType previewType;
4141
private boolean headerNeedsUpdating = false;
4242
private LocalFolder mFolder;
43+
private long size;
4344

4445

4546
LocalMessage(LocalStore localStore, String uid, LocalFolder folder) {
@@ -133,6 +134,8 @@ void populateFromGetMessageCursor(Cursor cursor) throws MessagingException {
133134
Log.d("No headers available for this message!");
134135
}
135136

137+
this.size = cursor.isNull(LocalStore.MSG_INDEX_SIZE) ? 0 : cursor.getLong(LocalStore.MSG_INDEX_SIZE);
138+
136139
headerNeedsUpdating = false;
137140
}
138141

@@ -449,4 +452,8 @@ public int hashCode() {
449452
private String getAccountUuid() {
450453
return getAccount().getUuid();
451454
}
455+
456+
public long getSize() {
457+
return size;
458+
}
452459
}

0 commit comments

Comments
 (0)