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({
|
||||
document.delete()
|
||||
}).start()
|
||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||
if (uri.endsWith(filename)) {
|
||||
document.delete()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
} else {
|
||||
file.delete()
|
||||
}).start()
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun handleZooming() {
|
||||
|
|
|
@ -214,29 +214,29 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
override fun deleteFiles(files: ArrayList<File>) {
|
||||
files.filter { it.exists() && it.isImageVideoGif() }
|
||||
.forEach {
|
||||
if (needsStupidWritePermissions(it.absolutePath)) {
|
||||
if (isShowingPermDialog(it))
|
||||
return
|
||||
val needsPermissions = needsStupidWritePermissions(files[0].path)
|
||||
if (needsPermissions && isShowingPermDialog(files[0])) {
|
||||
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
|
||||
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
||||
if (uri.endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
|
||||
Thread({
|
||||
// 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) {
|
||||
document.delete()
|
||||
}).start()
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
}
|
||||
} else {
|
||||
it.delete()
|
||||
}).start()
|
||||
}
|
||||
deleteFromMediaStore(it)
|
||||
}
|
||||
|
||||
deleteFromMediaStore(it)
|
||||
}
|
||||
}).start()
|
||||
|
||||
if (mMedia.isEmpty()) {
|
||||
finish()
|
||||
|
|
|
@ -232,34 +232,33 @@ 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({
|
||||
document.delete()
|
||||
}).start()
|
||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||
if (uri.endsWith(filename) && !document.isDirectory) {
|
||||
document.delete()
|
||||
}
|
||||
} else {
|
||||
file.delete()
|
||||
}
|
||||
|
||||
if (deleteFromMediaStore(file)) {
|
||||
reloadViewPager()
|
||||
} else {
|
||||
scanFile(file) {
|
||||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread({
|
||||
file.delete()
|
||||
}).start()
|
||||
}
|
||||
|
||||
if (deleteFromMediaStore(file)) {
|
||||
reloadViewPager()
|
||||
} else {
|
||||
scanFile(file) {
|
||||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun isDirEmpty(): Boolean {
|
||||
|
|
Loading…
Reference in a new issue