use of com.stx.xhb.dmgameapp.entity.ForumBean 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();
}
});
}
Aggregations