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 {
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.android.support:multidex:1.0.3'
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>) {
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
deleteFiles(filtered) {
Thread {
val mediumDao = galleryDB.MediumDao()
filtered.forEach {
if (!File(it.path).exists()) {
mediumDao.deleteMediumPath(it.path)
}
}
}.start()
if (!it) {
toast(R.string.unknown_error_occurred)
} else if (mMedia.isEmpty()) {
@ -673,6 +664,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
finish()
} else {
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() {
RenameItemDialog(this, getCurrentPath()) {
getCurrentMedia()[mPos].path = it
val oldPath = getCurrentPath()
RenameItemDialog(this, oldPath) {
getCurrentMedia()[mPos].apply {
path = it
name = it.getFilenameFromPath()
}
Thread {
updateMediaPath(oldPath, it)
}.start()
updateActionbarTitle()
}
}

View file

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

View file

@ -267,3 +267,9 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
}
}.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")
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="interval">Frekvens (sekunder):</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="random_order">Tilfældig rækkefølge</string>
<string name="use_fade">Use fade animations</string>