some corrections to deleting folders

This commit is contained in:
tibbi 2017-03-15 23:50:53 +01:00
parent 6bb03cda1a
commit 8b2793e971
3 changed files with 29 additions and 14 deletions

View file

@ -29,5 +29,5 @@ ext {
propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '2.11.7'
propVersionName = '2.12.0'
}

View file

@ -168,17 +168,23 @@ fun BaseSimpleActivity.deleteFileBg(file: File, allowDeleteFolder: Boolean = fal
rescanDeletedFile(file) {
callback(true)
}
} else if (isPathOnSD(file.absolutePath)) {
handleSAFDialog(file) {
fileDeleted = tryFastDocumentDelete(file)
if (!fileDeleted) {
val document = getFileDocument(file.absolutePath, baseConfig.treeUri)
fileDeleted = (document?.isFile == true || allowDeleteFolder) && document?.delete() == true
}
} else {
if (file.isDirectory || allowDeleteFolder) {
fileDeleted = deleteRecursively(file)
}
if (fileDeleted) {
rescanDeletedFile(file) {
callback(true)
if (!fileDeleted && isPathOnSD(file.absolutePath)) {
handleSAFDialog(file) {
fileDeleted = tryFastDocumentDelete(file)
if (!fileDeleted) {
val document = getFileDocument(file.absolutePath, baseConfig.treeUri)
fileDeleted = (document?.isFile == true || allowDeleteFolder) && document?.delete() == true
}
if (fileDeleted) {
rescanDeletedFile(file) {
callback(true)
}
}
}
}
@ -195,6 +201,17 @@ fun BaseSimpleActivity.rescanDeletedFile(file: File, callback: () -> Unit) {
}
}
private fun deleteRecursively(file: File): Boolean {
if (file.isDirectory) {
val files = file.listFiles() ?: return file.delete()
for (child in files) {
deleteRecursively(child)
}
}
return file.delete()
}
fun Activity.hideKeyboard() {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow((currentFocus ?: View(this)).windowToken, 0)

View file

@ -200,14 +200,12 @@ fun Context.rescanPaths(paths: ArrayList<String>, action: () -> Unit) {
}
fun getPaths(file: File): ArrayList<String> {
val paths = ArrayList<String>()
val paths = arrayListOf<String>(file.absolutePath)
if (file.isDirectory) {
val files = file.listFiles() ?: return paths
for (curFile in files) {
paths.addAll(getPaths(curFile))
}
} else {
paths.add(file.absolutePath)
}
return paths
}