improve folder discovery after renaming

This commit is contained in:
tibbi 2018-05-24 15:21:22 +02:00
parent 4248d87be5
commit 2bad1e2088
8 changed files with 19 additions and 13 deletions

View File

@ -47,7 +47,7 @@ ext {
} }
dependencies { 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.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View File

@ -261,7 +261,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
} }
private fun scanFinalPath(path: String) { private fun scanFinalPath(path: String) {
scanPath(path) { scanPathRecursively(path) {
setResult(Activity.RESULT_OK, intent) setResult(Activity.RESULT_OK, intent)
toast(R.string.file_saved) toast(R.string.file_saved)
finish() finish()

View File

@ -5,7 +5,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.beVisibleIf 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.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.adapters.ManageFoldersAdapter import com.simplemobiletools.gallery.adapters.ManageFoldersAdapter
@ -55,7 +55,7 @@ class IncludedFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
config.addIncludedFolder(it) config.addIncludedFolder(it)
updateFolders() updateFolders()
Thread { Thread {
scanPath(it) scanPathRecursively(it)
}.start() }.start()
} }
} }

View File

@ -67,14 +67,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false) mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false)
if (mUri!!.scheme == "file") { if (mUri!!.scheme == "file") {
scanPath(mUri!!.path) scanPathRecursively(mUri!!.path)
sendViewPagerIntent(mUri!!.path) sendViewPagerIntent(mUri!!.path)
finish() finish()
return return
} else { } else {
val path = applicationContext.getRealPathFromURI(mUri!!) ?: "" val path = applicationContext.getRealPathFromURI(mUri!!) ?: ""
if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms") { if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms") {
scanPath(mUri!!.path) scanPathRecursively(mUri!!.path)
sendViewPagerIntent(path) sendViewPagerIntent(path)
finish() finish()
return return

View File

@ -182,7 +182,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (!getDoesFilePathExist(mPath)) { if (!getDoesFilePathExist(mPath)) {
Thread { Thread {
scanPath(mPath) scanPathRecursively(mPath)
}.start() }.start()
finish() finish()
return return
@ -554,7 +554,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
copyFile(tmpPath, newPath) copyFile(tmpPath, newPath)
scanPath(newPath) scanPathRecursively(newPath)
toast(R.string.file_saved) toast(R.string.file_saved)
if (config.keepLastModified) { if (config.keepLastModified) {
@ -833,7 +833,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
tryDeleteFileDirItem(fileDirItem, true) tryDeleteFileDirItem(fileDirItem, true)
} }
scanPath(mDirectory) scanPathRecursively(mDirectory)
} }
private fun checkOrientation() { private fun checkOrientation() {

View File

@ -169,7 +169,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
tmb = File(it, tmb.getFilenameFromPath()).absolutePath tmb = File(it, tmb.getFilenameFromPath()).absolutePath
} }
updateDirs(dirs) updateDirs(dirs)
listener?.updateDirectories(dirs.toList() as ArrayList) Thread {
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
listener?.refreshItems()
}.start()
} }
} }
} }

View File

@ -106,7 +106,7 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
val fileDocument = getDocumentFile(path) val fileDocument = getDocumentFile(path)
if (fileDocument?.exists() == true && fileDocument.isDirectory) { if (fileDocument?.exists() == true && fileDocument.isDirectory) {
fileDocument.createFile("", NOMEDIA) fileDocument.createFile("", NOMEDIA)
applicationContext.scanFile(file) { applicationContext.scanFileRecursively(file) {
callback() callback()
} }
} else { } else {
@ -117,7 +117,7 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
} else { } else {
try { try {
file.createNewFile() file.createNewFile()
applicationContext.scanFile(file) { applicationContext.scanFileRecursively(file) {
callback() callback()
} }
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -22,4 +22,7 @@ interface DirectoryDao {
@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) 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)
} }