wrap folder creating on a try/catch block, report errors

This commit is contained in:
tibbi 2017-12-24 15:28:10 +01:00
parent b1d184df97
commit e7baf84fe7

View file

@ -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)
}
}