Guest User

Untitled

a guest
Nov 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class NoteDialog(
  2. private val viewGroup: ViewGroup,
  3. private val context: Context) {
  4.  
  5. private val createdView = createView()
  6. private val titleField = createdView.form_note_title
  7. private val descriptionField = createdView.form_note_description
  8.  
  9. fun alter(note: Note, altered: (alteredNote: Note) -> Unit) {
  10. titleField.setText(note.title)
  11. descriptionField.setText(note.description)
  12. AlertDialog.Builder(context)
  13. .setTitle("Alter note")
  14. .setView(createdView)
  15. .setPositiveButton("Save") { _, _ ->
  16. val title = titleField.text.toString()
  17. val description = descriptionField.text.toString()
  18. val alteredNote = Note(title = title, description = description)
  19. NoteWebClient().alter(alteredNote, {
  20. altered(it)
  21. }, {
  22. Toast.makeText(context, "Falha ao alterar nota", Toast.LENGTH_LONG).show()
  23. })
  24. }
  25. .show()
  26. }
  27.  
  28. fun add(created: (createdNote: Note) -> Unit) {
  29. AlertDialog.Builder(context)
  30. .setTitle("Add note")
  31. .setView(createdView)
  32. .setPositiveButton("Save") { _, _ ->
  33. val title = titleField.text.toString()
  34. val description = descriptionField.text.toString()
  35. val note = Note(title = title, description = description)
  36. NoteWebClient().insert(note, {
  37. created(it)
  38. }, {
  39. Toast.makeText(context, "Falha ao salvar nota", Toast.LENGTH_LONG).show()
  40. })
  41. }
  42. .show()
  43. }
  44.  
  45. private fun createView(): View {
  46. return LayoutInflater.from(context)
  47. .inflate(R.layout.form_note,
  48. viewGroup,
  49. false)
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment