set checklist by default at opening a checklist file

This commit is contained in:
tibbi 2021-03-21 13:11:01 +01:00
parent 4f1bb56d00
commit 7c6bca4fd7
3 changed files with 33 additions and 27 deletions

View File

@ -482,8 +482,8 @@ class MainActivity : SimpleActivity() {
}
}
private fun displayNewNoteDialog(value: String = "", title: String? = null, path: String = "") {
NewNoteDialog(this, title) {
private fun displayNewNoteDialog(value: String = "", title: String? = null, path: String = "", setChecklistAsDefault: Boolean = false) {
NewNoteDialog(this, title, setChecklistAsDefault) {
it.value = value
it.path = path
addNewNote(it)
@ -537,7 +537,7 @@ class MainActivity : SimpleActivity() {
if (checklistItems != null) {
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value)
displayNewNoteDialog(note.value, title = title)
displayNewNoteDialog(note.value, title = title, setChecklistAsDefault = true)
} else {
runOnUiThread {
OpenFileDialog(this, it.path) {
@ -622,10 +622,10 @@ class MainActivity : SimpleActivity() {
if (checklistItems != null) {
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value)
addNewNote(note)
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true)
} else {
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "")
addNewNote(note)
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
displayNewNoteDialog(note.value, title = noteTitle, "")
}
}

View File

@ -15,10 +15,16 @@ 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, title: String? = null, callback: (note: Note) -> Unit) {
class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, 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)
val defaultType = when {
setChecklistAsDefault -> type_checklist.id
activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value -> type_text_note.id
else -> type_checklist.id
}
new_note_type.check(defaultType)
}
view.note_title.setText(title)

View File

@ -27,7 +27,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, new
view.dialog_open_note_new_radio.setOnClickListener {
view.dialog_open_note_new_radio.isChecked = false
NewNoteDialog(activity) {
NewNoteDialog(activity, setChecklistAsDefault = false) {
callback(0, it)
dialog?.dismiss()
}