Skip to content

Commit 7c6bca4

Browse files
committed
set checklist by default at opening a checklist file
1 parent 4f1bb56 commit 7c6bca4

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ class MainActivity : SimpleActivity() {
482482
}
483483
}
484484

485-
private fun displayNewNoteDialog(value: String = "", title: String? = null, path: String = "") {
486-
NewNoteDialog(this, title) {
485+
private fun displayNewNoteDialog(value: String = "", title: String? = null, path: String = "", setChecklistAsDefault: Boolean = false) {
486+
NewNoteDialog(this, title, setChecklistAsDefault) {
487487
it.value = value
488488
it.path = path
489489
addNewNote(it)
@@ -537,7 +537,7 @@ class MainActivity : SimpleActivity() {
537537
if (checklistItems != null) {
538538
val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.')
539539
val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST.value)
540-
displayNewNoteDialog(note.value, title = title)
540+
displayNewNoteDialog(note.value, title = title, setChecklistAsDefault = true)
541541
} else {
542542
runOnUiThread {
543543
OpenFileDialog(this, it.path) {
@@ -622,10 +622,10 @@ class MainActivity : SimpleActivity() {
622622

623623
if (checklistItems != null) {
624624
val note = Note(null, noteTitle, content, NoteType.TYPE_CHECKLIST.value)
625-
addNewNote(note)
625+
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true)
626626
} else {
627-
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value, "")
628-
addNewNote(note)
627+
val note = Note(null, noteTitle, content, NoteType.TYPE_TEXT.value)
628+
displayNewNoteDialog(note.value, title = noteTitle, "")
629629
}
630630
}
631631

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewNoteDialog.kt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,43 @@ import com.simplemobiletools.notes.pro.helpers.NoteType
1515
import com.simplemobiletools.notes.pro.models.Note
1616
import kotlinx.android.synthetic.main.dialog_new_note.view.*
1717

18-
class NewNoteDialog(val activity: Activity, title: String? = null, callback: (note: Note) -> Unit) {
18+
class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, callback: (note: Note) -> Unit) {
1919
init {
2020
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply {
21-
new_note_type.check(if (activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value) type_text_note.id else type_checklist.id)
21+
val defaultType = when {
22+
setChecklistAsDefault -> type_checklist.id
23+
activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value -> type_text_note.id
24+
else -> type_checklist.id
25+
}
26+
27+
new_note_type.check(defaultType)
2228
}
2329

2430
view.note_title.setText(title)
2531

2632
AlertDialog.Builder(activity)
27-
.setPositiveButton(R.string.ok, null)
28-
.setNegativeButton(R.string.cancel, null)
29-
.create().apply {
30-
activity.setupDialogStuff(view, this, R.string.new_note) {
31-
showKeyboard(view.note_title)
32-
getButton(BUTTON_POSITIVE).setOnClickListener {
33-
val title = view.note_title.value
34-
ensureBackgroundThread {
35-
when {
36-
title.isEmpty() -> activity.toast(R.string.no_title)
37-
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
38-
else -> {
39-
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
40-
activity.config.lastCreatedNoteType = type
41-
val newNote = Note(null, title, "", type)
42-
callback(newNote)
43-
dismiss()
44-
}
33+
.setPositiveButton(R.string.ok, null)
34+
.setNegativeButton(R.string.cancel, null)
35+
.create().apply {
36+
activity.setupDialogStuff(view, this, R.string.new_note) {
37+
showKeyboard(view.note_title)
38+
getButton(BUTTON_POSITIVE).setOnClickListener {
39+
val title = view.note_title.value
40+
ensureBackgroundThread {
41+
when {
42+
title.isEmpty() -> activity.toast(R.string.no_title)
43+
activity.notesDB.getNoteIdWithTitle(title) != null -> activity.toast(R.string.title_taken)
44+
else -> {
45+
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) NoteType.TYPE_CHECKLIST.value else NoteType.TYPE_TEXT.value
46+
activity.config.lastCreatedNoteType = type
47+
val newNote = Note(null, title, "", type)
48+
callback(newNote)
49+
dismiss()
4550
}
4651
}
4752
}
4853
}
4954
}
55+
}
5056
}
5157
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/OpenNoteDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, new
2727

2828
view.dialog_open_note_new_radio.setOnClickListener {
2929
view.dialog_open_note_new_radio.isChecked = false
30-
NewNoteDialog(activity) {
30+
NewNoteDialog(activity, setChecklistAsDefault = false) {
3131
callback(0, it)
3232
dialog?.dismiss()
3333
}

0 commit comments

Comments
 (0)