mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
cache the directories to show instantly
This commit is contained in:
parent
09b3aced82
commit
e3779f6321
4 changed files with 21 additions and 3 deletions
|
@ -14,6 +14,8 @@ import android.support.v7.widget.GridLayoutManager
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.gallery.BuildConfig
|
import com.simplemobiletools.gallery.BuildConfig
|
||||||
|
@ -97,6 +99,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
deleteDirs()
|
deleteDirs()
|
||||||
|
storeDirectories()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -135,6 +138,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
if (mIsGettingDirs)
|
if (mIsGettingDirs)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
val token = object : TypeToken<List<Directory>>() {}.type
|
||||||
|
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||||
|
gotDirectories(dirs)
|
||||||
|
|
||||||
mIsGettingDirs = true
|
mIsGettingDirs = true
|
||||||
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent, mToBeDeleted) {
|
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent, mToBeDeleted) {
|
||||||
gotDirectories(it)
|
gotDirectories(it)
|
||||||
|
@ -329,6 +336,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
mDirs = dirs
|
mDirs = dirs
|
||||||
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
|
storeDirectories()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun storeDirectories() {
|
||||||
|
val directories = Gson().toJson(mDirs)
|
||||||
|
config.directories = directories
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
|
|
|
@ -95,4 +95,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
var mediaColumnCnt: Int
|
var mediaColumnCnt: Int
|
||||||
get() = prefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns))
|
get() = prefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns))
|
||||||
set(mediaColumnCnt) = prefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply()
|
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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.helpers
|
package com.simplemobiletools.gallery.helpers
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
val PREFS_KEY = "Gallery"
|
|
||||||
val IS_SAME_SORTING = "is_same_sorting"
|
val IS_SAME_SORTING = "is_same_sorting"
|
||||||
val SORT_ORDER = "sort_order"
|
val SORT_ORDER = "sort_order"
|
||||||
val DIRECTORY_SORT_ORDER = "directory_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_BY_DATE_TAKEN = 8
|
||||||
val SORT_DESCENDING = 1024
|
val SORT_DESCENDING = 1024
|
||||||
|
|
||||||
|
|
||||||
val DIRECTORY = "directory"
|
val DIRECTORY = "directory"
|
||||||
val MEDIUM = "medium"
|
val MEDIUM = "medium"
|
||||||
val GET_IMAGE_INTENT = "get_image_intent"
|
val GET_IMAGE_INTENT = "get_image_intent"
|
||||||
val GET_VIDEO_INTENT = "get_video_intent"
|
val GET_VIDEO_INTENT = "get_video_intent"
|
||||||
val GET_ANY_INTENT = "get_any_intent"
|
val GET_ANY_INTENT = "get_any_intent"
|
||||||
val SET_WALLPAPER_INTENT = "set_wallpaper_intent"
|
val SET_WALLPAPER_INTENT = "set_wallpaper_intent"
|
||||||
|
val DIRECTORIES = "directories"
|
||||||
|
|
||||||
val REQUEST_EDIT_IMAGE = 1
|
val REQUEST_EDIT_IMAGE = 1
|
||||||
val REQUEST_SET_WALLPAPER = 2
|
val REQUEST_SET_WALLPAPER = 2
|
||||||
|
|
|
@ -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_NAME
|
||||||
import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE
|
import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE
|
||||||
import com.simplemobiletools.gallery.helpers.SORT_DESCENDING
|
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,
|
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 {
|
companion object {
|
||||||
|
private val serialVersionUID = -6553649863575455L
|
||||||
var sorting: Int = 0
|
var sorting: Int = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue