mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
rely on Room db data at caching items
This commit is contained in:
parent
244e29b437
commit
c17b58dc53
4 changed files with 34 additions and 27 deletions
|
@ -573,14 +573,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
||||
|
||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||
directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll)
|
||||
directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll)
|
||||
|
||||
checkLastMediaChanged()
|
||||
mDirs = dirs
|
||||
|
||||
runOnUiThread {
|
||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||
directories_vertical_fastscroller.beVisibleIf(directories_grid.isVisible() && !allowHorizontalScroll)
|
||||
directories_horizontal_fastscroller.beVisibleIf(directories_grid.isVisible() && allowHorizontalScroll)
|
||||
setupAdapter()
|
||||
}
|
||||
|
||||
|
|
|
@ -454,9 +454,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
mIsGettingMedia = true
|
||||
val media = getCachedMedia(mPath)
|
||||
if (media.isNotEmpty() && !mLoadedInitialPhotos) {
|
||||
gotMedia(media, true)
|
||||
if (!mLoadedInitialPhotos) {
|
||||
getCachedMedia(mPath) {
|
||||
if (it.isEmpty()) {
|
||||
media_refresh_layout.isRefreshing = true
|
||||
} else {
|
||||
gotMedia(it, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
media_refresh_layout.isRefreshing = true
|
||||
}
|
||||
|
@ -631,8 +636,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}.start()
|
||||
|
||||
mIsGettingMedia = false
|
||||
media_refresh_layout.isRefreshing = false
|
||||
|
||||
checkLastMediaChanged()
|
||||
mMedia = media
|
||||
|
||||
runOnUiThread {
|
||||
media_refresh_layout.isRefreshing = false
|
||||
media_empty_text_label.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||
media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||
media_grid.beVisibleIf(media_empty_text_label.isGone())
|
||||
|
@ -641,10 +650,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
|
||||
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
||||
|
||||
checkLastMediaChanged()
|
||||
|
||||
mMedia = media
|
||||
runOnUiThread {
|
||||
setupAdapter()
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,12 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
|||
activity.setupDialogStuff(view, this, R.string.select_photo)
|
||||
}
|
||||
|
||||
val media = activity.getCachedMedia(path).filter { !it.isVideo() } as ArrayList
|
||||
activity.getCachedMedia(path) {
|
||||
val media = it.filter { !it.isVideo() } as ArrayList
|
||||
if (media.isNotEmpty()) {
|
||||
gotMedia(media)
|
||||
}
|
||||
}
|
||||
|
||||
GetMediaAsynctask(activity, path, false, true, false) {
|
||||
gotMedia(it)
|
||||
|
|
|
@ -11,8 +11,6 @@ import com.bumptech.glide.load.DecodeFormat
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
@ -256,7 +254,10 @@ fun Activity.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
|
|||
}.start()
|
||||
}
|
||||
|
||||
fun Activity.getCachedMedia(path: String): ArrayList<Medium> {
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
return Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(path), token) ?: ArrayList(1)
|
||||
fun Activity.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit) {
|
||||
Thread {
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
|
||||
callback(media)
|
||||
}.start()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue