mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-02-10 08:20:49 +01:00
do not allow syncing checklist files with the note itself
This commit is contained in:
parent
ec5977cf9f
commit
21e2a282b8
@ -349,11 +349,22 @@ class MainActivity : SimpleActivity() {
|
|||||||
private fun openFile() {
|
private fun openFile() {
|
||||||
FilePickerDialog(this, canAddShowHiddenButton = true) {
|
FilePickerDialog(this, canAddShowHiddenButton = true) {
|
||||||
openFile(it, 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) {
|
OpenFileDialog(this, it.path) {
|
||||||
addNewNote(it)
|
addNewNote(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openFile(path: String, checkTitle: Boolean, onChecksPassed: (file: File) -> Unit) {
|
private fun openFile(path: String, checkTitle: Boolean, onChecksPassed: (file: File) -> Unit) {
|
||||||
|
@ -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