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

@ -15,37 +15,43 @@ 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)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.new_note) {
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_title.value
ensureBackgroundThread {
when {
title.isEmpty() -> activity.toast(R.string.no_title)
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
else -> {
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
activity.config.lastCreatedNoteType = type
val newNote = Note(null, title, "", type)
callback(newNote)
dismiss()
}
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.new_note) {
showKeyboard(view.note_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_title.value
ensureBackgroundThread {
when {
title.isEmpty() -> activity.toast(R.string.no_title)
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
else -> {
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
activity.config.lastCreatedNoteType = type
val newNote = Note(null, title, "", type)
callback(newNote)
dismiss()
}
}
}
}
}
}
}
}

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()
}