From 7f60661dd63087460eb41ca85d57edaf4e2142f4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 26 Nov 2021 18:36:55 +0100 Subject: [PATCH] minor code style update for better readability --- .../commons/dialogs/FilePickerDialog.kt | 3 +- .../commons/extensions/File.kt | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt index 780a183fb..97aaf554e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt @@ -244,8 +244,7 @@ class FilePickerDialog( private fun getRegularItems(path: String, lastModifieds: HashMap, callback: (List) -> Unit) { val items = ArrayList() - val base = File(path) - val files = base.listFiles() + val files = File(path).listFiles()?.filterNotNull() if (files == null) { callback(items) return diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt index 644e718dd..42e5402db 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt @@ -75,17 +75,24 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int { return count } -fun File.getDirectChildrenCount(context: Context, countHiddenItems: Boolean) = - if (context.isRestrictedSAFOnlyRoot(path)) context.getAndroidSAFDirectChildrenCount( - path, - countHiddenItems - ) else listFiles()?.filter { - if (countHiddenItems) { - true - } else { - !it.name.startsWith('.') - } - }?.size ?: 0 +fun File.getDirectChildrenCount(context: Context, countHiddenItems: Boolean): Int { + val fileCount = if (context.isRestrictedSAFOnlyRoot(path)) { + context.getAndroidSAFDirectChildrenCount( + path, + countHiddenItems + ) + } else { + listFiles()?.filter { + if (countHiddenItems) { + true + } else { + !it.name.startsWith('.') + } + }?.size ?: 0 + } + + return fileCount +} fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, context.getIsPathDirectory(absolutePath), 0, length(), lastModified()) @@ -97,7 +104,10 @@ fun File.containsNoMedia(): Boolean { } } -fun File.doesThisOrParentHaveNoMedia(folderNoMediaStatuses: HashMap, callback: ((path: String, hasNoMedia: Boolean) -> Unit)?): Boolean { +fun File.doesThisOrParentHaveNoMedia( + folderNoMediaStatuses: HashMap, + callback: ((path: String, hasNoMedia: Boolean) -> Unit)? +): Boolean { var curFile = this while (true) { val noMediaPath = "${curFile.absolutePath}/$NOMEDIA"