From ec5977cf9f73b059c128b50bf42c78dc1aca8fe2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Dec 2018 19:03:06 +0100 Subject: [PATCH] add handling for exporting and sharing checklist notes --- .../notes/pro/activities/MainActivity.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 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 6226eb57..2e972d2f 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 @@ -434,30 +434,29 @@ class MainActivity : SimpleActivity() { private fun exportAsFile() { ExportFileDialog(this, mCurrentNote) { - if (getCurrentNoteText()?.isNotEmpty() == true) { - showExportFilePickUpdateDialog(it) + val textToExport = if (mCurrentNote.type == TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value + if (textToExport == null || textToExport.isEmpty()) { + toast(R.string.unknown_error_occurred) + } else if (mCurrentNote.type == TYPE_TEXT) { + showExportFilePickUpdateDialog(it, textToExport) + } else { + exportNoteValueToFile(it, textToExport, true) } } } - private fun showExportFilePickUpdateDialog(exportPath: String) { + 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))) RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC - val currentNoteText = getCurrentNoteText() - if (currentNoteText == null) { - toast(R.string.unknown_error_occurred) - return@RadioGroupDialog - } - - exportNoteValueToFile(exportPath, currentNoteText, true) { + exportNoteValueToFile(exportPath, textToExport, true) { if (syncFile) { mCurrentNote.path = exportPath - if (mCurrentNote.getNoteStoredValue() == currentNoteText) { + if (mCurrentNote.getNoteStoredValue() == textToExport) { mCurrentNote.value = "" } @@ -642,7 +641,7 @@ class MainActivity : SimpleActivity() { } private fun shareText() { - val text = getCurrentNoteText() + val text = if (mCurrentNote.type == TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value if (text == null || text.isEmpty()) { toast(R.string.cannot_share_empty_text) return