Search in sources :

Example 1 with NewsDetailBean

use of com.lauren.simplenews.beans.NewsDetailBean in project SimpleNews by liuling07.

the class NewsJsonUtils method readJsonNewsDetailBeans.

public static NewsDetailBean readJsonNewsDetailBeans(String res, String docId) {
    NewsDetailBean newsDetailBean = null;
    try {
        JsonParser parser = new JsonParser();
        JsonObject jsonObj = parser.parse(res).getAsJsonObject();
        JsonElement jsonElement = jsonObj.get(docId);
        if (jsonElement == null) {
            return null;
        }
        newsDetailBean = JsonUtils.deserialize(jsonElement.getAsJsonObject(), NewsDetailBean.class);
    } catch (Exception e) {
        LogUtils.e(TAG, "readJsonNewsBeans error", e);
    }
    return newsDetailBean;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) NewsDetailBean(com.lauren.simplenews.beans.NewsDetailBean) JsonParser(com.google.gson.JsonParser)

Example 2 with NewsDetailBean

use of com.lauren.simplenews.beans.NewsDetailBean in project SimpleNews by liuling07.

the class NewsModelImpl method loadNewsDetail.

/**
     * 加载新闻详情
     * @param docid
     * @param listener
     */
@Override
public void loadNewsDetail(final String docid, final OnLoadNewsDetailListener listener) {
    String url = getDetailUrl(docid);
    OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {

        @Override
        public void onSuccess(String response) {
            NewsDetailBean newsDetailBean = NewsJsonUtils.readJsonNewsDetailBeans(response, docid);
            listener.onSuccess(newsDetailBean);
        }

        @Override
        public void onFailure(Exception e) {
            listener.onFailure("load news detail info failure.", e);
        }
    };
    OkHttpUtils.get(url, loadNewsCallback);
}
Also used : NewsDetailBean(com.lauren.simplenews.beans.NewsDetailBean) OkHttpUtils(com.lauren.simplenews.utils.OkHttpUtils)

Aggregations

NewsDetailBean (com.lauren.simplenews.beans.NewsDetailBean)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 OkHttpUtils (com.lauren.simplenews.utils.OkHttpUtils)1