properly update files after renaming in the local database

This commit is contained in:
tibbi 2018-04-21 22:19:27 +02:00
parent 505c5a7e37
commit 0039591a53
7 changed files with 34 additions and 14 deletions

View file

@ -47,7 +47,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.19.5' implementation 'com.simplemobiletools:commons:3.19.7'
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

@ -657,15 +657,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) { override fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
deleteFiles(filtered) { deleteFiles(filtered) {
Thread {
val mediumDao = galleryDB.MediumDao()
filtered.forEach {
if (!File(it.path).exists()) {
mediumDao.deleteMediumPath(it.path)
}
}
}.start()
if (!it) { if (!it) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} else if (mMedia.isEmpty()) { } else if (mMedia.isEmpty()) {
@ -673,6 +664,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
finish() finish()
} else { } else {
updateStoredDirectories() updateStoredDirectories()
Thread {
val mediumDao = galleryDB.MediumDao()
filtered.forEach {
mediumDao.deleteMediumPath(it.path)
}
}.start()
} }
} }
} }

View file

@ -757,8 +757,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun renameFile() { private fun renameFile() {
RenameItemDialog(this, getCurrentPath()) { val oldPath = getCurrentPath()
getCurrentMedia()[mPos].path = it RenameItemDialog(this, oldPath) {
getCurrentMedia()[mPos].apply {
path = it
name = it.getFilenameFromPath()
}
Thread {
updateMediaPath(oldPath, it)
}.start()
updateActionbarTitle() updateActionbarTitle()
} }
} }

View file

@ -148,7 +148,12 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
} }
private fun renameFile() { private fun renameFile() {
RenameItemDialog(activity, getCurrentPath()) { val oldPath = getCurrentPath()
RenameItemDialog(activity, oldPath) {
Thread {
activity.updateMediaPath(oldPath, it)
}.start()
activity.runOnUiThread { activity.runOnUiThread {
listener?.refreshItems() listener?.refreshItems()
finishActMode() finishActMode()

View file

@ -267,3 +267,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
} }
}.start() }.start()
} }
fun Context.updateMediaPath(oldPath: String, newPath: String) {
val newFilename = newPath.getFilenameFromPath()
val newParentPath = newPath.getParentPath()
galleryDB.MediumDao().updateMedia(oldPath, newParentPath, newFilename, newPath)
}

View file

@ -22,4 +22,7 @@ interface MediumDao {
@Query("DELETE FROM media WHERE full_path = :path") @Query("DELETE FROM media WHERE full_path = :path")
fun deleteMediumPath(path: String) fun deleteMediumPath(path: String)
@Query("UPDATE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath")
fun updateMedia(oldPath: String, newParentPath: String, newFilename: String, newFullPath: String)
} }

View file

@ -97,7 +97,7 @@
<string name="slideshow">Slideshow</string> <string name="slideshow">Slideshow</string>
<string name="interval">Frekvens (sekunder):</string> <string name="interval">Frekvens (sekunder):</string>
<string name="include_photos">Inkluder billeder</string> <string name="include_photos">Inkluder billeder</string>
<string name="include_videos">Inkluder videoer/string> <string name="include_videos">Inkluder videoer</string>
<string name="include_gifs">Inkluder GIF\'er</string> <string name="include_gifs">Inkluder GIF\'er</string>
<string name="random_order">Tilfældig rækkefølge</string> <string name="random_order">Tilfældig rækkefølge</string>
<string name="use_fade">Use fade animations</string> <string name="use_fade">Use fade animations</string>