Skip to content

Commit 894d9da

Browse files
committed
fix #87, add an option at file exporting to keep the note synced with file
1 parent 0d6de33 commit 894d9da

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import java.io.File
3737
import java.nio.charset.Charset
3838

3939
class MainActivity : SimpleActivity() {
40+
private val EXPORT_FILE_SYNC = 1
41+
private val EXPORT_FILE_NO_SYNC = 2
42+
4043
private lateinit var mCurrentNote: Note
4144
private var mNotes = ArrayList<Note>()
4245
private var mAdapter: NotesPagerAdapter? = null
@@ -411,7 +414,34 @@ class MainActivity : SimpleActivity() {
411414
private fun exportAsFile() {
412415
ExportFileDialog(this, mCurrentNote) {
413416
if (getCurrentNoteText()?.isNotEmpty() == true) {
414-
exportNoteValueToFile(it, getCurrentNoteText()!!, true)
417+
showExportFilePickUpdateDialog(it)
418+
}
419+
}
420+
}
421+
422+
private fun showExportFilePickUpdateDialog(exportPath: String) {
423+
val items = arrayListOf(
424+
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
425+
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
426+
427+
RadioGroupDialog(this, items) {
428+
val syncFile = it as Int == EXPORT_FILE_SYNC
429+
val currentNoteText = getCurrentNoteText()
430+
if (currentNoteText == null) {
431+
toast(R.string.unknown_error_occurred)
432+
return@RadioGroupDialog
433+
}
434+
435+
exportNoteValueToFile(exportPath, currentNoteText, true) {
436+
if (syncFile) {
437+
mCurrentNote.path = exportPath
438+
dbHelper.updateNotePath(mCurrentNote)
439+
440+
if (mCurrentNote.getNoteStoredValue() == currentNoteText) {
441+
mCurrentNote.value = ""
442+
dbHelper.updateNoteValue(mCurrentNote)
443+
}
444+
}
415445
}
416446
}
417447
}

0 commit comments

Comments
 (0)