do not allow syncing checklist files with the note itself

This commit is contained in:
tibbi 2018-12-09 20:08:44 +01:00
parent ec5977cf9f
commit 21e2a282b8
2 changed files with 30 additions and 3 deletions

View File

@ -349,11 +349,22 @@ class MainActivity : SimpleActivity() {
private fun openFile() {
FilePickerDialog(this, canAddShowHiddenButton = true) {
openFile(it, true) {
Thread {
val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems()
if (checklistItems != null) {
val note = Note(null, it.absolutePath.getFilenameFromPath(), fileText, TYPE_CHECKLIST)
addNewNote(note)
} else {
runOnUiThread {
OpenFileDialog(this, it.path) {
addNewNote(it)
}
}
}
}.start()
}
}
}
private fun openFile(path: String, checkTitle: Boolean, onChecksPassed: (file: File) -> Unit) {

View File

@ -0,0 +1,16 @@
package com.simplemobiletools.notes.pro.extensions
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.notes.pro.models.ChecklistItem
fun String.parseChecklistItems(): ArrayList<ChecklistItem>? {
if (startsWith("[{") && endsWith("}]")) {
try {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
return Gson().fromJson<ArrayList<ChecklistItem>>(this, checklistItemType) ?: ArrayList(1)
} catch (e: Exception) {
}
}
return null
}