mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 06:52:03 +02:00
fix some glitches related to notes synced to files
This commit is contained in:
parent
853ee3143c
commit
aa25f23c38
@ -479,16 +479,17 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
RadioGroupDialog(this, items) {
|
RadioGroupDialog(this, items) {
|
||||||
val syncFile = it as Int == EXPORT_FILE_SYNC
|
val syncFile = it as Int == EXPORT_FILE_SYNC
|
||||||
|
val storedValue = mCurrentNote.getNoteStoredValue() ?: ""
|
||||||
tryExportNoteValueToFile(exportPath, textToExport, true) {
|
tryExportNoteValueToFile(exportPath, textToExport, true) {
|
||||||
if (syncFile) {
|
if (syncFile) {
|
||||||
mCurrentNote.path = exportPath
|
mCurrentNote.path = exportPath
|
||||||
|
mCurrentNote.value = ""
|
||||||
if (mCurrentNote.getNoteStoredValue() == textToExport) {
|
} else {
|
||||||
mCurrentNote.value = ""
|
mCurrentNote.path = ""
|
||||||
}
|
mCurrentNote.value = storedValue
|
||||||
|
|
||||||
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -503,22 +504,44 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun exportAllNotes() {
|
private fun exportAllNotes() {
|
||||||
ExportFilesDialog(this, mNotes) { parent, extension ->
|
ExportFilesDialog(this, mNotes) { parent, extension ->
|
||||||
var failCount = 0
|
val items = arrayListOf(
|
||||||
NotesHelper(this).getNotes {
|
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
|
||||||
mNotes = it
|
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
|
||||||
mNotes.forEachIndexed { index, note ->
|
|
||||||
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
|
|
||||||
val file = File(parent, filename)
|
|
||||||
if (!filename.isAValidFilename()) {
|
|
||||||
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
|
|
||||||
} else {
|
|
||||||
tryExportNoteValueToFile(file.absolutePath, note.value, false) {
|
|
||||||
if (!it) {
|
|
||||||
failCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == mNotes.size - 1) {
|
RadioGroupDialog(this, items) {
|
||||||
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
|
val syncFile = it as Int == EXPORT_FILE_SYNC
|
||||||
|
var failCount = 0
|
||||||
|
NotesHelper(this).getNotes {
|
||||||
|
mNotes = it
|
||||||
|
mNotes.forEachIndexed { index, note ->
|
||||||
|
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
|
||||||
|
val file = File(parent, filename)
|
||||||
|
if (!filename.isAValidFilename()) {
|
||||||
|
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
|
||||||
|
} else {
|
||||||
|
val noteStoredValue = note.getNoteStoredValue() ?: ""
|
||||||
|
tryExportNoteValueToFile(file.absolutePath, note.value, false) {
|
||||||
|
if (syncFile) {
|
||||||
|
note.path = file.absolutePath
|
||||||
|
note.value = ""
|
||||||
|
} else {
|
||||||
|
note.path = ""
|
||||||
|
note.value = noteStoredValue
|
||||||
|
}
|
||||||
|
|
||||||
|
NotesHelper(this).insertOrUpdateNote(note)
|
||||||
|
if (mCurrentNote.id == note.id) {
|
||||||
|
mCurrentNote.value = note.value
|
||||||
|
mCurrentNote.path = note.path
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!it) {
|
||||||
|
failCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == mNotes.size - 1) {
|
||||||
|
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ data class Note(
|
|||||||
|
|
||||||
fun getNoteStoredValue(): String? {
|
fun getNoteStoredValue(): String? {
|
||||||
return if (path.isNotEmpty()) {
|
return if (path.isNotEmpty()) {
|
||||||
return try {
|
try {
|
||||||
File(path).readText()
|
File(path).readText()
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
null
|
null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user