Java Code Examples for com.socks.jiandan.model.Commentator#setTag()

The following examples show how to use com.socks.jiandan.model.Commentator#setTag() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 2
Source Project: JianDan   File: Request4CommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 3
Source Project: JianDanRxJava   File: CommentListParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ArrayList<Commentator> parse(Response response) {

    if (!response.isSuccessful())
        return null;


    try {
        //获取到所有的数据
        String jsonStr = response.body().string();
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        mCallBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return new ArrayList<>();
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return commentators;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 4
@Nullable
@Override
public ArrayList<Commentator> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;


    try {
        //获取到所有的数据
        String jsonStr = response.body().string();
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return new ArrayList<>();
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return commentators;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
@Override
protected Response<ArrayList<Commentator>> parseNetworkResponse(NetworkResponse response) {

    try {
        //获取到所有的数据
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultJson = new JSONObject(jsonStr);
        String allThreadId = resultJson.getString("response").replace("[", "").replace
                ("]", "").replace("\"", "");
        String[] threadIds = allThreadId.split("\\,");

        callBack.loadFinish(resultJson.optJSONObject("thread").optString("thread_id"));

        if (TextUtils.isEmpty(threadIds[0])) {
            return Response.success(new ArrayList<Commentator>(), HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {

            //然后根据thread_id再去获得对应的评论和作者信息
            JSONObject parentPostsJson = resultJson.getJSONObject("parentPosts");
            //找出热门评论
            String hotPosts = resultJson.getString("hotPosts").replace("[", "").replace
                    ("]", "").replace("\"", "");
            String[] allHotPosts = hotPosts.split("\\,");

            ArrayList<Commentator> commentators = new ArrayList<>();
            List<String> allHotPostsArray = Arrays.asList(allHotPosts);

            for (String threadId : threadIds) {
                Commentator commentator = new Commentator();
                JSONObject threadObject = parentPostsJson.getJSONObject(threadId);

                //解析评论,打上TAG
                if (allHotPostsArray.contains(threadId)) {
                    commentator.setTag(Commentator.TAG_HOT);
                } else {
                    commentator.setTag(Commentator.TAG_NORMAL);
                }

                commentator.setPost_id(threadObject.optString("post_id"));
                commentator.setParent_id(threadObject.optString("parent_id"));

                String parentsString = threadObject.optString("parents").replace("[", "").replace
                        ("]", "").replace("\"", "");

                String[] parents = parentsString.split("\\,");
                commentator.setParents(parents);

                //如果第一个数据为空,则只有一层
                if (TextUtil.isNull(parents[0])) {
                    commentator.setFloorNum(1);
                } else {
                    commentator.setFloorNum(parents.length + 1);
                }

                commentator.setMessage(threadObject.optString("message"));
                commentator.setCreated_at(threadObject.optString("created_at"));
                JSONObject authorObject = threadObject.optJSONObject("author");
                commentator.setName(authorObject.optString("name"));
                commentator.setAvatar_url(authorObject.optString("avatar_url"));
                commentator.setType(Commentator.TYPE_NORMAL);
                commentators.add(commentator);
            }

            return Response.success(commentators, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}