From 0b3267a2bc8f170c64c69110b94bae2e9c5f2ce3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 18 Oct 2017 17:38:35 +0200 Subject: [PATCH] format FileDirItem model --- .../commons/models/FileDirItem.kt | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt index 511166892..7adc202f0 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt @@ -19,28 +19,27 @@ data class FileDirItem(val path: String, val name: String, val isDirectory: Bool 1 } else { var result: Int - if (sorting and SORT_BY_NAME != 0) { - result = name.toLowerCase().compareTo(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) { - val file = File(path) - val otherFile = File(other.path) - result = if (file.lastModified() == otherFile.lastModified()) - 0 - else if (file.lastModified() > otherFile.lastModified()) - 1 - else - -1 - } else { - val extension = if (isDirectory) name else path.substringAfterLast('.', "") - val otherExtension = if (other.isDirectory) other.name else other.path.substringAfterLast('.', "") - result = extension.toLowerCase().compareTo(otherExtension.toLowerCase()) + when { + sorting and SORT_BY_NAME != 0 -> result = name.toLowerCase().compareTo(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 -> { + val file = File(path) + val otherFile = File(other.path) + result = when { + file.lastModified() == otherFile.lastModified() -> 0 + file.lastModified() > otherFile.lastModified() -> 1 + else -> -1 + } + } + else -> { + val extension = if (isDirectory) name else path.substringAfterLast('.', "") + val otherExtension = if (other.isDirectory) other.name else other.path.substringAfterLast('.', "") + result = extension.toLowerCase().compareTo(otherExtension.toLowerCase()) + } } if (sorting and SORT_DESCENDING != 0) {