mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-22 19:40:07 +01:00
set checklist by default at opening a checklist file
This commit is contained in:
parent
4f1bb56d00
commit
7c6bca4fd7
@ -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, "")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user