Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onResponse(Call call, final okhttp3.Response response) throws IOException {
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- try {
- ResponseBody responseBody = response.body();
- String content = responseBody.string();
- Log.e("TAG", "save or publish article" + content);
- JSONObject response = new JSONObject(content);
- if (response.has("success")) {
- JSONArray jsonArray = response.getJSONArray("data");
- if (jsonArray.length() > 0) {
- txtNoData.setVisibility(View.GONE);
- final ArrayList<HashMap<String, String>> articleList = new ArrayList<HashMap<String, String>>();
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- HashMap<String, String> store = new HashMap<String, String>();
- store.put("article_id", jsonObject.getString("id"));
- store.put("advisor_id", jsonObject.getString("advisor_id"));
- store.put("title", jsonObject.getString("title"));
- store.put("article_image", jsonObject.getString("image"));
- store.put("likes", jsonObject.getString("likes"));
- store.put("has_liked", jsonObject.getString("has_liked"));
- **JSONObject advisor = jsonObject.getJSONObject("advisor");**
- String name = advisor.getString("name");
- String image;
- if (advisor.getString("image").equals("")) {
- image = "null";
- } else {
- image = advisor.getString("image");
- }
- String date = advisor.getString("created_at").split(" ")[0];
- SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd");
- Date newDate = spf.parse(date);
- spf = new SimpleDateFormat("dd MMM yyyy");
- date = spf.format(newDate);
- System.out.println(date);
- store.put("name", name);
- store.put("advisor_image", image);
- store.put("created_at", date);
- articleList.add(store);
- }
Add Comment
Please, Sign In to add comment