From 2bad1e20884b2dfc5ea506c1ca2801f8aae9343d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 24 May 2018 15:21:22 +0200 Subject: [PATCH] improve folder discovery after renaming --- app/build.gradle | 2 +- .../simplemobiletools/gallery/activities/EditActivity.kt | 2 +- .../gallery/activities/IncludedFoldersActivity.kt | 4 ++-- .../gallery/activities/PhotoVideoActivity.kt | 4 ++-- .../gallery/activities/ViewPagerActivity.kt | 6 +++--- .../simplemobiletools/gallery/adapters/DirectoryAdapter.kt | 5 ++++- .../com/simplemobiletools/gallery/extensions/Activity.kt | 4 ++-- .../simplemobiletools/gallery/interfaces/DirectoryDao.kt | 5 ++++- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 42bde0498..0f4cd0a71 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.0.23' + implementation 'com.simplemobiletools:commons:4.1.1' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 98d7909d5..79ea0700e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -261,7 +261,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } private fun scanFinalPath(path: String) { - scanPath(path) { + scanPathRecursively(path) { setResult(Activity.RESULT_OK, intent) toast(R.string.file_saved) finish() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt index cbbb5e701..ede3ab8d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -5,7 +5,7 @@ import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.scanPath +import com.simplemobiletools.commons.extensions.scanPathRecursively import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.ManageFoldersAdapter @@ -55,7 +55,7 @@ class IncludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener { config.addIncludedFolder(it) updateFolders() Thread { - scanPath(it) + scanPathRecursively(it) }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 3cd1fcecc..d230fa2f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -67,14 +67,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false) if (mUri!!.scheme == "file") { - scanPath(mUri!!.path) + scanPathRecursively(mUri!!.path) sendViewPagerIntent(mUri!!.path) finish() return } else { val path = applicationContext.getRealPathFromURI(mUri!!) ?: "" if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms") { - scanPath(mUri!!.path) + scanPathRecursively(mUri!!.path) sendViewPagerIntent(path) finish() return diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 1c6a30d40..95a5ed982 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -182,7 +182,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (!getDoesFilePathExist(mPath)) { Thread { - scanPath(mPath) + scanPathRecursively(mPath) }.start() finish() return @@ -554,7 +554,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } copyFile(tmpPath, newPath) - scanPath(newPath) + scanPathRecursively(newPath) toast(R.string.file_saved) if (config.keepLastModified) { @@ -833,7 +833,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View tryDeleteFileDirItem(fileDirItem, true) } - scanPath(mDirectory) + scanPathRecursively(mDirectory) } private fun checkOrientation() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index e1faec46d..66c7e08fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -169,7 +169,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList Unit) { val fileDocument = getDocumentFile(path) if (fileDocument?.exists() == true && fileDocument.isDirectory) { fileDocument.createFile("", NOMEDIA) - applicationContext.scanFile(file) { + applicationContext.scanFileRecursively(file) { callback() } } else { @@ -117,7 +117,7 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) { } else { try { file.createNewFile() - applicationContext.scanFile(file) { + applicationContext.scanFileRecursively(file) { callback() } } catch (e: Exception) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt index 62bef007a..c61717d95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/DirectoryDao.kt @@ -20,6 +20,9 @@ interface DirectoryDao { @Query("DELETE FROM directories WHERE path = :path") fun deleteDirPath(path: String) - @Query("UPDATE OR REPLACE directories SET thumbnail = :thumbnail, media_count = :mediaCnt, last_modified = :lastModified, date_taken = :dateTaken, size = :size, media_types = :mediaTypes WHERE path = :path") + @Query("UPDATE OR REPLACE directories SET thumbnail = :thumbnail, media_count = :mediaCnt, last_modified = :lastModified, date_taken = :dateTaken, size = :size, media_types = :mediaTypes WHERE path = :path") fun updateDirectory(path: String, thumbnail: String, mediaCnt: Int, lastModified: Long, dateTaken: Long, size: Long, mediaTypes: Int) + + @Query("UPDATE directories SET thumbnail = :thumbnail, filename = :name, path = :newPath WHERE path = :oldPath") + fun updateDirectoryAfterRename(thumbnail: String, name: String, newPath: String, oldPath: String) }