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 9bbaa26b3..33c1ab8f8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -102,7 +102,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") }*/ - if (hasPermission(PERMISSION_WRITE_STORAGE)) { + if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE)) { checkOTGInclusion() } } @@ -255,18 +255,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun checkOTGInclusion() { - if (!config.wasOTGHandled) { - Thread { - if (hasOTGConnected()) { - runOnUiThread { - handleOTGPermission { - config.addIncludedFolder(OTG_PATH) - } + Thread { + if (hasOTGConnected()) { + runOnUiThread { + handleOTGPermission { + config.addIncludedFolder(OTG_PATH) } - config.wasOTGHandled = true } - }.start() - } + config.wasOTGHandled = true + } + }.start() } private fun tryLoadGallery() { @@ -301,7 +299,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_refresh_layout.isRefreshing = true } } - gotDirectories(it) + gotDirectories(addTempFolderIfNeeded(it)) } } @@ -377,8 +375,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } Thread { + val directoryDao = galleryDB.DirectoryDao() folders.filter { !it.exists() }.forEach { - galleryDB.DirectoryDao().deleteDirPath(it.absolutePath) + directoryDao.deleteDirPath(it.absolutePath) } }.start() } @@ -760,7 +759,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { dirs.forEach { if (!getDoesFilePathExist(it.path)) { invalidDirs.add(it) - } else { + } else if (it.path != config.tempFolderPath) { val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false if (!hasMediaFile) { 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 0cfd4d85a..8ef8e068c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -312,7 +312,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag fun Context.removeInvalidDBDirectories(dirs: ArrayList? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { val dirsToCheck = dirs ?: directoryDao.getAll() - dirsToCheck.filter { !getDoesFilePathExist(it.path) }.forEach { + dirsToCheck.filter { !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach { directoryDao.deleteDirPath(it.path) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 7df52c96f..62bef007a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.gallery.interfaces import android.arch.persistence.room.Dao -import android.arch.persistence.room.Delete import android.arch.persistence.room.Insert import android.arch.persistence.room.OnConflictStrategy.REPLACE import android.arch.persistence.room.Query @@ -18,9 +17,6 @@ interface DirectoryDao { @Insert(onConflict = REPLACE) fun insertAll(directories: List) - @Delete - fun deleteDir(directory: Directory) - @Query("DELETE FROM directories WHERE path = :path") fun deleteDirPath(path: String)