make sure in MediaActivity the gotMedia is called on a background thread

This commit is contained in:
tibbi 2018-07-01 20:38:59 +02:00
parent 0316a21e39
commit 3a1c3b6cf9
1 changed files with 10 additions and 11 deletions

View File

@ -551,7 +551,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mLoadedInitialPhotos = true mLoadedInitialPhotos = true
mCurrAsyncTask?.stopFetching() mCurrAsyncTask?.stopFetching()
mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) { mCurrAsyncTask = GetMediaAsynctask(applicationContext, mPath, mIsGetImageIntent, mIsGetVideoIntent, mShowAll) {
Thread {
gotMedia(it) gotMedia(it)
}.start()
} }
mCurrAsyncTask!!.execute() mCurrAsyncTask!!.execute()
@ -779,15 +781,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun gotMedia(media: ArrayList<ThumbnailItem>, isFromCache: Boolean = false) { private fun gotMedia(media: ArrayList<ThumbnailItem>, isFromCache: Boolean = false) {
Thread {
mLatestMediaId = getLatestMediaId()
mLatestMediaDateId = getLatestMediaByDateId()
if (!isFromCache) {
val mediaToInsert = (mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium }
galleryDB.MediumDao().insertAll(mediaToInsert)
}
}.start()
mIsGettingMedia = false mIsGettingMedia = false
checkLastMediaChanged() checkLastMediaChanged()
mMedia = media mMedia = media
@ -801,9 +794,15 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll) media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll) media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
setupAdapter() setupAdapter()
} }
mLatestMediaId = getLatestMediaId()
mLatestMediaDateId = getLatestMediaByDateId()
if (!isFromCache) {
val mediaToInsert = (mMedia.clone() as ArrayList<ThumbnailItem>).filter { it is Medium && it.deletedTS == 0L }.map { it as Medium }
galleryDB.MediumDao().insertAll(mediaToInsert)
}
} }
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) { override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {