Search in sources :

Example 1 with JsonResponse

use of com.stx.xhb.dmgameapp.utils.JsonResponse in project DMGameApp by xiaohaibin.

the class GetForumListPresenter method getForumListData.

@Override
public void getForumListData(String fid) {
    OkHttpUtils.postString().content(GsonUtil.newGson().toJson(new ForumContentEntity(fid, "forums"))).url(API.USER_API).build().execute(new StringCallback() {

        @Override
        public void onBefore(Request request, int id) {
            getView().showLoading();
        }

        @Override
        public void onError(Call call, Exception e, int id) {
            getView().getForumListDataFailed(e.getMessage());
        }

        @Override
        public void onResponse(String response, int id) {
            if (!TextUtils.isEmpty(response)) {
                try {
                    JsonResponse jsonResponse = new JsonResponse(new JSONObject(response));
                    if (jsonResponse.isSuccess()) {
                        List<ForumBean> dataList = new ArrayList<>();
                        JSONArray array = jsonResponse.getDataList();
                        JSONObject object = jsonResponse.getObject();
                        if (array != null && object != null) {
                            for (int i = 0; i < array.length(); i++) {
                                ForumBean forumBean = new ForumBean();
                                JSONObject jsonObject = object.getJSONObject(array.getString(i));
                                forumBean.setFid(jsonObject.getString("fid"));
                                forumBean.setName(jsonObject.getString("name"));
                                forumBean.setTodayposts(jsonObject.getString("todayposts"));
                                forumBean.setRank(jsonObject.getString("rank"));
                                forumBean.setType(jsonObject.getString("type"));
                                forumBean.setIcon(jsonObject.getString("icon"));
                                dataList.add(forumBean);
                            }
                            getView().getForumListDataSuccess(dataList);
                        } else {
                            getView().hideLoading();
                            getView().getForumListDataFailed(jsonResponse.getMsg());
                        }
                    } else {
                        getView().hideLoading();
                        getView().getForumListDataFailed(jsonResponse.getMsg());
                    }
                } catch (JSONException e) {
                    getView().hideLoading();
                    getView().getForumListDataFailed(e.getMessage());
                }
            }
        }

        @Override
        public void onAfter(int id) {
            getView().hideLoading();
        }
    });
}
Also used : Call(okhttp3.Call) StringCallback(com.zhy.http.okhttp.callback.StringCallback) Request(okhttp3.Request) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException) JsonResponse(com.stx.xhb.dmgameapp.utils.JsonResponse) JSONObject(org.json.JSONObject) ForumBean(com.stx.xhb.dmgameapp.entity.ForumBean) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ForumBean (com.stx.xhb.dmgameapp.entity.ForumBean)1 JsonResponse (com.stx.xhb.dmgameapp.utils.JsonResponse)1 StringCallback (com.zhy.http.okhttp.callback.StringCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1