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() }