From 026f80aa20f41141bf9e49b96cd2cfc132f53687 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 17 Jun 2018 22:23:26 +0200 Subject: [PATCH] catch some Room db exceptions --- .../gallery/extensions/Context.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index cdcee9016..9506dd064 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.content.res.Configuration import android.database.Cursor +import android.database.sqlite.SQLiteException import android.graphics.Point import android.media.AudioManager import android.os.Build @@ -276,7 +277,11 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList) -> Unit) { Thread { val directoryDao = galleryDB.DirectoryDao() - val directories = directoryDao.getAll() as ArrayList + val directories = try { + directoryDao.getAll() as ArrayList + } catch (e: SQLiteException) { + ArrayList() + } val shouldShowHidden = config.shouldShowHidden val excludedPaths = config.excludedFolders val includedPaths = config.includedFolders @@ -317,8 +322,11 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag var media = ArrayList() val shouldShowHidden = config.shouldShowHidden foldersToScan.forEach { - val currMedia = mediumDao.getMediaFromPath(it) - media.addAll(currMedia) + try { + val currMedia = mediumDao.getMediaFromPath(it) + media.addAll(currMedia) + } catch (ignored: IllegalStateException) { + } } if (!shouldShowHidden) {