AppSync SDK vs. Amplify Android?
That blog from 2018 was written with the AWS Android AppSync SDK in mind. The README on the AppSync SDK includes notes on code generation from a schema file. If you will continue to follow the 2018 blog, I would supplement your exercise with that documentation.
This year, AWS' public documentation has been updated to point customers to the new Amplify Android library. The Amplify CLI (amplify
) has also been updated to work with the Amplify Android library. The Amplify CLI will currently generate Java code that can be used by the Amplify Android API and DataStore categories.
TLDR, if you're just getting going, I'd work from the Tutorial section of the AWS Amplify Android docs.
There's also a more recent (May 2020) blog post about AppSync that you can follow, here.
Iterator<T>
and RecyclerView.Adapater
There are a ton of ways to pass the results into the adapter, of varying complexity.
The most straight-forward approach would be something like this:
First, back your adapter with a List<SomeModel>
. The List<SomeModel>
can be updated after you create the ItemAdapter
, by design:
final class ItemAdapter implements RecyclerView.Adapter<ItemHolder> {
private final List<SomeModel> data;
ItemAdapter(List<SomeModel> data) {
this.data = data;
}
}
Then, in the Amplify callback, update the List
, and notify the adapter that the dataset has changed:
List<SomeModel> models = new ArrayList<>();
ItemAdapter adapter = new ItemAdapter(models);
Amplify.API.query(SomeModel.class,
iterator -> {
if (!iterator.hasNext()) return;
models.clear();
while (iterator.hasNext()) {
models.add(iterator.next());
}
adapter.notifyDataSetChanged();
},
failure -> {
// As an exercise: display an
// error item into the RecyclerView.
}
);