fix deleting Recycle Bin files

This commit is contained in:
tibbi 2018-12-02 20:53:25 +01:00
parent 6098c24227
commit 88b13012aa
4 changed files with 10 additions and 6 deletions

View file

@ -847,7 +847,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
if (!curMedia.contains(it)) {
val path = (it as? Medium)?.path
if (path != null) {
mMediumDao.deleteMediumPath(path)
deleteDBPath(mMediumDao, path)
}
}
}

View file

@ -884,8 +884,8 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
Thread {
val useRecycleBin = config.useRecycleBin
filtered.forEach {
if (!useRecycleBin) {
mMediumDao.deleteMediumPath(it.path)
if (it.path.startsWith(recycleBinPath) || !useRecycleBin) {
deleteDBPath(mMediumDao, it.path)
}
}
}.start()

View file

@ -193,7 +193,7 @@ fun BaseSimpleActivity.tryDeleteFileDirItem(fileDirItem: FileDirItem, allowDelet
deleteFile(fileDirItem, allowDeleteFolder) {
if (deleteFromDatabase) {
Thread {
galleryDB.MediumDao().deleteMediumPath(fileDirItem.path)
deleteDBPath(galleryDB.MediumDao(), fileDirItem.path)
runOnUiThread {
callback?.invoke(it)
}

View file

@ -218,7 +218,7 @@ fun Context.rescanFolderMediaSync(path: String) {
if (!newMedia.contains(it)) {
val mediumPath = (it as? Medium)?.path
if (mediumPath != null) {
mediumDao.deleteMediumPath(mediumPath)
deleteDBPath(mediumDao, mediumPath)
}
}
}
@ -437,7 +437,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
val mediaToDelete = ArrayList<Medium>()
media.filter { !getDoesFilePathExist(it.path) }.forEach {
if (it.path.startsWith(recycleBinPath)) {
mediumDao.deleteMediumPath(it.path.removePrefix(recycleBinPath))
deleteDBPath(mediumDao, it.path)
} else {
mediaToDelete.add(it)
}
@ -478,3 +478,7 @@ fun Context.getUpdatedDeletedMedia(mediumDao: MediumDao): ArrayList<Medium> {
}
return media
}
fun Context.deleteDBPath(mediumDao: MediumDao, path: String) {
mediumDao.deleteMediumPath(path.replaceFirst(recycleBinPath, RECYCLE_BIN))
}