in app/src/main/java/com/amazonaws/postsapp/PostsAdapter.java [381:430]
private void downVotePost(final View view, final int position, final ListPostsQuery.ListPost p) {
//Execute Mutation
UpdatePostMutation updatePostMutation = UpdatePostMutation.builder()
.input(UpdatePostInput.builder()
.id(p.id())
.title(p.title())
.author(p.author())
.content(p.content())
.ups(p.ups())
.downs(p.downs()+1)
.build())
.build();
ClientFactory.getInstance(view.getContext()).mutate(updatePostMutation).enqueue(new GraphQLCall.Callback<UpdatePostMutation.Data>() {
@Override
public void onResponse(@Nonnull final Response<UpdatePostMutation.Data> response) {
Log.d(TAG, "Down voted successfully");
display.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(display, "Down Voted!", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onFailure(@Nonnull final ApolloException e) {
display.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(display, "Failed to Down Vote post!", Toast.LENGTH_SHORT).show();
}
});
Log.e("", e.getMessage());
}
});
//Update listPostsQuery cache for optimistic UI
display.runOnUiThread(new Runnable() {
@Override
public void run() {
allPosts.put(p.id(), new ListPostsQuery.ListPost("Post",
p.id(), p.author(), p.title(), p.content(),
p.url(), p.ups(), p.downs() + 1, p.createdDate(),
p.aws_ds()));
updateListPostsQueryCache();
notifyDataSetChanged();
}
});
}