Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun saveItem(item: Note, callback: (Note) -> Unit) {
- Log.d(TAG, "Saving ite ${item.noteId}")
- val mutation = SaveNoteMutation.builder()
- .noteId(item.noteId)
- .title(if (item.title == "") " " else item.title)
- .content(if (item.content == "") " " else item.content)
- .build()
- val graphqlCallback = object : GraphQLCall.Callback<SaveNoteMutation.Data>() {
- override fun onResponse(response: Response<SaveNoteMutation.Data>) {
- if (response.hasErrors()) {
- Log.d(TAG, "saveItem::onResponse - has errors")
- } else {
- Log.d(TAG, "saveItem::onResponse - data received")
- response.data()?.saveNote()?.let {
- val note = Note(it.noteId()).apply {
- title = it.title() ?: ""
- content = it.content() ?: ""
- }
- invalidate()
- runOnUiThread { callback(note) }
- }
- }
- }
- override fun onFailure(e: ApolloException) {
- throw e
- }
- }
- appSyncClient.mutate(mutation)
- .refetchQueries(GetNoteQuery.builder().noteId(item.noteId).build())
- .enqueue(graphqlCallback)
- }
Add Comment
Please, Sign In to add comment