mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-08 23:48:42 +01:00
do not allow syncing checklist files with the note itself
This commit is contained in:
parent
ec5977cf9f
commit
21e2a282b8
@ -349,9 +349,20 @@ class MainActivity : SimpleActivity() {
|
||||
private fun openFile() {
|
||||
FilePickerDialog(this, canAddShowHiddenButton = true) {
|
||||
openFile(it, true) {
|
||||
OpenFileDialog(this, it.path) {
|
||||
addNewNote(it)
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user