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)