mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-21 05:38:02 +02:00
correct file/directory creating on sd cards
This commit is contained in:
parent
4b56761751
commit
8354107091
@ -48,7 +48,9 @@ class Utils {
|
|||||||
var document = DocumentFile.fromTreeUri(context, Uri.parse(Config.newInstance(context).treeUri))
|
var document = DocumentFile.fromTreeUri(context, Uri.parse(Config.newInstance(context).treeUri))
|
||||||
val parts = relativePath.split("/")
|
val parts = relativePath.split("/")
|
||||||
for (part in parts) {
|
for (part in parts) {
|
||||||
document = document.findFile(part)
|
val currDocument = document.findFile(part)
|
||||||
|
if (currDocument != null)
|
||||||
|
document = currDocument
|
||||||
}
|
}
|
||||||
return document
|
return document
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,14 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun createDirectory(file: File, alertDialog: AlertDialog): Boolean {
|
private fun createDirectory(file: File, alertDialog: AlertDialog): Boolean {
|
||||||
return if (file.mkdirs()) {
|
return if (Utils.needsStupidWritePermissions(context, path)) {
|
||||||
alertDialog.dismiss()
|
val documentFile = Utils.getFileDocument(context, file.absolutePath)
|
||||||
listener.onSuccess()
|
documentFile.createDirectory(file.name)
|
||||||
|
success(alertDialog)
|
||||||
|
true
|
||||||
|
} else if (file.mkdirs()) {
|
||||||
|
success(alertDialog)
|
||||||
true
|
true
|
||||||
} else
|
} else
|
||||||
false
|
false
|
||||||
@ -68,9 +71,13 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
|
|||||||
|
|
||||||
private fun createFile(file: File, alertDialog: AlertDialog): Boolean {
|
private fun createFile(file: File, alertDialog: AlertDialog): Boolean {
|
||||||
try {
|
try {
|
||||||
if (file.createNewFile()) {
|
if (Utils.needsStupidWritePermissions(context, path)) {
|
||||||
alertDialog.dismiss()
|
val documentFile = Utils.getFileDocument(context, file.absolutePath)
|
||||||
listener.onSuccess()
|
documentFile.createFile("", file.name)
|
||||||
|
success(alertDialog)
|
||||||
|
return true
|
||||||
|
} else if (file.createNewFile()) {
|
||||||
|
success(alertDialog)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} catch (ignored: IOException) {
|
} catch (ignored: IOException) {
|
||||||
@ -80,6 +87,11 @@ class CreateNewItemDialog(val context: Context, val path: String, val listener:
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun success(alertDialog: AlertDialog) {
|
||||||
|
alertDialog.dismiss()
|
||||||
|
listener.onSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
interface OnCreateNewItemListener {
|
interface OnCreateNewItemListener {
|
||||||
fun onSuccess()
|
fun onSuccess()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user