/** * Constructor. * * @param jsonResult Result from API call. Used directly to populate the ArrayList. */ public GroupMembersMap(String jsonResult) { try { JSONArray jsonArray = new JSONArray(jsonResult); if (jsonArray.length() > 0) { Gson gson = new Gson(); for (int i = 0; i < jsonArray.length(); i++) { GroupMemberData member = gson.fromJson(jsonArray.getString(i), GroupMemberData.class); if (member.isNew(mMembersList)) { mMembersList.add(member); } } } } catch (JSONException ex) { System.err.println("GroupMembersMap/" + ex); } }
/** * Runs on the UI thread after doInBackground(Params...). The specified result is the value * returned by doInBackground(Params...). * * @param jsonResult Result of the API call. */ @Override protected void onPostExecute(String jsonResult) { jsonResult = jsonResult.replaceAll("firstname", "fname"); jsonResult = jsonResult.replaceAll("lastname", "lname"); GroupMembersMap friends = new GroupMembersMap(jsonResult); if (friends.size() == 0) { // If the newly pulled friends list is empty, indicate the end of data. mEndOfData = true; // If the members list is also empty, there are no group members, so add // a blank indicator showing so. if (mMembersList.size() == 0) { GroupMemberData blank = new GroupMemberData(); blank.setName("No members to display"); mMembersList.add(blank); mAdapter.notifyDataSetChanged(); mListView.setEnabled(false); } } else { // If we pulled less than 10 new friends, indicate we are at the end of data. if (friends.size() < LIMIT) { mEndOfData = true; } // Add all the new members to our list and update our ListView. mMembersList.addAll(friends.getGroupMemberData()); mAdapter.notifyDataSetChanged(); } // If we are not at the end of data, show our load more button and increase our offset. if (!mEndOfData) { mLoadMoreButton.setVisibility(View.VISIBLE); mLoadingIndicator.setVisibility(View.GONE); mOffset += friends.size(); // If we are at the end of data, remove the load more button. } else { mListView.removeFooterView(mFooter); } }