fix #358, allow creating a new note from the Open Note dialog

This commit is contained in:
tibbi
2020-09-19 16:23:56 +02:00
parent 4610bd4127
commit 50281671e4
3 changed files with 54 additions and 12 deletions

View File

@ -914,8 +914,12 @@ class MainActivity : SimpleActivity() {
}
private fun displayOpenNoteDialog() {
OpenNoteDialog(this) {
updateSelectedNote(it)
OpenNoteDialog(this) { noteId, newNote ->
if (newNote == null) {
updateSelectedNote(noteId)
} else {
addNewNote(newNote)
}
}
}

View File

@ -16,7 +16,7 @@ import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_open_note.view.*
import kotlinx.android.synthetic.main.open_note_item.view.*
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long) -> Unit) {
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long, newNote: Note?) -> Unit) {
private var dialog: AlertDialog? = null
init {
@ -24,6 +24,14 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long) ->
NotesHelper(activity).getNotes {
initDialog(it, view)
}
view.dialog_open_note_new_radio.setOnClickListener {
view.dialog_open_note_new_radio.isChecked = false
NewNoteDialog(activity) {
callback(0, it)
dialog?.dismiss()
}
}
}
private fun initDialog(notes: ArrayList<Note>, view: View) {
@ -37,7 +45,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long) ->
id = note.id!!.toInt()
setOnClickListener {
callback(note.id!!)
callback(note.id!!, null)
dialog?.dismiss()
}
}
@ -53,8 +61,8 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long) ->
}
dialog = AlertDialog.Builder(activity)
.create().apply {
activity.setupDialogStuff(view, this, R.string.open_note)
}
.create().apply {
activity.setupDialogStuff(view, this, R.string.open_note)
}
}
}