Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NoteDialog(
- private val viewGroup: ViewGroup,
- private val context: Context) {
- private val createdView = createView()
- private val titleField = createdView.form_note_title
- private val descriptionField = createdView.form_note_description
- fun alter(note: Note, altered: (alteredNote: Note) -> Unit) {
- titleField.setText(note.title)
- descriptionField.setText(note.description)
- AlertDialog.Builder(context)
- .setTitle("Alter note")
- .setView(createdView)
- .setPositiveButton("Save") { _, _ ->
- val title = titleField.text.toString()
- val description = descriptionField.text.toString()
- val alteredNote = Note(title = title, description = description)
- NoteWebClient().alter(alteredNote, {
- altered(it)
- }, {
- Toast.makeText(context, "Falha ao alterar nota", Toast.LENGTH_LONG).show()
- })
- }
- .show()
- }
- fun add(created: (createdNote: Note) -> Unit) {
- AlertDialog.Builder(context)
- .setTitle("Add note")
- .setView(createdView)
- .setPositiveButton("Save") { _, _ ->
- val title = titleField.text.toString()
- val description = descriptionField.text.toString()
- val note = Note(title = title, description = description)
- NoteWebClient().insert(note, {
- created(it)
- }, {
- Toast.makeText(context, "Falha ao salvar nota", Toast.LENGTH_LONG).show()
- })
- }
- .show()
- }
- private fun createView(): View {
- return LayoutInflater.from(context)
- .inflate(R.layout.form_note,
- viewGroup,
- false)
- }
- }
Add Comment
Please, Sign In to add comment