From e67517dd4c6a16ad1f033e6d31d0c7c886cc9334 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 12 Apr 2018 19:21:23 +0200 Subject: [PATCH] handle null file parent in some cases --- .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 2 +- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index e9d25e99e..19f73ddde 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -38,7 +38,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val firstItem = curMedia.first() val lastItem = curMedia.last() - val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) firstItem.path.getParentPath() else File(firstItem.path).parent + val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) firstItem.path.getParentPath() else File(firstItem.path).parent ?: continue var thumbnail = curMedia.firstOrNull { context.getDoesFilePathExist(it.path) }?.path ?: "" if (thumbnail.startsWith(OTG_PATH)) { thumbnail = thumbnail.getOTGPublicPath(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index b212851f3..61e88604b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -113,7 +113,7 @@ class MediaFetcher(val context: Context) { if (cursor.moveToFirst()) { do { val path = cursor.getStringValue(MediaStore.Images.Media.DATA).trim() - val parentPath = File(path).parent.trimEnd('/') + val parentPath = File(path).parent?.trimEnd('/') ?: continue if (!includedFolders.contains(parentPath)) { foldersToScan.add(parentPath) }