From a8c4b93fb5ee6e52de8d7d79a355f1abcc228bcb Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 15 Mar 2018 23:36:34 +0100 Subject: [PATCH] update stored directories if a file is deleted from the thumbnails view --- .../gallery/activities/MainActivity.kt | 6 +----- .../gallery/activities/MediaActivity.kt | 2 ++ .../gallery/extensions/Context.kt | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 5 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 d13e162f3..f82c8b100 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -13,7 +13,6 @@ import android.view.Menu import android.view.MenuItem import android.view.ViewGroup import android.widget.FrameLayout -import com.google.gson.Gson import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.NewAppDialog @@ -167,7 +166,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun onPause() { super.onPause() - storeDirectories() directories_refresh_layout.isRefreshing = false mIsGettingDirs = false storeStateVariables() @@ -616,9 +614,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun storeDirectories() { if (!config.temporarilyShowHidden && config.tempFolderPath.isEmpty()) { - val subList = mDirs.subList(0, Math.min(SAVE_DIRS_CNT, mDirs.size)) - val directories = Gson().toJson(subList) - config.directories = directories + storeDirectoryItems(mDirs) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 4463be0e8..9df15a242 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -675,6 +675,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } else if (mMedia.isEmpty()) { deleteDirectoryIfEmpty() finish() + } else { + updateStoredDirectories() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index b19200dab..fde901b01 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -14,9 +14,11 @@ import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.activities.SettingsActivity +import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA +import com.simplemobiletools.gallery.helpers.SAVE_DIRS_CNT import com.simplemobiletools.gallery.helpers.SAVE_MEDIA_CNT import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium @@ -148,3 +150,17 @@ fun Context.storeFolderItems(path: String, items: ArrayList) { } catch (ignored: OutOfMemoryError) { } } + +fun Context.updateStoredDirectories() { + GetDirectoriesAsynctask(this, false, false) { + if (!config.temporarilyShowHidden) { + storeDirectoryItems(it) + } + }.execute() +} + +fun Context.storeDirectoryItems(items: ArrayList) { + val subList = items.subList(0, Math.min(SAVE_DIRS_CNT, items.size)) + val directories = Gson().toJson(subList) + config.directories = directories +}