mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +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_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
||||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
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()
|
checkLastMediaChanged()
|
||||||
mDirs = dirs
|
mDirs = dirs
|
||||||
|
|
||||||
runOnUiThread {
|
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()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -454,9 +454,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsGettingMedia = true
|
mIsGettingMedia = true
|
||||||
val media = getCachedMedia(mPath)
|
if (!mLoadedInitialPhotos) {
|
||||||
if (media.isNotEmpty() && !mLoadedInitialPhotos) {
|
getCachedMedia(mPath) {
|
||||||
gotMedia(media, true)
|
if (it.isEmpty()) {
|
||||||
|
media_refresh_layout.isRefreshing = true
|
||||||
|
} else {
|
||||||
|
gotMedia(it, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
media_refresh_layout.isRefreshing = true
|
media_refresh_layout.isRefreshing = true
|
||||||
}
|
}
|
||||||
|
@ -631,8 +636,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
mIsGettingMedia = false
|
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_label.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||||
media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache)
|
media_empty_text.beVisibleIf(media.isEmpty() && !isFromCache)
|
||||||
media_grid.beVisibleIf(media_empty_text_label.isGone())
|
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_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
|
||||||
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
||||||
|
|
||||||
checkLastMediaChanged()
|
|
||||||
|
|
||||||
mMedia = media
|
|
||||||
runOnUiThread {
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,12 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
||||||
activity.setupDialogStuff(view, this, R.string.select_photo)
|
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()) {
|
if (media.isNotEmpty()) {
|
||||||
gotMedia(media)
|
gotMedia(media)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GetMediaAsynctask(activity, path, false, true, false) {
|
GetMediaAsynctask(activity, path, false, true, false) {
|
||||||
gotMedia(it)
|
gotMedia(it)
|
||||||
|
|
|
@ -11,8 +11,6 @@ import com.bumptech.glide.load.DecodeFormat
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||||
import com.bumptech.glide.request.RequestOptions
|
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.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
|
@ -256,7 +254,10 @@ fun Activity.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.getCachedMedia(path: String): ArrayList<Medium> {
|
fun Activity.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit) {
|
||||||
val token = object : TypeToken<List<Medium>>() {}.type
|
Thread {
|
||||||
return Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(path), token) ?: ArrayList(1)
|
val mediumDao = galleryDB.MediumDao()
|
||||||
|
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
|
||||||
|
callback(media)
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue