From 189f9b7410893684a8918bf070c20905ff88f0fb Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Sep 2017 21:58:22 +0200 Subject: [PATCH] store the new folder path in shared prefs, so its more accessible --- .../gallery/activities/MainActivity.kt | 14 ++++++++------ .../simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../simplemobiletools/gallery/helpers/Constants.kt | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index e1dcac814..ad77fa735 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -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, isFromCache: Boolean) { val directories = ArrayList() - 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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 9fa94ce47..f17e9eed1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 7b743837f..705c91d76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -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"