From cbba53b7984215f1bdff8b747705b49dbe939a2e Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Mon, 13 Sep 2021 05:07:56 +0300 Subject: [PATCH 1/2] Fix error when exporting notes to Google Drive Use "rwt" mode instead of "wt" as the "wt" seems to not work with Google Drive. See this: https://github.com/itinance/react-native-fs/pull/837#issuecomment-776677509 --- .../com/simplemobiletools/notes/pro/activities/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index 752ece6f..f8ea9629 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -880,7 +880,7 @@ class MainActivity : SimpleActivity() { private fun exportNoteValueToUri(uri: Uri, content: String, callback: ((success: Boolean) -> Unit)? = null) { try { - val outputStream = contentResolver.openOutputStream(uri, "wt") + val outputStream = contentResolver.openOutputStream(uri, "rwt") outputStream!!.bufferedWriter().use { out -> out.write(content) } From ab0d7a5666920fee31d08c24c468d0d26acc4aff Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Mon, 13 Sep 2021 05:18:45 +0300 Subject: [PATCH 2/2] Don't update note info if export failed --- .../notes/pro/activities/MainActivity.kt | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index f8ea9629..f6618754 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -750,17 +750,19 @@ class MainActivity : SimpleActivity() { RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC - tryExportNoteValueToFile(exportPath, textToExport, true) { - if (syncFile) { - mCurrentNote.path = exportPath - mCurrentNote.value = "" - } else { - mCurrentNote.path = "" - mCurrentNote.value = textToExport - } + tryExportNoteValueToFile(exportPath, textToExport, true) { exportedSuccessfully -> + if (exportedSuccessfully) { + if (syncFile) { + mCurrentNote.path = exportPath + mCurrentNote.value = "" + } else { + mCurrentNote.path = "" + mCurrentNote.value = textToExport + } - getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value) - NotesHelper(this).insertOrUpdateNote(mCurrentNote) + getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value) + NotesHelper(this).insertOrUpdateNote(mCurrentNote) + } } } } @@ -792,23 +794,26 @@ class MainActivity : SimpleActivity() { toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename))) } else { val noteStoredValue = note.getNoteStoredValue(this) ?: "" - tryExportNoteValueToFile(file.absolutePath, note.value, false) { - if (syncFile) { - note.path = file.absolutePath - note.value = "" - } else { - note.path = "" - note.value = noteStoredValue + tryExportNoteValueToFile(file.absolutePath, note.value, false) { exportedSuccessfully -> + if (exportedSuccessfully) { + if (syncFile) { + note.path = file.absolutePath + note.value = "" + } else { + note.path = "" + note.value = noteStoredValue + } + + NotesHelper(this).insertOrUpdateNote(note) } - NotesHelper(this).insertOrUpdateNote(note) if (mCurrentNote.id == note.id) { mCurrentNote.value = note.value mCurrentNote.path = note.path getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value) } - if (!it) { + if (!exportedSuccessfully) { failCount++ }