@@ -51,6 +51,21 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
5151
5252 private fun createDirectory (path : String , alertDialog : AlertDialog , callback : (Boolean ) -> Unit ) {
5353 when {
54+ activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) {
55+ if (! it) {
56+ return @handleSAFDialog
57+ }
58+
59+ val documentFile = activity.getDocumentFile(path.getParentPath())
60+ if (documentFile == null ) {
61+ val error = String .format(activity.getString(R .string.could_not_create_folder), path)
62+ activity.showErrorToast(error)
63+ callback(false )
64+ return @handleSAFDialog
65+ }
66+ documentFile.createDirectory(path.getFilenameFromPath())
67+ success(alertDialog)
68+ }
5469 isRPlus() || path.startsWith(activity.internalStoragePath, true ) -> {
5570 if (activity.isRestrictedSAFOnlyRoot(path)) {
5671 activity.handleAndroidSAFDialog(path) {
@@ -66,33 +81,12 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
6681 callback(false )
6782 }
6883 }
69- } else if (activity.isPathOnOTG(path)) {
70- val parent = activity.getDocumentFile(path.getParentPath())
71- val created = parent?.createDirectory(path.getFilenameFromPath())
72- if (created != null ) {
73- success(alertDialog)
74- }
7584 } else {
7685 if (File (path).mkdirs()) {
7786 success(alertDialog)
7887 }
7988 }
8089 }
81- activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) {
82- if (! it) {
83- return @handleSAFDialog
84- }
85-
86- val documentFile = activity.getDocumentFile(path.getParentPath())
87- if (documentFile == null ) {
88- val error = String .format(activity.getString(R .string.could_not_create_folder), path)
89- activity.showErrorToast(error)
90- callback(false )
91- return @handleSAFDialog
92- }
93- documentFile.createDirectory(path.getFilenameFromPath())
94- success(alertDialog)
95- }
9690 else -> {
9791 RootHelpers (activity).createFileFolder(path, false ) {
9892 if (it) {
@@ -143,17 +137,8 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
143137 }
144138
145139 isRPlus() || path.startsWith(activity.internalStoragePath, true ) -> {
146-
147- if (activity.isPathOnOTG(path)) {
148- val parent = activity.getDocumentFile(path.getParentPath())
149- val created = parent?.createFile(path.getMimeType(), path.getFilenameFromPath())
150- if (created != null ) {
151- success(alertDialog)
152- }
153- } else {
154- if (File (path).createNewFile()) {
155- success(alertDialog)
156- }
140+ if (File (path).createNewFile()) {
141+ success(alertDialog)
157142 }
158143 }
159144 else -> {
0 commit comments