cache 30 images per folder for faster loading the second time
This commit is contained in:
parent
a259a0240c
commit
8b37560ed4
4 changed files with 25 additions and 1 deletions
|
@ -130,6 +130,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
if (mIsGettingDirs)
|
||||
return
|
||||
|
||||
mIsGettingDirs = true
|
||||
val token = object : TypeToken<List<Directory>>() {}.type
|
||||
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||
if (dirs.size == 0) {
|
||||
|
@ -138,7 +139,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
gotDirectories(dirs)
|
||||
}
|
||||
|
||||
mIsGettingDirs = true
|
||||
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) {
|
||||
gotDirectories(it)
|
||||
}.execute()
|
||||
|
|
|
@ -13,6 +13,8 @@ import android.view.MenuItem
|
|||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.animation.GlideAnimation
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||
|
@ -164,6 +166,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
return
|
||||
|
||||
mIsGettingMedia = true
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
val media = Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(mPath), token) ?: ArrayList<Medium>(1)
|
||||
if (media.size == 0) {
|
||||
media_holder.isRefreshing = true
|
||||
} else {
|
||||
gotMedia(media)
|
||||
}
|
||||
|
||||
GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mShowAll) {
|
||||
gotMedia(it)
|
||||
}.execute()
|
||||
|
@ -277,6 +287,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
mMedia = media
|
||||
initializeGallery()
|
||||
storeFolder()
|
||||
}
|
||||
|
||||
private fun storeFolder() {
|
||||
val subList = mMedia.subList(0, Math.min(30, mMedia.size))
|
||||
val json = Gson().toJson(subList)
|
||||
config.saveFolderMedia(mPath, json)
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
|
|
|
@ -68,6 +68,12 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
|
||||
fun getIsFolderHidden(path: String) = hiddenFolders.contains(path)
|
||||
|
||||
fun saveFolderMedia(path: String, json: String) {
|
||||
prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply()
|
||||
}
|
||||
|
||||
fun loadFolderMedia(path: String) = prefs.getString(SAVE_FOLDER_PREFIX + path, "")
|
||||
|
||||
var hiddenFolders: MutableSet<String>
|
||||
get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
|
||||
set(hiddenFolders) = prefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
|
||||
|
|
|
@ -14,6 +14,7 @@ val DIR_COLUMN_CNT = "dir_column_cnt"
|
|||
val MEDIA_COLUMN_CNT = "media_column_cnt"
|
||||
val SHOW_ALL = "show_all" // display images and videos from all folders together
|
||||
val SHOW_MEDIA = "show_media"
|
||||
val SAVE_FOLDER_PREFIX = "folder_"
|
||||
|
||||
// sorting
|
||||
val SORT_BY_NAME = 1
|
||||
|
|
Loading…
Reference in a new issue