@@ -467,7 +467,7 @@ class MainActivity : SimpleActivity() {
467467 } else if (mCurrentNote.type == TYPE_TEXT ) {
468468 showExportFilePickUpdateDialog(it, textToExport)
469469 } else {
470- exportNoteValueToFile (it, textToExport, true )
470+ tryExportNoteValueToFile (it, textToExport, true )
471471 }
472472 }
473473 }
@@ -479,7 +479,7 @@ class MainActivity : SimpleActivity() {
479479
480480 RadioGroupDialog (this , items) {
481481 val syncFile = it as Int == EXPORT_FILE_SYNC
482- exportNoteValueToFile (exportPath, textToExport, true ) {
482+ tryExportNoteValueToFile (exportPath, textToExport, true ) {
483483 if (syncFile) {
484484 mCurrentNote.path = exportPath
485485
@@ -512,7 +512,7 @@ class MainActivity : SimpleActivity() {
512512 if (! filename.isAValidFilename()) {
513513 toast(String .format(getString(R .string.filename_invalid_characters_placeholder, filename)))
514514 } else {
515- exportNoteValueToFile (file.absolutePath, note.value, false ) {
515+ tryExportNoteValueToFile (file.absolutePath, note.value, false ) {
516516 if (! it) {
517517 failCount++
518518 }
@@ -527,7 +527,15 @@ class MainActivity : SimpleActivity() {
527527 }
528528 }
529529
530- fun exportNoteValueToFile (path : String , content : String , showSuccessToasts : Boolean , callback : ((success: Boolean ) -> Unit )? = null) {
530+ fun tryExportNoteValueToFile (path : String , content : String , showSuccessToasts : Boolean , callback : ((success: Boolean ) -> Unit )? = null) {
531+ handlePermission(PERMISSION_WRITE_STORAGE ) {
532+ if (it) {
533+ exportNoteValueToFile(path, content, showSuccessToasts, callback)
534+ }
535+ }
536+ }
537+
538+ private fun exportNoteValueToFile (path : String , content : String , showSuccessToasts : Boolean , callback : ((success: Boolean ) -> Unit )? = null) {
531539 try {
532540 if (getIsPathDirectory(path)) {
533541 toast(R .string.name_taken)
0 commit comments