Guest User

Untitled

a guest
May 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. fun saveItem(item: Note, callback: (Note) -> Unit) {
  2. Log.d(TAG, "Saving ite ${item.noteId}")
  3. val mutation = SaveNoteMutation.builder()
  4. .noteId(item.noteId)
  5. .title(if (item.title == "") " " else item.title)
  6. .content(if (item.content == "") " " else item.content)
  7. .build()
  8.  
  9. val graphqlCallback = object : GraphQLCall.Callback<SaveNoteMutation.Data>() {
  10. override fun onResponse(response: Response<SaveNoteMutation.Data>) {
  11. if (response.hasErrors()) {
  12. Log.d(TAG, "saveItem::onResponse - has errors")
  13. } else {
  14. Log.d(TAG, "saveItem::onResponse - data received")
  15. response.data()?.saveNote()?.let {
  16. val note = Note(it.noteId()).apply {
  17. title = it.title() ?: ""
  18. content = it.content() ?: ""
  19. }
  20.  
  21. invalidate()
  22. runOnUiThread { callback(note) }
  23. }
  24. }
  25. }
  26.  
  27. override fun onFailure(e: ApolloException) {
  28. throw e
  29. }
  30. }
  31.  
  32. appSyncClient.mutate(mutation)
  33. .refetchQueries(GetNoteQuery.builder().noteId(item.noteId).build())
  34. .enqueue(graphqlCallback)
  35. }
Add Comment
Please, Sign In to add comment