Merge pull request #445 from qwertyfinger/fix/google-drive-export

Fix error when exporting notes to Google Drive
This commit is contained in:
Tibor Kaputa 2021-09-13 21:19:07 +02:00 committed by GitHub
commit a33e418391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -750,7 +750,8 @@ class MainActivity : SimpleActivity() {
RadioGroupDialog(this, items) {
val syncFile = it as Int == EXPORT_FILE_SYNC
tryExportNoteValueToFile(exportPath, textToExport, true) {
tryExportNoteValueToFile(exportPath, textToExport, true) { exportedSuccessfully ->
if (exportedSuccessfully) {
if (syncFile) {
mCurrentNote.path = exportPath
mCurrentNote.value = ""
@ -764,6 +765,7 @@ class MainActivity : SimpleActivity() {
}
}
}
}
private fun tryExportAllNotes() {
handlePermission(PERMISSION_WRITE_STORAGE) {
@ -792,7 +794,8 @@ 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) {
tryExportNoteValueToFile(file.absolutePath, note.value, false) { exportedSuccessfully ->
if (exportedSuccessfully) {
if (syncFile) {
note.path = file.absolutePath
note.value = ""
@ -802,13 +805,15 @@ class MainActivity : SimpleActivity() {
}
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++
}
@ -880,7 +885,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)
}