diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 172977392..a52935acb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -200,17 +200,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } Thread({ - if (needsPermissions) { - val document = getFileDocument(file.absolutePath, config.treeUri) + if (!file.delete()) { + if (needsPermissions) { + val document = getFileDocument(file.absolutePath, config.treeUri) - // double check we have the uri to the proper file path, not some parent folder - val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") - val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8") - if (uri.endsWith(filename)) { - document.delete() + // double check we have the uri to the proper file path, not some parent folder + val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") + val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8") + if (uri.endsWith(filename)) { + document.delete() + } } - } else { - file.delete() } }).start() } 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 08f2f150b..8526d2a95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -237,19 +237,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { var hadSuccess = false files.filter { it.exists() && it.isImageVideoGif() } .forEach { - if (needsPermissions) { - val document = getFileDocument(it.absolutePath, config.treeUri) + if (!it.delete()) { + if (needsPermissions) { + val document = getFileDocument(it.absolutePath, config.treeUri) - // double check we have the uri to the proper file path, not some parent folder - val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") - val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8") - if (uri.endsWith(filename) && !document.isDirectory) { - if (document.delete()) - hadSuccess = true - } - } else { - if (it.delete()) + // double check we have the uri to the proper file path, not some parent folder + val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") + val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8") + if (uri.endsWith(filename) && !document.isDirectory) { + if (document.delete()) + hadSuccess = true + } + } else { hadSuccess = true + } } deleteFromMediaStore(it) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 7bb2844ed..e09131c1b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -8,6 +8,7 @@ import android.graphics.BitmapFactory import android.graphics.Matrix import android.media.ExifInterface import android.net.Uri +import android.os.Build import android.os.Bundle import android.provider.MediaStore import android.support.v4.view.ViewPager @@ -286,7 +287,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return (floatD + floatM / 60 + floatS / 3600).toFloat() } - override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { if (requestCode == REQUEST_EDIT_IMAGE) { if (resultCode == Activity.RESULT_OK && resultData != null) { @@ -314,23 +314,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } - Thread({ - if (needsPermissions) { - val document = getFileDocument(file.absolutePath, config.treeUri) + Thread { + if (!file.delete()) { + if (needsPermissions) { + val document = getFileDocument(file.absolutePath, config.treeUri) - // double check we have the uri to the proper file path, not some parent folder - val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") - val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8") - if (uri.endsWith(filename) && !document.isDirectory) { - document.delete() - } else { - runOnUiThread { - toast(R.string.unknown_error_occurred) + // double check we have the uri to the proper file path, not some parent folder + val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") + val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8") + if (uri.endsWith(filename) && !document.isDirectory) { + document.delete() + } else { + runOnUiThread { + toast(R.string.unknown_error_occurred) + } + return@Thread } - return@Thread } - } else { - file.delete() } if (deleteFromMediaStore(file)) { @@ -340,7 +340,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View reloadViewPager() } } - }).start() + }.start() } private fun isDirEmpty(): Boolean {