fix media inserting ConcurrentModificationException in a proper way

This commit is contained in:
tibbi 2018-04-23 13:31:26 +02:00
parent 3aaa17a02d
commit 4f724786b2

View File

@ -633,14 +633,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun gotMedia(media: ArrayList<Medium>, isFromCache: Boolean = false) { private fun gotMedia(media: ArrayList<Medium>, isFromCache: Boolean = false) {
val mediaToInsert = media.clone() as ArrayList<Medium>
Thread { Thread {
mLatestMediaId = getLatestMediaId() mLatestMediaId = getLatestMediaId()
mLatestMediaDateId = getLatestMediaByDateId() mLatestMediaDateId = getLatestMediaByDateId()
if (!isFromCache) { if (!isFromCache) {
try { galleryDB.MediumDao().insertAll(mediaToInsert)
galleryDB.MediumDao().insertAll(media)
} catch (e: ConcurrentModificationException) {
}
} }
}.start() }.start()