mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 06:17:59 +01:00
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)
|
if (mIsGettingDirs)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mIsGettingDirs = true
|
||||||
val token = object : TypeToken<List<Directory>>() {}.type
|
val token = object : TypeToken<List<Directory>>() {}.type
|
||||||
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||||
if (dirs.size == 0) {
|
if (dirs.size == 0) {
|
||||||
|
@ -138,7 +139,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
gotDirectories(dirs)
|
gotDirectories(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsGettingDirs = true
|
|
||||||
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) {
|
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) {
|
||||||
gotDirectories(it)
|
gotDirectories(it)
|
||||||
}.execute()
|
}.execute()
|
||||||
|
|
|
@ -13,6 +13,8 @@ import android.view.MenuItem
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.animation.GlideAnimation
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
import com.bumptech.glide.request.target.SimpleTarget
|
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.commons.extensions.*
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||||
|
@ -164,6 +166,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
return
|
return
|
||||||
|
|
||||||
mIsGettingMedia = true
|
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) {
|
GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mShowAll) {
|
||||||
gotMedia(it)
|
gotMedia(it)
|
||||||
}.execute()
|
}.execute()
|
||||||
|
@ -277,6 +287,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
|
|
||||||
mMedia = media
|
mMedia = media
|
||||||
initializeGallery()
|
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() {
|
override fun refreshItems() {
|
||||||
|
|
|
@ -68,6 +68,12 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
|
|
||||||
fun getIsFolderHidden(path: String) = hiddenFolders.contains(path)
|
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>
|
var hiddenFolders: MutableSet<String>
|
||||||
get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
|
get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
|
||||||
set(hiddenFolders) = prefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
|
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 MEDIA_COLUMN_CNT = "media_column_cnt"
|
||||||
val SHOW_ALL = "show_all" // display images and videos from all folders together
|
val SHOW_ALL = "show_all" // display images and videos from all folders together
|
||||||
val SHOW_MEDIA = "show_media"
|
val SHOW_MEDIA = "show_media"
|
||||||
|
val SAVE_FOLDER_PREFIX = "folder_"
|
||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
val SORT_BY_NAME = 1
|
val SORT_BY_NAME = 1
|
||||||
|
|
Loading…
Reference in a new issue