mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
fix #358, allow creating a new note from the Open Note dialog
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user