Sign up for heroku, you will need it to gain access to the data
Create a new Android Project called HerokuApp and
download the src file. Replace the src file of your app with the downloaded one (unzip and move to the app directory of your project). These are the dependencies you will need for GSON and Retrofit 2.0:
Login to the app using the credentials you gave yourself during signup. The username and password are simply being stored in the default preferences for the application. This is obviously an unsafe way of storing a password but for our purposes it will do. Feel free to change this to work however you like.
You will be using GSON model JSON objects in java. Read through this GSON example and look at the Consuming JSON objects section. They show you how to set up a Model class for JSON objects as well as how to convert JSON to a Model.
Add GSON to your dependencies if you haven't yet.
Implement the custom_list_item.xml resource file to display the information associated with the model you created. A simple way of doing this is using 3 textviews for name, genre and platform. NOTE: set the focusable attribute of the button you use to “false”, this allows you to click on the list item AND the button in the list item.
Implement the CustomAdapter class to work for the model and list item you created. Look at the TODOs and the existing code. It should be fairly self explanatory, but don't be afraid to ask for help.
MAKE SURE YOUR CUSTOM ADAPTER WORKS BEFORE CONTINUING
Now it is time to make some http requests using the Retrofit 2.0 api. There library abstracts away much of the nitty-gritty work with http clients and provides an easier way of making http requests.
Carefully look over these links from the Retrofit website
, they have an excellent developer page with examples on how to set up the ServiceGenerator and ServiceClient interface. We will be dealing with Sectoin 1,2,and 5 mostly.
You have been given a partially implemented ServiceGenerator Class, you may delete that and start from scratch or implement the TODOs. Here is where you authorization gets handled. Make sure you are passing your username and passoword in as arguments to the createService method while instantiating a ServiceClient. You will have to add them to the HTTP header as marked by the TODOs in the with this:
Set up the GameClient interface to make a GET request to /api/games
Now comes the fun part. Read about Syncronous and Asyncronous Requests
and implement asyncronous call in the getGamesRetro() method in MainActivity to retrieve the game json file.
Use GSON to deserialize this json file to populate your listview.
Holy Cow! It Works!!! Now implement the delete request in the CustomAdapter
Additional Tasks (Optional)
Now you should have a fairly decent introduction to HTTP, JSON and common 3rd Party Libraries, but to become a Master Programmer you can do these additional excercises:
Implement a safer way to handle username and password needs
Implement a way to make new POSTS
Implement the onClick of the list items to display additional information about the game
Do the beginner MEAN stack tutorial
It is quick tutorial that glosses over a lot of extremely useful tools. When configuring yo, be sure to say yes to a authentication boilerplate even though the tutorial says no. If not, you will have errors.