mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
fix some glitches related to notes synced to files
This commit is contained in:
parent
853ee3143c
commit
aa25f23c38
@ -479,19 +479,20 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
RadioGroupDialog(this, items) {
|
||||
val syncFile = it as Int == EXPORT_FILE_SYNC
|
||||
val storedValue = mCurrentNote.getNoteStoredValue() ?: ""
|
||||
tryExportNoteValueToFile(exportPath, textToExport, true) {
|
||||
if (syncFile) {
|
||||
mCurrentNote.path = exportPath
|
||||
|
||||
if (mCurrentNote.getNoteStoredValue() == textToExport) {
|
||||
mCurrentNote.value = ""
|
||||
} else {
|
||||
mCurrentNote.path = ""
|
||||
mCurrentNote.value = storedValue
|
||||
}
|
||||
|
||||
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryExportAllNotes() {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
@ -503,6 +504,12 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
private fun exportAllNotes() {
|
||||
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)))
|
||||
|
||||
RadioGroupDialog(this, items) {
|
||||
val syncFile = it as Int == EXPORT_FILE_SYNC
|
||||
var failCount = 0
|
||||
NotesHelper(this).getNotes {
|
||||
mNotes = it
|
||||
@ -512,7 +519,22 @@ class MainActivity : SimpleActivity() {
|
||||
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++
|
||||
}
|
||||
@ -526,6 +548,7 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun tryExportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
|
@ -17,7 +17,7 @@ data class Note(
|
||||
|
||||
fun getNoteStoredValue(): String? {
|
||||
return if (path.isNotEmpty()) {
|
||||
return try {
|
||||
try {
|
||||
File(path).readText()
|
||||
} catch (e: FileNotFoundException) {
|
||||
null
|
||||
|
Loading…
x
Reference in New Issue
Block a user