Skip to content

Commit f153b78

Browse files
committed
fix #247, add an extra check about write permissions when saving note content
1 parent 30fcf9d commit f153b78

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class TextFragment : NoteFragment() {
194194
val currentText = getCurrentNoteViewText()
195195
if (currentText != null) {
196196
val displaySuccess = activity?.config?.displaySuccess ?: false
197-
(activity as? MainActivity)?.exportNoteValueToFile(note.path, currentText, displaySuccess)
197+
(activity as? MainActivity)?.tryExportNoteValueToFile(note.path, currentText, displaySuccess)
198198
}
199199
}
200200
}

0 commit comments

Comments
 (0)