From 7ebc110ac88541e4940fda8868479a8f55925734 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 15 Mar 2018 21:49:58 +0100 Subject: [PATCH] rescan and cache destination path after copy --- app/build.gradle | 2 +- .../gallery/activities/MediaActivity.kt | 9 +-------- .../gallery/adapters/MediaAdapter.kt | 1 + .../gallery/extensions/Activity.kt | 2 +- .../gallery/extensions/Context.kt | 20 +++++++++++++++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6d04656a0..bdd2e235e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.16.9' + implementation 'com.simplemobiletools:commons:3.16.10' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.code.gson:gson:2.8.2' 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 92e2decf5..4463be0e8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -20,7 +20,6 @@ import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition -import com.google.gson.Gson import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* @@ -663,13 +662,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private fun storeFolder() { if (!config.temporarilyShowHidden) { Thread { - try { - val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size)) - val json = Gson().toJson(subList) - config.saveFolderMedia(mPath, json) - } catch (ignored: Exception) { - } catch (ignored: OutOfMemoryError) { - } + storeFolderItems(mPath, mMedia) }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 70dc22f94..b5c043d9c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -187,6 +187,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { config.tempFolderPath = "" + activity.applicationContext.updateStoredFolderItems(it) if (!isCopyOperation) { listener?.refreshItems() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index c1c0e0dbd..c27b19fc9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -183,7 +183,7 @@ fun Activity.loadImage(type: Int, path: String, target: MySquareImageView, horiz } } -fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, isCopyOperation: Boolean, callback: () -> Unit) { +fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList, isCopyOperation: Boolean, callback: (destinationPath: String) -> Unit) { if (fileDirItems.isEmpty()) { toast(R.string.unknown_error_occurred) return 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 1be5ed7d8..b19200dab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -9,13 +9,17 @@ import android.media.AudioManager import android.os.Build import android.provider.MediaStore import android.view.WindowManager +import com.google.gson.Gson 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.GetMediaAsynctask import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA +import com.simplemobiletools.gallery.helpers.SAVE_MEDIA_CNT import com.simplemobiletools.gallery.models.Directory +import com.simplemobiletools.gallery.models.Medium import java.io.File val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT @@ -128,3 +132,19 @@ fun Context.isPathInMediaStore(path: String): Boolean { } return false } + +fun Context.updateStoredFolderItems(path: String) { + GetMediaAsynctask(this, path, false, false, false) { + storeFolderItems(path, it) + }.execute() +} + +fun Context.storeFolderItems(path: String, items: ArrayList) { + try { + val subList = items.subList(0, Math.min(SAVE_MEDIA_CNT, items.size)) + val json = Gson().toJson(subList) + config.saveFolderMedia(path, json) + } catch (ignored: Exception) { + } catch (ignored: OutOfMemoryError) { + } +}