Skip to content

Commit dd5dc50

Browse files
TommyDL-InfomaniakKevinBoulongne
authored andcommitted
Improve Folder sorting
1 parent f93ec1b commit dd5dc50

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/src/main/java/com/infomaniak/mail/data/models/Folder.kt

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.content.Context
2323
import androidx.annotation.DrawableRes
2424
import androidx.annotation.StringRes
2525
import com.infomaniak.lib.core.utils.Utils.enumValueOfOrNull
26+
import com.infomaniak.lib.core.utils.removeAccents
2627
import com.infomaniak.mail.R
2728
import com.infomaniak.mail.data.models.message.Message
2829
import com.infomaniak.mail.data.models.thread.Thread
@@ -81,6 +82,8 @@ class Folder : RealmObject, Cloneable {
8182
var isCollapsed: Boolean = false // For parents only (collapsing a parent Folder will hide its children)
8283
@Transient
8384
var roleOrder: Int = role?.order ?: CUSTOM_FOLDER_ROLE_ORDER
85+
@Transient
86+
var sortedName: String = name
8487
//endregion
8588

8689
private val _parents by backlinks(Folder::children)
@@ -125,6 +128,8 @@ class Folder : RealmObject, Cloneable {
125128
this.isHistoryComplete = isHistoryComplete
126129
this.isHidden = isHidden
127130
this.isCollapsed = isCollapsed
131+
132+
this.sortedName = this.name.lowercase().removeAccents()
128133
}
129134

130135
fun resetLocalValues() {

app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ fun List<Folder>.flattenFolderChildren(dismissHiddenChildren: Boolean = false):
339339
/**
340340
* These 2 `sortFolders()` functions should always implement the same sort logic.
341341
*/
342-
fun RealmQuery<Folder>.sortFolders() = sort(Folder::name.name, Sort.ASCENDING)
342+
fun RealmQuery<Folder>.sortFolders() = sort(Folder::sortedName.name, Sort.ASCENDING)
343343
.sort(Folder::isFavorite.name, Sort.DESCENDING)
344344
.sort(Folder::roleOrder.name, Sort.DESCENDING)
345345

346346
/**
347347
* These 2 `sortFolders()` functions should always implement the same sort logic.
348348
*/
349-
fun List<Folder>.sortFolders() = sortedBy { it.name }
349+
fun List<Folder>.sortFolders() = sortedBy { it.sortedName }
350350
.sortedByDescending { it.isFavorite }
351351
.sortedByDescending { it.roleOrder }
352352

0 commit comments

Comments
 (0)