avoid deleting newly created temporary folder too early

This commit is contained in:
tibbi 2018-04-26 16:08:20 +02:00
parent a0cf205c8c
commit 7b2a3d6365
3 changed files with 14 additions and 19 deletions

View file

@ -102,7 +102,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock")
}*/ }*/
if (hasPermission(PERMISSION_WRITE_STORAGE)) { if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE)) {
checkOTGInclusion() checkOTGInclusion()
} }
} }
@ -255,7 +255,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
private fun checkOTGInclusion() { private fun checkOTGInclusion() {
if (!config.wasOTGHandled) {
Thread { Thread {
if (hasOTGConnected()) { if (hasOTGConnected()) {
runOnUiThread { runOnUiThread {
@ -267,7 +266,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
}.start() }.start()
} }
}
private fun tryLoadGallery() { private fun tryLoadGallery() {
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(PERMISSION_WRITE_STORAGE) {
@ -301,7 +299,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
directories_refresh_layout.isRefreshing = true directories_refresh_layout.isRefreshing = true
} }
} }
gotDirectories(it) gotDirectories(addTempFolderIfNeeded(it))
} }
} }
@ -377,8 +375,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
Thread { Thread {
val directoryDao = galleryDB.DirectoryDao()
folders.filter { !it.exists() }.forEach { folders.filter { !it.exists() }.forEach {
galleryDB.DirectoryDao().deleteDirPath(it.absolutePath) directoryDao.deleteDirPath(it.absolutePath)
} }
}.start() }.start()
} }
@ -760,7 +759,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
dirs.forEach { dirs.forEach {
if (!getDoesFilePathExist(it.path)) { if (!getDoesFilePathExist(it.path)) {
invalidDirs.add(it) 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 children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList()
val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false
if (!hasMediaFile) { if (!hasMediaFile) {

View file

@ -312,7 +312,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
val dirsToCheck = dirs ?: directoryDao.getAll() 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) directoryDao.deleteDirPath(it.path)
} }
} }

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.gallery.interfaces package com.simplemobiletools.gallery.interfaces
import android.arch.persistence.room.Dao import android.arch.persistence.room.Dao
import android.arch.persistence.room.Delete
import android.arch.persistence.room.Insert import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy.REPLACE import android.arch.persistence.room.OnConflictStrategy.REPLACE
import android.arch.persistence.room.Query import android.arch.persistence.room.Query
@ -18,9 +17,6 @@ interface DirectoryDao {
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)
fun insertAll(directories: List<Directory>) fun insertAll(directories: List<Directory>)
@Delete
fun deleteDir(directory: Directory)
@Query("DELETE FROM directories WHERE path = :path") @Query("DELETE FROM directories WHERE path = :path")
fun deleteDirPath(path: String) fun deleteDirPath(path: String)