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 val filtered = fileDirItems.filter { it.path.isImageVideoGif() } as ArrayList
deleteFiles(filtered) { deleteFiles(filtered) {
if (!it) { if (!it) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} else if (mMedia.isEmpty()) { 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() deleteDirectoryIfEmpty()
deleteDBDirectory() deleteDBDirectory()
finish() finish()
} else {
Thread {
val mediumDao = galleryDB.MediumDao()
filtered.forEach {
mediumDao.deleteMediumPath(it.path)
}
}.start()
} }
} }
} }

View file

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