Created
October 29, 2015 04:29
-
-
Save BenjaminLu/62bb08bc3fa634d980ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class GetFavoriteActivitiesAsyncTask extends AsyncTask<Void, Void, Void> | |
{ | |
List<ActivityDescription> favoriteActivityDescriptionList = new ArrayList<>(); | |
@Override | |
protected Void doInBackground(Void... params) | |
{ | |
HttpRequest request = HttpRequest.get(getActivity().getString(R.string.get_favorite_activities)).header("Cookie", mSession); | |
if (request.ok()) { | |
String response = request.body(); | |
try { | |
JSONArray array = new JSONArray(response); | |
for (int i = 0; i < array.length(); i++) { | |
JSONObject object = array.getJSONObject(i); | |
int id = object.getInt("id"); | |
String name = object.getString("name"); | |
String body = object.getString("body"); | |
String imageURL = object.getString("image"); | |
String gainStartDate = object.getString("gain_start"); | |
String gainEndDate = object.getString("gain_end"); | |
String exchangeStartDate = object.getString("ex_start"); | |
String exchangeEndDate = object.getString("ex_end"); | |
ActivityDescription activityDescription = new ActivityDescription(); | |
activityDescription.setId(id); | |
activityDescription.setActivityName(name); | |
activityDescription.setActivityContent(body); | |
activityDescription.setActivityImageURL(imageURL); | |
activityDescription.setGainStartDate(gainStartDate); | |
activityDescription.setGainEndDate(gainEndDate); | |
activityDescription.setExchangeStartDate(exchangeStartDate); | |
activityDescription.setExchangeEndDate(exchangeEndDate); | |
favoriteActivityDescriptionList.add(activityDescription); | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
return null; | |
} | |
@Override | |
protected void onPostExecute(Void result) | |
{ | |
//do something with favoriteActivityDescriptionList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment