Ensure that `needsStupidWritePermissions` is tried before fallback methods
This commit is contained in:
parent
5cd666d949
commit
c8b980bf3e
|
@ -51,6 +51,21 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||
|
||||
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
||||
when {
|
||||
activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
val documentFile = activity.getDocumentFile(path.getParentPath())
|
||||
if (documentFile == null) {
|
||||
val error = String.format(activity.getString(R.string.could_not_create_folder), path)
|
||||
activity.showErrorToast(error)
|
||||
callback(false)
|
||||
return@handleSAFDialog
|
||||
}
|
||||
documentFile.createDirectory(path.getFilenameFromPath())
|
||||
success(alertDialog)
|
||||
}
|
||||
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
|
||||
if (activity.isRestrictedSAFOnlyRoot(path)) {
|
||||
activity.handleAndroidSAFDialog(path) {
|
||||
|
@ -66,33 +81,12 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||
callback(false)
|
||||
}
|
||||
}
|
||||
} else if (activity.isPathOnOTG(path)) {
|
||||
val parent = activity.getDocumentFile(path.getParentPath())
|
||||
val created = parent?.createDirectory(path.getFilenameFromPath())
|
||||
if (created != null) {
|
||||
success(alertDialog)
|
||||
}
|
||||
} else {
|
||||
if (File(path).mkdirs()) {
|
||||
success(alertDialog)
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) {
|
||||
if (!it) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
val documentFile = activity.getDocumentFile(path.getParentPath())
|
||||
if (documentFile == null) {
|
||||
val error = String.format(activity.getString(R.string.could_not_create_folder), path)
|
||||
activity.showErrorToast(error)
|
||||
callback(false)
|
||||
return@handleSAFDialog
|
||||
}
|
||||
documentFile.createDirectory(path.getFilenameFromPath())
|
||||
success(alertDialog)
|
||||
}
|
||||
else -> {
|
||||
RootHelpers(activity).createFileFolder(path, false) {
|
||||
if (it) {
|
||||
|
@ -143,19 +137,10 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||
}
|
||||
|
||||
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
|
||||
|
||||
if (activity.isPathOnOTG(path)) {
|
||||
val parent = activity.getDocumentFile(path.getParentPath())
|
||||
val created = parent?.createFile(path.getMimeType(), path.getFilenameFromPath())
|
||||
if (created != null) {
|
||||
success(alertDialog)
|
||||
}
|
||||
} else {
|
||||
if (File(path).createNewFile()) {
|
||||
success(alertDialog)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
RootHelpers(activity).createFileFolder(path, true) {
|
||||
if (it) {
|
||||
|
|
Loading…
Reference in New Issue