Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. @Override
  2. public void onResponse(Call call, final okhttp3.Response response) throws IOException {
  3. activity.runOnUiThread(new Runnable() {
  4. @Override
  5. public void run() {
  6. try {
  7.  
  8. ResponseBody responseBody = response.body();
  9. String content = responseBody.string();
  10.  
  11. Log.e("TAG", "save or publish article" + content);
  12.  
  13. JSONObject response = new JSONObject(content);
  14.  
  15. if (response.has("success")) {
  16.  
  17. JSONArray jsonArray = response.getJSONArray("data");
  18.  
  19. if (jsonArray.length() > 0) {
  20. txtNoData.setVisibility(View.GONE);
  21.  
  22. final ArrayList<HashMap<String, String>> articleList = new ArrayList<HashMap<String, String>>();
  23. for (int i = 0; i < jsonArray.length(); i++) {
  24. JSONObject jsonObject = jsonArray.getJSONObject(i);
  25.  
  26. HashMap<String, String> store = new HashMap<String, String>();
  27. store.put("article_id", jsonObject.getString("id"));
  28. store.put("advisor_id", jsonObject.getString("advisor_id"));
  29. store.put("title", jsonObject.getString("title"));
  30. store.put("article_image", jsonObject.getString("image"));
  31. store.put("likes", jsonObject.getString("likes"));
  32. store.put("has_liked", jsonObject.getString("has_liked"));
  33.  
  34. **JSONObject advisor = jsonObject.getJSONObject("advisor");**
  35. String name = advisor.getString("name");
  36. String image;
  37. if (advisor.getString("image").equals("")) {
  38.  
  39. image = "null";
  40. } else {
  41. image = advisor.getString("image");
  42. }
  43. String date = advisor.getString("created_at").split(" ")[0];
  44.  
  45. SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd");
  46. Date newDate = spf.parse(date);
  47. spf = new SimpleDateFormat("dd MMM yyyy");
  48. date = spf.format(newDate);
  49. System.out.println(date);
  50.  
  51. store.put("name", name);
  52. store.put("advisor_image", image);
  53. store.put("created_at", date);
  54.  
  55. articleList.add(store);
  56. }
Add Comment
Please, Sign In to add comment