From 5df874ff43a871ec5aa525fd4932800272b8159a Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 7 Dec 2016 20:37:37 +0100 Subject: [PATCH] update the deletefiles function with stdlib --- .../gallery/activities/MediaActivity.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index e66a36236..aa4c60771 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -199,23 +199,22 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } override fun deleteFiles(files: ArrayList) { - for (file in files) { - if (file.exists() && file.isImageVideoGif()) { - if (needsStupidWritePermissions(file.absolutePath)) { - if (isShowingPermDialog(file)) - return + files.filter { it.exists() && it.isImageVideoGif() } + .forEach { + if (needsStupidWritePermissions(it.absolutePath)) { + if (isShowingPermDialog(it)) + return - val document = getFileDocument(file.absolutePath, mConfig.treeUri) + val document = getFileDocument(it.absolutePath, mConfig.treeUri) - // double check we have the uri to the proper file path, not some parent folder - if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) { - document.delete() + // double check we have the uri to the proper file path, not some parent folder + if (document.uri.toString().endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) { + document.delete() + } + } else { + it.delete() } - } else { - file.delete() } - } - } scanFiles(files) { if (mMedia.isEmpty()) {