use of com.amazonaws.amplify.generated.graphql.CreatePostMutation in project aws-mobile-appsync-sdk-android by awslabs.
the class AddPostActivity method save.
private void save() {
final AddPostActivity display = this;
String title = ((EditText) findViewById(R.id.updateTitle)).getText().toString();
String author = ((EditText) findViewById(R.id.updateAuthor)).getText().toString();
String url = ((EditText) findViewById(R.id.updateUrl)).getText().toString();
String content = ((EditText) findViewById(R.id.updateContent)).getText().toString();
final AWSAppSyncClient client = ClientFactory.getInstance(this.getApplicationContext());
CreatePostMutation.Data expected = new CreatePostMutation.Data(null);
CreatePostInput createPostInput = CreatePostInput.builder().title(title).author(author).content(content).url(url).ups(0).downs(0).build();
CreatePostMutation addPostMutation = CreatePostMutation.builder().input(createPostInput).build();
client.mutate(addPostMutation, expected).enqueue(new GraphQLCall.Callback<CreatePostMutation.Data>() {
@Override
public void onResponse(@Nonnull final Response<CreatePostMutation.Data> response) {
Log.d(TAG, "Post added");
// Add To Delta Table
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(display, "Added!", Toast.LENGTH_SHORT).show();
display.finish();
}
});
}
@Override
public void onFailure(@Nonnull ApolloException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(display, "Failed to add post!", Toast.LENGTH_SHORT).show();
display.finish();
}
});
Log.d(TAG, "Post add failed with [" + e.getLocalizedMessage() + "]");
e.printStackTrace();
}
});
}
Aggregations