store the new folder path in shared prefs, so its more accessible

This commit is contained in:
tibbi 2017-09-05 21:58:22 +02:00
parent 551fc3a1c6
commit 189f9b7410
3 changed files with 13 additions and 6 deletions

View File

@ -57,7 +57,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private var mLoadedInitialPhotos = false
private var mLastMediaModified = 0
private var mLastMediaHandler = Handler()
private var mNewFolderPath = ""
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
@ -74,6 +73,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent ||
mIsGetAnyContentIntent || mIsSetWallpaperIntent
config.tempFolderPath = ""
directories_refresh_layout.setOnRefreshListener({ getDirectories() })
mDirs = ArrayList()
mStoredAnimateGifs = config.animateGifs
@ -160,12 +160,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
super.onDestroy()
config.temporarilyShowHidden = false
val newFolder = File(mNewFolderPath)
val newFolder = File(config.tempFolderPath)
if (newFolder.exists() && newFolder.isDirectory) {
if (newFolder.list()?.isEmpty() == true) {
deleteFileBg(newFolder, true) { }
}
}
config.tempFolderPath = ""
}
private fun tryloadGallery() {
@ -314,7 +315,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun createNewFolder() {
FilePickerDialog(this, internalStoragePath, false, config.shouldShowHidden) {
CreateNewFolderDialog(this, it) {
mNewFolderPath = it
config.tempFolderPath = it
addTempFolderIfNeeded(mDirs, true)
}
}
@ -322,8 +323,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun addTempFolderIfNeeded(dirs: ArrayList<Directory>, isFromCache: Boolean) {
val directories = ArrayList<Directory>()
if (mNewFolderPath.isNotEmpty()) {
val newFolder = Directory(mNewFolderPath, "", mNewFolderPath.getFilenameFromPath(), 0, 0, 0, 0L)
val tempFolderPath = config.tempFolderPath
if (tempFolderPath.isNotEmpty()) {
val newFolder = Directory(tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L)
directories.add(newFolder)
}
directories.addAll(dirs)
@ -449,7 +451,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
private fun storeDirectories() {
if (!config.temporarilyShowHidden && mNewFolderPath.isEmpty()) {
if (!config.temporarilyShowHidden && config.tempFolderPath.isEmpty()) {
val directories = Gson().toJson(mDirs)
config.directories = directories
}

View File

@ -276,4 +276,8 @@ class Config(context: Context) : BaseConfig(context) {
var loopSlideshow: Boolean
get() = prefs.getBoolean(SLIDESHOW_LOOP, false)
set(loopSlideshow) = prefs.edit().putBoolean(SLIDESHOW_LOOP, loopSlideshow).apply()
var tempFolderPath: String
get() = prefs.getString(TEMP_FOLDER_PATH, "")
set(tempFolderPath) = prefs.edit().putString(TEMP_FOLDER_PATH, tempFolderPath).apply()
}

View File

@ -36,6 +36,7 @@ val HIDE_SYSTEM_UI = "hide_system_ui"
val REPLACE_SHARE_WITH_ROTATE = "replace_share_with_rotate"
val DELETE_EMPTY_FOLDERS = "delete_empty_folders"
val ALLOW_VIDEO_GESTURES = "allow_video_gestures"
val TEMP_FOLDER_PATH = "temp_folder_path"
// slideshow
val SLIDESHOW_INTERVAL = "slideshow_interval"