Adding REST Support & Project Clean Up
The main purpose of this version of Donation is to connect to a Web Service (our sister site) and be able to retrieve, insert and delete Donations.
To make things a bit easier I've devloped a simple API to make the HTTP calls and convert the responses from JSON into objects our Android App can use.
So go ahead and download the package here.
The extracted archive consists of the following:
- DonationApi.java
- Rest.java
(viewed in Finder)
You will need to add these classes to your Android Studio Project and the simplest way is to copy the api folder in Windows Explorer or Finder and paste directly into your ie.app package in your Android Studio Project. Once completed, your project should look something like this:
Now, if you Rebuild the project
Build->Rebuild Project
you'll have a number of errors relating to Googles Gson, so first thing to do is add Googles Gson's dependency to our project:
Open your 'build.gradle' file for app, NOT THE PROJECT!
Add the Gson dependency
compile 'com.google.code.gson:gson:2.2.3'
so your dependencies in your build file looks something like this
Rebuild your project again and you should now be error free!
The next thing we need to do is remove/delete our database classes and reintroduce a simple list back into our DonationApp Application class.
So,
- first, just delete the whole ie.app.database package (don't worry about the errors, we'll fix those soon)
- next, reintroduce our donations list into the DonationApp class
public List <Donation> donations = new ArrayList<Donation>();
- finally, remove all references to dbManager in the project and replace with our donations or app.donations (depending on the context).
We've actually taken a step back as regards functionality, as we're not adding donations to our list directly - the list is only to be used to hold the result of our REST calls.
So let's go ahead and start using our REST classes for data retrieval.