couple threading fixes related to delete

This commit is contained in:
tibbi 2017-01-08 22:45:11 +01:00
parent 051ba24296
commit a0ec0de5a4
5 changed files with 25 additions and 22 deletions

View file

@ -190,11 +190,16 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val document = getFileDocument(file.absolutePath, config.treeUri) val document = getFileDocument(file.absolutePath, config.treeUri)
// double check we have the uri to the proper file path, not some parent folder // 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) if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) {
document.delete() Thread({
document.delete()
}).start()
}
} }
} else { } else {
file.delete() Thread({
file.delete()
}).start()
} }
} }

View file

@ -214,10 +214,14 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
// double check we have the uri to the proper file path, not some parent folder // 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) { if (document.uri.toString().endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
document.delete() Thread({
document.delete()
}).start()
} }
} else { } else {
it.delete() Thread({
it.delete()
}).start()
} }
deleteFromMediaStore(it) deleteFromMediaStore(it)

View file

@ -160,9 +160,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun askConfirmDelete() { private fun askConfirmDelete() {
ConfirmationDialog(this) { ConfirmationDialog(this) {
Thread({ deleteFile()
deleteFile()
}).start()
} }
} }
@ -175,10 +173,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (!isShowingPermDialog(file)) { if (!isShowingPermDialog(file)) {
val document = getFileDocument(mPath, config.treeUri) val document = getFileDocument(mPath, config.treeUri)
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory)
document.delete() Thread({
document.delete()
}).start()
} }
} else { } else {
file.delete() Thread({
file.delete()
}).start()
} }
if (deleteFromMediaStore(file)) { if (deleteFromMediaStore(file)) {

View file

@ -231,9 +231,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
private fun askConfirmDelete() { private fun askConfirmDelete() {
ConfirmationDialog(activity) { ConfirmationDialog(activity) {
actMode?.finish() actMode?.finish()
Thread({ deleteFiles()
deleteFiles()
}).start()
} }
} }
@ -247,9 +245,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val directory = dirs[it] val directory = dirs[it]
paths.add(directory.path) paths.add(directory.path)
removeDirs.add(directory) removeDirs.add(directory)
activity.runOnUiThread { notifyItemRemoved(it)
notifyItemRemoved(it)
}
} }
dirs.removeAll(removeDirs) dirs.removeAll(removeDirs)

View file

@ -171,9 +171,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
private fun askConfirmDelete() { private fun askConfirmDelete() {
ConfirmationDialog(activity) { ConfirmationDialog(activity) {
actMode?.finish() actMode?.finish()
Thread({ deleteFiles()
deleteFiles()
}).start()
} }
} }
@ -189,9 +187,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val medium = media[it] val medium = media[it]
files.add(File(medium.path)) files.add(File(medium.path))
removeMedia.add(medium) removeMedia.add(medium)
activity.runOnUiThread { notifyItemRemoved(it)
notifyItemRemoved(it)
}
} }
media.removeAll(removeMedia) media.removeAll(removeMedia)