Allow opening files as Checklists

This commit is contained in:
Pavol Franek 2020-03-29 10:40:17 +02:00
parent 8bdac0e761
commit 6733a9f263
2 changed files with 9 additions and 6 deletions

View File

@ -497,8 +497,8 @@ class MainActivity : SimpleActivity() {
}
}
private fun displayNewNoteDialog(value: String = "") {
NewNoteDialog(this) {
private fun displayNewNoteDialog(value: String = "", title: String? = null) {
NewNoteDialog(this, title) {
it.value = value
addNewNote(it)
}
@ -545,12 +545,13 @@ class MainActivity : SimpleActivity() {
val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems()
if (checklistItems != null) {
val note = Note(null, it.absolutePath.getFilenameFromPath().substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST.value)
addNewNote(note)
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value)
displayNewNoteDialog(note.value, title = title)
} else {
runOnUiThread {
OpenFileDialog(this, it.path) {
addNewNote(it)
displayNewNoteDialog(it.value, title = it.title)
}
}
}

View File

@ -15,12 +15,14 @@ import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_new_note.view.*
class NewNoteDialog(val activity: Activity, callback: (note: Note) -> Unit) {
class NewNoteDialog(val activity: Activity, title: String? = null, callback: (note: Note) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply {
new_note_type.check(if (activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value) type_text_note.id else type_checklist.id)
}
view.note_title.setText(title)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)