Skip to content

Commit a33e418

Browse files
authored
Merge pull request #445 from qwertyfinger/fix/google-drive-export
Fix error when exporting notes to Google Drive
2 parents 9a53d8a + ab0d7a5 commit a33e418

File tree

1 file changed

+25
-20
lines changed
  • app/src/main/kotlin/com/simplemobiletools/notes/pro/activities

1 file changed

+25
-20
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -750,17 +750,19 @@ class MainActivity : SimpleActivity() {
750750

751751
RadioGroupDialog(this, items) {
752752
val syncFile = it as Int == EXPORT_FILE_SYNC
753-
tryExportNoteValueToFile(exportPath, textToExport, true) {
754-
if (syncFile) {
755-
mCurrentNote.path = exportPath
756-
mCurrentNote.value = ""
757-
} else {
758-
mCurrentNote.path = ""
759-
mCurrentNote.value = textToExport
760-
}
753+
tryExportNoteValueToFile(exportPath, textToExport, true) { exportedSuccessfully ->
754+
if (exportedSuccessfully) {
755+
if (syncFile) {
756+
mCurrentNote.path = exportPath
757+
mCurrentNote.value = ""
758+
} else {
759+
mCurrentNote.path = ""
760+
mCurrentNote.value = textToExport
761+
}
761762

762-
getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value)
763-
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
763+
getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value)
764+
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
765+
}
764766
}
765767
}
766768
}
@@ -792,23 +794,26 @@ class MainActivity : SimpleActivity() {
792794
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
793795
} else {
794796
val noteStoredValue = note.getNoteStoredValue(this) ?: ""
795-
tryExportNoteValueToFile(file.absolutePath, note.value, false) {
796-
if (syncFile) {
797-
note.path = file.absolutePath
798-
note.value = ""
799-
} else {
800-
note.path = ""
801-
note.value = noteStoredValue
797+
tryExportNoteValueToFile(file.absolutePath, note.value, false) { exportedSuccessfully ->
798+
if (exportedSuccessfully) {
799+
if (syncFile) {
800+
note.path = file.absolutePath
801+
note.value = ""
802+
} else {
803+
note.path = ""
804+
note.value = noteStoredValue
805+
}
806+
807+
NotesHelper(this).insertOrUpdateNote(note)
802808
}
803809

804-
NotesHelper(this).insertOrUpdateNote(note)
805810
if (mCurrentNote.id == note.id) {
806811
mCurrentNote.value = note.value
807812
mCurrentNote.path = note.path
808813
getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value)
809814
}
810815

811-
if (!it) {
816+
if (!exportedSuccessfully) {
812817
failCount++
813818
}
814819

@@ -880,7 +885,7 @@ class MainActivity : SimpleActivity() {
880885

881886
private fun exportNoteValueToUri(uri: Uri, content: String, callback: ((success: Boolean) -> Unit)? = null) {
882887
try {
883-
val outputStream = contentResolver.openOutputStream(uri, "wt")
888+
val outputStream = contentResolver.openOutputStream(uri, "rwt")
884889
outputStream!!.bufferedWriter().use { out ->
885890
out.write(content)
886891
}

0 commit comments

Comments
 (0)