From e7624ea7d7437b327d1cb1d70422e693f4b7bbb4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Feb 2019 22:17:37 +0100 Subject: [PATCH] catching some exceptions thrown related to handling cache db --- .../gallery/pro/activities/MainActivity.kt | 6 +++--- .../gallery/pro/extensions/Context.kt | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 2141f70f0..52b27337d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -917,11 +917,11 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { setupAdapter(dirs) try { mDirectoryDao.insert(newDir) + if (folder != RECYCLE_BIN) { + mMediumDao.insertAll(newMedia) + } } catch (ignored: Exception) { } - if (folder != RECYCLE_BIN) { - mMediumDao.insertAll(newMedia) - } } mLoadedInitialPhotos = true 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 a6f259da8..fb2d6f48d 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 @@ -592,7 +592,10 @@ fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, direc fun Context.updateDBMediaPath(oldPath: String, newPath: String) { val newFilename = newPath.getFilenameFromPath() val newParentPath = newPath.getParentPath() - galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath) + try { + galleryDB.MediumDao().updateMedium(oldPath, newParentPath, newFilename, newPath) + } catch (ignored: Exception) { + } } fun Context.updateDBDirectory(directory: Directory, directoryDao: DirectoryDao) { @@ -609,7 +612,12 @@ fun Context.getFavoritePaths(): ArrayList { // remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user... fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList { - val media = mediumDao.getDeletedMedia() as ArrayList + val media = try { + mediumDao.getDeletedMedia() as ArrayList + } catch (ignored: Exception) { + ArrayList() + } + media.forEach { it.path = File(recycleBinPath, it.path.removePrefix(RECYCLE_BIN)).toString() }