improve file deleting from thumbnails view

This commit is contained in:
tibbi 2018-04-26 11:51:17 +02:00
parent be54d59bd0
commit 7600fa68b4
2 changed files with 16 additions and 11 deletions

View file

@ -671,22 +671,27 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
}
override fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
override fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) {
val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
deleteFiles(filtered) {
if (!it) {
toast(R.string.unknown_error_occurred)
} else if (mMedia.isEmpty()) {
deleteDirectoryIfEmpty()
deleteDBDirectory()
finish()
} else {
return@deleteFiles
}
mMedia.removeAll { filtered.map { it.path }.contains(it.path) }
Thread {
val mediumDao = galleryDB.MediumDao()
filtered.forEach {
mediumDao.deleteMediumPath(it.path)
}
}.start()
if (mMedia.isEmpty()) {
deleteDirectoryIfEmpty()
deleteDBDirectory()
finish()
}
}
}

View file

@ -241,7 +241,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
media.removeAll(removeMedia)
listener?.deleteFiles(fileDirItems)
listener?.tryDeleteFiles(fileDirItems)
removeSelectedItems()
}
}
@ -327,7 +327,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
interface MediaOperationsListener {
fun refreshItems()
fun deleteFiles(fileDirItems: ArrayList<FileDirItem>)
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>)
fun selectedPaths(paths: ArrayList<String>)
}