From a0ec0de5a4c6cf2aab3dadf2a89cae1de76719b4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 8 Jan 2017 22:45:11 +0100 Subject: [PATCH] couple threading fixes related to delete --- .../gallery/activities/MainActivity.kt | 11 ++++++++--- .../gallery/activities/MediaActivity.kt | 8 ++++++-- .../gallery/activities/ViewPagerActivity.kt | 12 +++++++----- .../gallery/adapters/DirectoryAdapter.kt | 8 ++------ .../gallery/adapters/MediaAdapter.kt | 8 ++------ 5 files changed, 25 insertions(+), 22 deletions(-) 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 6449a73fa..4b113535f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -190,11 +190,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val document = getFileDocument(file.absolutePath, config.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() + if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) { + Thread({ + document.delete() + }).start() + } } } else { - file.delete() + Thread({ + 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 ea631f811..6b7e6e29b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -214,10 +214,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { // 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() + Thread({ + document.delete() + }).start() } } else { - it.delete() + Thread({ + it.delete() + }).start() } 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 3b843fe28..e515d7b4f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -160,9 +160,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun askConfirmDelete() { ConfirmationDialog(this) { - Thread({ - deleteFile() - }).start() + deleteFile() } } @@ -175,10 +173,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (!isShowingPermDialog(file)) { val document = getFileDocument(mPath, config.treeUri) if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) - document.delete() + Thread({ + document.delete() + }).start() } } else { - file.delete() + Thread({ + file.delete() + }).start() } if (deleteFromMediaStore(file)) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index b266165ed..27c61a373 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -231,9 +231,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, private fun askConfirmDelete() { ConfirmationDialog(activity) { actMode?.finish() - Thread({ - deleteFiles() - }).start() + deleteFiles() } } @@ -189,9 +187,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val medium = media[it] files.add(File(medium.path)) removeMedia.add(medium) - activity.runOnUiThread { - notifyItemRemoved(it) - } + notifyItemRemoved(it) } media.removeAll(removeMedia)