make sure to always create a new thread for inserting some things in db

This commit is contained in:
tibbi 2020-04-25 16:20:21 +02:00
parent 963fd57113
commit 462182271d
2 changed files with 13 additions and 6 deletions

View file

@ -955,7 +955,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
// update directories and media files in the local db, delete invalid items
updateDBDirectory(directory)
if (!directory.isRecycleBin()) {
Thread {
mediaDB.insertAll(curMedia)
}.start()
}
getCachedMedia(directory.path, getVideosOnly, getImagesOnly) {
@ -1029,10 +1031,13 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
dirs.add(newDir)
setupAdapter(dirs)
try {
// make sure to create a new thread for these operations, dont just use the common bg thread
Thread {
directoryDao.insert(newDir)
if (folder != RECYCLE_BIN) {
mediaDB.insertAll(newMedia)
}
}.start()
} catch (ignored: Exception) {
}
}

View file

@ -873,7 +873,9 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
if (!isFromCache) {
val mediaToInsert = (mMedia).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium }
try {
Thread {
mediaDB.insertAll(mediaToInsert)
}.start()
} catch (e: Exception) {
}
}