diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 6293eba76..ec877c43c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -16,29 +16,23 @@ data class Directory(val path: String, val tmb: String, val name: String, var me override fun compareTo(other: Directory): Int { var result: Int - if (sorting and SORT_BY_NAME != 0) { - result = AlphanumComparator().compare(name.toLowerCase(), other.name.toLowerCase()) - } else if (sorting and SORT_BY_SIZE != 0) { - result = if (size == other.size) - 0 - else if (size > other.size) - 1 - else - -1 - } else if (sorting and SORT_BY_DATE_MODIFIED != 0) { - result = if (modified == other.modified) - 0 - else if (modified > other.modified) - 1 - else - -1 - } else { - result = if (taken == other.taken) - 0 - else if (taken > other.taken) - 1 - else - -1 + when { + sorting and SORT_BY_NAME != 0 -> result = AlphanumComparator().compare(name.toLowerCase(), other.name.toLowerCase()) + sorting and SORT_BY_SIZE != 0 -> result = when { + size == other.size -> 0 + size > other.size -> 1 + else -> -1 + } + sorting and SORT_BY_DATE_MODIFIED != 0 -> result = when { + modified == other.modified -> 0 + modified > other.modified -> 1 + else -> -1 + } + else -> result = when { + taken == other.taken -> 0 + taken > other.taken -> 1 + else -> -1 + } } if (sorting and SORT_DESCENDING != 0) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 1663c60b1..a04a39aa9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -25,29 +25,23 @@ data class Medium(var name: String, var path: String, val video: Boolean, val mo override fun compareTo(other: Medium): Int { var result: Int - if (sorting and SORT_BY_NAME != 0) { - result = AlphanumComparator().compare(name.toLowerCase(), other.name.toLowerCase()) - } else if (sorting and SORT_BY_SIZE != 0) { - result = if (size == other.size) - 0 - else if (size > other.size) - 1 - else - -1 - } else if (sorting and SORT_BY_DATE_MODIFIED != 0) { - result = if (modified == other.modified) - 0 - else if (modified > other.modified) - 1 - else - -1 - } else { - result = if (taken == other.taken) - 0 - else if (taken > other.taken) - 1 - else - -1 + when { + sorting and SORT_BY_NAME != 0 -> result = AlphanumComparator().compare(name.toLowerCase(), other.name.toLowerCase()) + sorting and SORT_BY_SIZE != 0 -> result = when { + size == other.size -> 0 + size > other.size -> 1 + else -> -1 + } + sorting and SORT_BY_DATE_MODIFIED != 0 -> result = when { + modified == other.modified -> 0 + modified > other.modified -> 1 + else -> -1 + } + else -> result = when { + taken == other.taken -> 0 + taken > other.taken -> 1 + else -> -1 + } } if (sorting and SORT_DESCENDING != 0) {