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
app/src/main/kotlin/com/simplemobiletools/notes/pro

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

@ -15,10 +15,16 @@ import com.simplemobiletools.notes.pro.helpers.NoteType
import com.simplemobiletools.notes.pro.models.Note import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_new_note.view.* 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 { init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply { 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.note_title.setText(title)

@ -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.setOnClickListener {
view.dialog_open_note_new_radio.isChecked = false view.dialog_open_note_new_radio.isChecked = false
NewNoteDialog(activity) { NewNoteDialog(activity, setChecklistAsDefault = false) {
callback(0, it) callback(0, it)
dialog?.dismiss() dialog?.dismiss()
} }