show error messages if deleting failed

This commit is contained in:
tibbi 2017-02-10 23:59:28 +01:00
parent 67a459ced7
commit 0c2598d37b
2 changed files with 14 additions and 2 deletions

View file

@ -235,6 +235,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
Thread({ Thread({
var hadSuccess = false
files.filter { it.exists() && it.isImageVideoGif() } files.filter { it.exists() && it.isImageVideoGif() }
.forEach { .forEach {
if (needsPermissions) { if (needsPermissions) {
@ -244,13 +245,19 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8") val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8")
if (uri.endsWith(filename) && !document.isDirectory) { if (uri.endsWith(filename) && !document.isDirectory) {
document.delete() if (document.delete())
hadSuccess = true
} }
} else { } else {
it.delete() if (it.delete())
hadSuccess = true
} }
deleteFromMediaStore(it) deleteFromMediaStore(it)
} }
if (!hadSuccess)
runOnUiThread {
toast(R.string.unknown_error_occurred)
}
}).start() }).start()
if (mMedia.isEmpty()) { if (mMedia.isEmpty()) {

View file

@ -246,6 +246,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8") val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
if (uri.endsWith(filename) && !document.isDirectory) { if (uri.endsWith(filename) && !document.isDirectory) {
document.delete() document.delete()
} else {
runOnUiThread {
toast(R.string.unknown_error_occurred)
}
return@Thread
} }
} else { } else {
file.delete() file.delete()