tweak the way files are deleted
This commit is contained in:
parent
e06bb0e412
commit
cbcd3cfa6a
3 changed files with 50 additions and 49 deletions
|
@ -189,23 +189,25 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
|
||||
private fun deleteItem(file: File) {
|
||||
if (needsStupidWritePermissions(file.absolutePath)) {
|
||||
if (!isShowingPermDialog(file)) {
|
||||
val needsPermissions = needsStupidWritePermissions(file.path)
|
||||
if (needsPermissions && isShowingPermDialog(file)) {
|
||||
return
|
||||
}
|
||||
|
||||
Thread({
|
||||
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")
|
||||
if (uri.endsWith(file.absolutePath.getFilenameFromPath())) {
|
||||
Thread({
|
||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||
if (uri.endsWith(filename)) {
|
||||
document.delete()
|
||||
}).start()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
file.delete()
|
||||
}).start()
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun handleZooming() {
|
||||
|
|
|
@ -214,29 +214,29 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
override fun deleteFiles(files: ArrayList<File>) {
|
||||
val needsPermissions = needsStupidWritePermissions(files[0].path)
|
||||
if (needsPermissions && isShowingPermDialog(files[0])) {
|
||||
return
|
||||
}
|
||||
|
||||
Thread({
|
||||
files.filter { it.exists() && it.isImageVideoGif() }
|
||||
.forEach {
|
||||
if (needsStupidWritePermissions(it.absolutePath)) {
|
||||
if (isShowingPermDialog(it))
|
||||
return
|
||||
|
||||
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")
|
||||
if (uri.endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
|
||||
Thread({
|
||||
val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||
if (uri.endsWith(filename) && !document.isDirectory) {
|
||||
document.delete()
|
||||
}).start()
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
it.delete()
|
||||
}).start()
|
||||
}
|
||||
|
||||
deleteFromMediaStore(it)
|
||||
}
|
||||
}).start()
|
||||
|
||||
if (mMedia.isEmpty()) {
|
||||
finish()
|
||||
|
|
|
@ -232,25 +232,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun deleteFile() {
|
||||
val file = File(mMedia[mPos].path)
|
||||
if (isShowingPermDialog(file))
|
||||
val needsPermissions = needsStupidWritePermissions(file.path)
|
||||
if (needsPermissions && isShowingPermDialog(file)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (needsStupidWritePermissions(mPath)) {
|
||||
if (!isShowingPermDialog(file)) {
|
||||
Thread({
|
||||
if (needsPermissions) {
|
||||
val document = getFileDocument(mPath, 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")
|
||||
if (uri.endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
|
||||
Thread({
|
||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||
if (uri.endsWith(filename) && !document.isDirectory) {
|
||||
document.delete()
|
||||
}).start()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
file.delete()
|
||||
}).start()
|
||||
}
|
||||
|
||||
if (deleteFromMediaStore(file)) {
|
||||
|
@ -260,6 +258,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun isDirEmpty(): Boolean {
|
||||
|
|
Loading…
Reference in a new issue