From d8e0e87cb1e71a2183ef69ccb428d80f651d24db Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 26 May 2019 21:57:18 +0200 Subject: [PATCH] adding some default medium at creating directories from files --- .../com/simplemobiletools/gallery/pro/extensions/Context.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 8b7fdd242..a3dfdda6f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -797,8 +797,9 @@ fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList, } } - val firstItem = curMedia.first() - val lastItem = curMedia.last() + val defaultMedium = Medium(0, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L) + val firstItem = curMedia.firstOrNull() ?: defaultMedium + val lastItem = curMedia.lastOrNull() ?: defaultMedium val dirName = checkAppendingHidden(path, hiddenString, includedFolders) val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified) val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)