ignore ConcurrentModificationExceptions thrown at updating the directories

This commit is contained in:
tibbi 2018-06-17 22:02:52 +02:00
parent 875ba99dc0
commit 0258fc5e29

View file

@ -37,6 +37,7 @@ import com.simplemobiletools.gallery.models.Directory
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import java.io.* import java.io.*
import java.util.*
class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private val PICK_MEDIA = 2 private val PICK_MEDIA = 2
@ -609,41 +610,44 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val directoryDao = galleryDB.DirectoryDao() val directoryDao = galleryDB.DirectoryDao()
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0
for (directory in dirs) { try {
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken) for (directory in dirs) {
val newDir = if (curMedia.isEmpty()) { val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken)
directory val newDir = if (curMedia.isEmpty()) {
} else { directory
createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) } else {
} createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
}
// we are looping through the already displayed folders looking for changes, do not do anything if nothing changed // we are looping through the already displayed folders looking for changes, do not do anything if nothing changed
if (directory == newDir) { if (directory == newDir) {
continue continue
} }
directory.apply { directory.apply {
tmb = newDir.tmb tmb = newDir.tmb
name = newDir.name name = newDir.name
mediaCnt = newDir.mediaCnt mediaCnt = newDir.mediaCnt
modified = newDir.modified modified = newDir.modified
taken = newDir.taken taken = newDir.taken
this@apply.size = newDir.size this@apply.size = newDir.size
types = newDir.types types = newDir.types
} }
showSortedDirs(dirs) showSortedDirs(dirs)
// update directories and media files in the local db, delete invalid items // update directories and media files in the local db, delete invalid items
updateDBDirectory(directory) updateDBDirectory(directory)
mediumDao.insertAll(curMedia) mediumDao.insertAll(curMedia)
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
it.forEach { it.forEach {
if (!curMedia.contains(it)) { if (!curMedia.contains(it)) {
mediumDao.deleteMediumPath(it.path) mediumDao.deleteMediumPath(it.path)
}
} }
} }
} }
} catch (ignored: ConcurrentModificationException) {
} }
val foldersToScan = mediaFetcher.getFoldersToScan() val foldersToScan = mediaFetcher.getFoldersToScan()