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) {
|
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
||||||
when {
|
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) -> {
|
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
|
||||||
if (activity.isRestrictedSAFOnlyRoot(path)) {
|
if (activity.isRestrictedSAFOnlyRoot(path)) {
|
||||||
activity.handleAndroidSAFDialog(path) {
|
activity.handleAndroidSAFDialog(path) {
|
||||||
|
@ -66,33 +81,12 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
||||||
callback(false)
|
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 {
|
} else {
|
||||||
if (File(path).mkdirs()) {
|
if (File(path).mkdirs()) {
|
||||||
success(alertDialog)
|
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 -> {
|
else -> {
|
||||||
RootHelpers(activity).createFileFolder(path, false) {
|
RootHelpers(activity).createFileFolder(path, false) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
@ -143,19 +137,10 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
||||||
}
|
}
|
||||||
|
|
||||||
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
|
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()) {
|
if (File(path).createNewFile()) {
|
||||||
success(alertDialog)
|
success(alertDialog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else -> {
|
else -> {
|
||||||
RootHelpers(activity).createFileFolder(path, true) {
|
RootHelpers(activity).createFileFolder(path, true) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
|
Loading…
Reference in New Issue