From b56d4d660026a628005e2f2a894aadf7430e54e7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 09:55:41 +0200 Subject: [PATCH] do not try parsing media files of empty lists --- .../gallery/activities/MainActivity.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index f64d84277..55a9aee4f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -575,7 +575,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { for (directory in dirs) { val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly) - val newDir = createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + val newDir = if (curMedia.isEmpty()) { + directory + } else { + createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + } // we are looping through the already displayed folders looking for changes, do not do anything if nothing changed if (directory == newDir) { @@ -667,8 +671,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val firstItem = curMedia.first() val lastItem = curMedia.last() - val lastModified = if (!isSortingAscending) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified) - val dateTaken = if (!isSortingAscending) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken) + 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) val size = curMedia.sumByLong { it.size } return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes) }