From de60443c21569e49a9ddd9481e567d01d492b36b Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Sun, 22 Aug 2021 11:03:40 +0300 Subject: [PATCH 1/2] Fix editing previously exported notes not working properly OutputStream for existing files with "content://" path needs to be opened in truncate mode, its description: "If the file already exists and is a regular file and is opened for writing, it will be truncated to length 0." Streams for files with "/storage" don't seem to be affected by this issue and don't need the truncate mode. See more at https://developer.android.com/reference/android/os/ParcelFileDescriptor#parseMode(java.lang.String). --- .../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 c7c35d91..8d7af816 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 @@ -875,7 +875,7 @@ class MainActivity : SimpleActivity() { private fun exportNoteValueToUri(uri: Uri, content: String, callback: ((success: Boolean) -> Unit)? = null) { try { - val outputStream = contentResolver.openOutputStream(uri) + val outputStream = contentResolver.openOutputStream(uri, "wt") outputStream!!.bufferedWriter().use { out -> out.write(content) } From d0a947ddffbf18dfc3d1268d0a1e409ce07492fa Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Sun, 22 Aug 2021 11:20:12 +0300 Subject: [PATCH 2/2] Simplify and reformat code --- .../notes/pro/activities/MainActivity.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 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 8d7af816..2733c451 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 @@ -650,7 +650,8 @@ class MainActivity : SimpleActivity() { } else { val items = arrayListOf( RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)), - RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content))) + RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)) + ) RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC @@ -740,7 +741,8 @@ class MainActivity : SimpleActivity() { private fun showExportFilePickUpdateDialog(exportPath: String, textToExport: String) { val items = arrayListOf( RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)), - RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content))) + RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)) + ) RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC @@ -771,7 +773,8 @@ class MainActivity : SimpleActivity() { ExportFilesDialog(this, mNotes) { parent, extension -> val items = arrayListOf( RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)), - RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content))) + RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)) + ) RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC @@ -858,9 +861,7 @@ class MainActivity : SimpleActivity() { } } else { val file = File(path) - file.printWriter().use { out -> - out.write(content) - } + file.writeText(content) if (showSuccessToasts) { noteExportedSuccessfully(path.getFilenameFromPath())