correct file/directory creating on sd cards

This commit is contained in:
tibbi
2016-11-05 18:22:26 +01:00
parent 4b56761751
commit 8354107091
2 changed files with 22 additions and 8 deletions

View File

@ -52,11 +52,14 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
}
}
private fun createDirectory(file: File, alertDialog: AlertDialog): Boolean {
return if (file.mkdirs()) {
alertDialog.dismiss()
listener.onSuccess()
return if (Utils.needsStupidWritePermissions(context, path)) {
val documentFile = Utils.getFileDocument(context, file.absolutePath)
documentFile.createDirectory(file.name)
success(alertDialog)
true
} else if (file.mkdirs()) {
success(alertDialog)
true
} else
false
@ -68,9 +71,13 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
private fun createFile(file: File, alertDialog: AlertDialog): Boolean {
try {
if (file.createNewFile()) {
alertDialog.dismiss()
listener.onSuccess()
if (Utils.needsStupidWritePermissions(context, path)) {
val documentFile = Utils.getFileDocument(context, file.absolutePath)
documentFile.createFile("", file.name)
success(alertDialog)
return true
} else if (file.createNewFile()) {
success(alertDialog)
return true
}
} catch (ignored: IOException) {
@ -80,6 +87,11 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
return false
}
private fun success(alertDialog: AlertDialog) {
alertDialog.dismiss()
listener.onSuccess()
}
interface OnCreateNewItemListener {
fun onSuccess()
}