diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/MessageEntity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/MessageEntity.kt index 2b08ccb1f9..1501861c08 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/MessageEntity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/MessageEntity.kt @@ -794,7 +794,11 @@ data class MessageEntity( ?: entity.alias.orEmpty() GmailApiLabelsListAdapter.Label(name, entity.labelColor, entity.textColor) } - }.sortedBy { it.name.lowercase() } + }.sortedWith(compareByDescending { + it.name.equals(JavaEmailConstants.FOLDER_INBOX, ignoreCase = true) + }.thenBy { + it.name.lowercase() + }) } } } diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/database/entity/MessageEntityTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/database/entity/MessageEntityTest.kt new file mode 100644 index 0000000000..92db6e2702 --- /dev/null +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/database/entity/MessageEntityTest.kt @@ -0,0 +1,44 @@ +/* + * © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com + * Contributors: denbond7 + */ + +package com.flowcrypt.email.database.entity + +import com.flowcrypt.email.database.entity.LabelEntity.LabelListVisibility +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * @author Denys Bondarenko + */ +class MessageEntityTest { + @Test + fun generateColoredLabelsCorrectInboxPositionTest() { + val labelIds = (1..5).map { + "Some_Name_$it" + }.shuffled().toMutableList().apply { + add("INBOX") + } + + val labelEntities = labelIds.map { + LabelEntity( + email = "email", + accountType = "accountType", + name = it, + isCustom = true, + alias = it, + messagesTotal = 0, + attributes = "", + labelColor = "labelColor", + textColor = "textColor", + labelListVisibility = LabelListVisibility.SHOW, + ) + } + val labels = MessageEntity.generateColoredLabels( + labelIds, + labelEntities + ) + assertEquals("Inbox", labels.first().name) + } +} \ No newline at end of file