update stored directories if a file is deleted from the thumbnails view

This commit is contained in:
tibbi 2018-03-15 23:36:34 +01:00
parent fa201e6524
commit a8c4b93fb5
3 changed files with 19 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -675,6 +675,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} else if (mMedia.isEmpty()) {
deleteDirectoryIfEmpty()
finish()
} else {
updateStoredDirectories()
}
}
}

View File

@ -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<Medium>) {
} catch (ignored: OutOfMemoryError) {
}
}
fun Context.updateStoredDirectories() {
GetDirectoriesAsynctask(this, false, false) {
if (!config.temporarilyShowHidden) {
storeDirectoryItems(it)
}
}.execute()
}
fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
val subList = items.subList(0, Math.min(SAVE_DIRS_CNT, items.size))
val directories = Gson().toJson(subList)
config.directories = directories
}