From 433a7c1762aad4b2f3b2d851add5ca2ef1d1f650 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Wed, 31 Jan 2024 06:38:31 +0000 Subject: [PATCH] Fix missing .json file extension when exporting notes The input from the user doesn't have a .json suffix. Previously, we passed that value to ActivityResultContracts.CreateDocument as is (without an extension), and relied on the file picker to automatically append the extension based on the MIME type. But some file pickers don't automatically append the extension, e.g. the native Files app (com.android.documentsui) on Android <= 9, and FossifyOrg/File-Manager. This results in the exported file not having a .json extension. Fix this by manually appending the .json extension before passing the file name to CreateDocument. Manually appending the extension shouldn't cause a problem for file pickers that can automatically add an extension. For example the native Files app doesn't add a second extension, and if the file already exists it generates a unique name correctly, with the "(1)" inserted before the extension, e.g. "Notes (1).json". Fixes #13. --- .../kotlin/org/fossify/notes/activities/SettingsActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt index 057f491c..0c33222f 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt @@ -301,7 +301,7 @@ class SettingsActivity : SimpleActivity() { private fun setupNotesExport() { binding.settingsExportNotesHolder.setOnClickListener { ExportNotesDialog(this) { filename -> - saveDocument.launch(filename) + saveDocument.launch("$filename.json") } } }