mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-27 06:57: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_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,20 +636,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
mIsGettingMedia = false
|
mIsGettingMedia = false
|
||||||
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())
|
|
||||||
|
|
||||||
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
|
||||||
media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
|
|
||||||
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
|
||||||
|
|
||||||
checkLastMediaChanged()
|
checkLastMediaChanged()
|
||||||
|
|
||||||
mMedia = media
|
mMedia = media
|
||||||
|
|
||||||
runOnUiThread {
|
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())
|
||||||
|
|
||||||
|
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFiles == VIEW_TYPE_GRID
|
||||||
|
media_vertical_fastscroller.beVisibleIf(media_grid.isVisible() && !allowHorizontalScroll)
|
||||||
|
media_horizontal_fastscroller.beVisibleIf(media_grid.isVisible() && allowHorizontalScroll)
|
||||||
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,12 +33,14 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() })
|
.setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() })
|
||||||
.create().apply {
|
.create().apply {
|
||||||
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) {
|
||||||
if (media.isNotEmpty()) {
|
val media = it.filter { !it.isVideo() } as ArrayList
|
||||||
gotMedia(media)
|
if (media.isNotEmpty()) {
|
||||||
|
gotMedia(media)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMediaAsynctask(activity, path, false, true, false) {
|
GetMediaAsynctask(activity, path, false, true, false) {
|
||||||
|
|
|
@ -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