mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-16 20:00:36 +01: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))
|
||||
val parts = relativePath.split("/")
|
||||
for (part in parts) {
|
||||
document = document.findFile(part)
|
||||
val currDocument = document.findFile(part)
|
||||
if (currDocument != null)
|
||||
document = currDocument
|
||||
}
|
||||
return document
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user