From e7baf84fe74b7684ecdeee102e9889770262e12c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Dec 2017 15:28:10 +0100 Subject: [PATCH] wrap folder creating on a try/catch block, report errors --- .../commons/dialogs/CreateNewFolderDialog.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt index 2310c7aa8..bde5529cf 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/CreateNewFolderDialog.kt @@ -41,18 +41,24 @@ class CreateNewFolderDialog(val activity: BaseSimpleActivity, val path: String, } private fun createFolder(file: File, alertDialog: AlertDialog) { - if (activity.needsStupidWritePermissions(file.absolutePath)) { - activity.handleSAFDialog(file) { - try { - val documentFile = activity.getFileDocument(file.absolutePath) - documentFile?.createDirectory(file.name) - sendSuccess(alertDialog, file) - } catch (e: SecurityException) { - activity.showErrorToast(e) + try { + if (activity.needsStupidWritePermissions(file.absolutePath)) { + activity.handleSAFDialog(file) { + try { + val documentFile = activity.getFileDocument(file.absolutePath) + documentFile?.createDirectory(file.name) + sendSuccess(alertDialog, file) + } catch (e: SecurityException) { + activity.showErrorToast(e) + } } + } else if (file.mkdirs()) { + sendSuccess(alertDialog, file) + } else { + activity.toast(R.string.unknown_error_occurred) } - } else if (file.mkdirs()) { - sendSuccess(alertDialog, file) + } catch (e: Exception) { + activity.showErrorToast(e) } }