cache the directories to show instantly

This commit is contained in:
tibbi 2017-01-04 22:06:03 +01:00
parent 09b3aced82
commit e3779f6321
4 changed files with 21 additions and 3 deletions

View file

@ -14,6 +14,8 @@ import android.support.v7.widget.GridLayoutManager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.gallery.BuildConfig
@ -97,6 +99,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
override fun onPause() {
super.onPause()
deleteDirs()
storeDirectories()
}
override fun onDestroy() {
@ -135,6 +138,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
if (mIsGettingDirs)
return
val token = object : TypeToken<List<Directory>>() {}.type
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
gotDirectories(dirs)
mIsGettingDirs = true
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent, mToBeDeleted) {
gotDirectories(it)
@ -329,6 +336,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mDirs = dirs
setupAdapter()
storeDirectories()
}
fun storeDirectories() {
val directories = Gson().toJson(mDirs)
config.directories = directories
}
private fun setupAdapter() {

View file

@ -95,4 +95,8 @@ class Config(context: Context) : BaseConfig(context) {
var mediaColumnCnt: Int
get() = prefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns))
set(mediaColumnCnt) = prefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply()
var directories: String
get() = prefs.getString(DIRECTORIES, "")
set(directories) = prefs.edit().putString(DIRECTORIES, directories).apply()
}

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.gallery.helpers
// shared preferences
val PREFS_KEY = "Gallery"
val IS_SAME_SORTING = "is_same_sorting"
val SORT_ORDER = "sort_order"
val DIRECTORY_SORT_ORDER = "directory_sort_order"
@ -23,13 +22,13 @@ val SORT_BY_SIZE = 4
val SORT_BY_DATE_TAKEN = 8
val SORT_DESCENDING = 1024
val DIRECTORY = "directory"
val MEDIUM = "medium"
val GET_IMAGE_INTENT = "get_image_intent"
val GET_VIDEO_INTENT = "get_video_intent"
val GET_ANY_INTENT = "get_any_intent"
val SET_WALLPAPER_INTENT = "set_wallpaper_intent"
val DIRECTORIES = "directories"
val REQUEST_EDIT_IMAGE = 1
val REQUEST_SET_WALLPAPER = 2

View file

@ -4,10 +4,12 @@ import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.gallery.helpers.SORT_BY_NAME
import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE
import com.simplemobiletools.gallery.helpers.SORT_DESCENDING
import java.io.Serializable
data class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val date_modified: Long, val date_taken: Long,
var size: Long) : Comparable<Directory> {
var size: Long) : Serializable, Comparable<Directory> {
companion object {
private val serialVersionUID = -6553649863575455L
var sorting: Int = 0
}