tweak the way files are deleted

This commit is contained in:
tibbi 2017-02-10 23:27:14 +01:00
parent e06bb0e412
commit cbcd3cfa6a
3 changed files with 50 additions and 49 deletions

View file

@ -189,23 +189,25 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
private fun deleteItem(file: File) { private fun deleteItem(file: File) {
if (needsStupidWritePermissions(file.absolutePath)) { val needsPermissions = needsStupidWritePermissions(file.path)
if (!isShowingPermDialog(file)) { if (needsPermissions && isShowingPermDialog(file)) {
return
}
Thread({
if (needsPermissions) {
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
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(file.absolutePath.getFilenameFromPath())) { val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
Thread({ if (uri.endsWith(filename)) {
document.delete() document.delete()
}).start()
} }
} } else {
} else {
Thread({
file.delete() file.delete()
}).start() }
} }).start()
} }
private fun handleZooming() { private fun handleZooming() {

View file

@ -214,29 +214,29 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
override fun deleteFiles(files: ArrayList<File>) { override fun deleteFiles(files: ArrayList<File>) {
files.filter { it.exists() && it.isImageVideoGif() } val needsPermissions = needsStupidWritePermissions(files[0].path)
.forEach { if (needsPermissions && isShowingPermDialog(files[0])) {
if (needsStupidWritePermissions(it.absolutePath)) { return
if (isShowingPermDialog(it)) }
return
val document = getFileDocument(it.absolutePath, config.treeUri) Thread({
files.filter { it.exists() && it.isImageVideoGif() }
.forEach {
if (needsPermissions) {
val document = getFileDocument(it.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
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) { val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8")
Thread({ if (uri.endsWith(filename) && !document.isDirectory) {
document.delete() document.delete()
}).start() }
} } else {
} else {
Thread({
it.delete() it.delete()
}).start() }
deleteFromMediaStore(it)
} }
}).start()
deleteFromMediaStore(it)
}
if (mMedia.isEmpty()) { if (mMedia.isEmpty()) {
finish() finish()

View file

@ -232,34 +232,33 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun deleteFile() { private fun deleteFile() {
val file = File(mMedia[mPos].path) val file = File(mMedia[mPos].path)
if (isShowingPermDialog(file)) val needsPermissions = needsStupidWritePermissions(file.path)
if (needsPermissions && isShowingPermDialog(file)) {
return return
}
if (needsStupidWritePermissions(mPath)) { Thread({
if (!isShowingPermDialog(file)) { if (needsPermissions) {
val document = getFileDocument(mPath, config.treeUri) val document = getFileDocument(mPath, 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
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8") val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) { val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
Thread({ if (uri.endsWith(filename) && !document.isDirectory) {
document.delete() document.delete()
}).start() }
} else {
file.delete()
}
if (deleteFromMediaStore(file)) {
reloadViewPager()
} else {
scanFile(file) {
reloadViewPager()
} }
} }
} else { }).start()
Thread({
file.delete()
}).start()
}
if (deleteFromMediaStore(file)) {
reloadViewPager()
} else {
scanFile(file) {
reloadViewPager()
}
}
} }
private fun isDirEmpty(): Boolean { private fun isDirEmpty(): Boolean {