Java Code Examples for com.socks.jiandan.model.Comment4FreshNews

The following examples show how to use com.socks.jiandan.model.Comment4FreshNews. 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
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 6 votes vote down vote up
private void getParenFreshNews(ArrayList<Comment4FreshNews> tempComments, ArrayList<Comment4FreshNews> comment4FreshNewses, int parentId) {

        for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
            if (comment4FreshNews.getId() != parentId) continue;
            //找到了父评论
            tempComments.add(comment4FreshNews);
            //父评论又有父评论
            if (comment4FreshNews.getParentId() != 0 && comment4FreshNews.getParentComments() != null) {
                comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                tempComments.addAll(comment4FreshNews.getParentComments());
                return;
            }
            //父评论没有父评论了
            comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
        }
    }
 
Example #2
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 6 votes vote down vote up
private void getParenFreshNews(ArrayList<Comment4FreshNews> tempComments, ArrayList<Comment4FreshNews> comment4FreshNewses, int parentId) {

        for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
            if (comment4FreshNews.getId() != parentId) continue;
            //找到了父评论
            tempComments.add(comment4FreshNews);
            //父评论又有父评论
            if (comment4FreshNews.getParentId() != 0 && comment4FreshNews.getParentComments() != null) {
                comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                tempComments.addAll(comment4FreshNews.getParentComments());
                return;
            }
            //父评论没有父评论了
            comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
        }
    }
 
Example #3
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: FreshNewsCommentParser.java    License: Apache License 2.0 6 votes vote down vote up
private void getParenFreshNews(ArrayList<Comment4FreshNews> tempComments, ArrayList<Comment4FreshNews> comment4FreshNewses, int parentId) {

        for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
            if (comment4FreshNews.getId() != parentId) continue;
            //找到了父评论
            tempComments.add(comment4FreshNews);
            //父评论又有父评论
            if (comment4FreshNews.getParentId() != 0 && comment4FreshNews.getParentComments() != null) {
                comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                tempComments.addAll(comment4FreshNews.getParentComments());
                return;
            }
            //父评论没有父评论了
            comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
        }
    }
 
Example #4
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: JDApi.java    License: Apache License 2.0 6 votes vote down vote up
public static Observable<ArrayList<Comment4FreshNews>> getCommentator4FreshNews(final String thread_key, LoadFinishCallBack callBack) {

        return Observable.create(new Observable.OnSubscribe<ArrayList<Comment4FreshNews>>() {

            @Override
            public void call(Subscriber<? super ArrayList<Comment4FreshNews>> subscriber) {
                String url = Comment4FreshNews.getUrlComments(thread_key);
                try {
                    subscriber.onNext(new FreshNewsCommentParser(callBack).parse(OkHttpProxy.get()
                            .url(url)
                            .execute()));
                    subscriber.onCompleted();
                } catch (IOException e) {
                    subscriber.onError(e);
                }
            }
        }).compose(applySchedulers());
    }
 
Example #5
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: FreshNewsCommentParser.java    License: Apache License 2.0 6 votes vote down vote up
private void getParenFreshNews(ArrayList<Comment4FreshNews> tempComments, ArrayList<Comment4FreshNews> comment4FreshNewses, int parentId) {

        for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
            if (comment4FreshNews.getId() != parentId) continue;
            //找到了父评论
            tempComments.add(comment4FreshNews);
            //父评论又有父评论
            if (comment4FreshNews.getParentId() != 0 && comment4FreshNews.getParentComments() != null) {
                comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                tempComments.addAll(comment4FreshNews.getParentComments());
                return;
            }
            //父评论没有父评论了
            comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
        }
    }
 
Example #6
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 6 votes vote down vote up
private void getParenFreshNews(ArrayList<Comment4FreshNews> tempComments, ArrayList<Comment4FreshNews> comment4FreshNewses, int parentId) {

        for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
            if (comment4FreshNews.getId() != parentId) continue;
            //找到了父评论
            tempComments.add(comment4FreshNews);
            //父评论又有父评论
            if (comment4FreshNews.getParentId() != 0 && comment4FreshNews.getParentComments() != null) {
                comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                tempComments.addAll(comment4FreshNews.getParentComments());
                return;
            }
            //父评论没有父评论了
            comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
        }
    }
 
Example #7
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4PushFreshComment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 包装无父评论的请求参数
 *
 * @return
 */
public static String getRequestURLNoParent(String post_id,String name, String email,String content) {
	//方法1 转义
	//content= MessageFormat.format("%40%3Ca+href%3D%27%23comment-{0}%27%3E{1}%3C%2Fa%3E%3A+{2}",parent_id,parent_name, content);
	//方法2 URLEncoder(更优)
	try {
		name = URLEncoder.encode(name, "utf-8");
		content=URLEncoder.encode(content, "utf-8");
	}catch (Exception ex){
		Logger.d("URLEncoder error");
	}
	return   MessageFormat.format("{0}&post_id={1}&content={2}&email={3}&name={4}",
			Comment4FreshNews.URL_PUSH_COMMENT, post_id, content, email, name);
}
 
Example #8
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4PushFreshComment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 包装无父评论的请求参数
 *
 * @return
 */
public static String getRequestURLNoParent(String post_id,String name, String email,String content) {
	//方法1 转义
	//content= MessageFormat.format("%40%3Ca+href%3D%27%23comment-{0}%27%3E{1}%3C%2Fa%3E%3A+{2}",parent_id,parent_name, content);
	//方法2 URLEncoder(更优)
	try {
		name = URLEncoder.encode(name, "utf-8");
		content=URLEncoder.encode(content, "utf-8");
	}catch (Exception ex){
		Logger.d("URLEncoder error");
	}
	return   MessageFormat.format("{0}&post_id={1}&content={2}&email={3}&name={4}",
			Comment4FreshNews.URL_PUSH_COMMENT, post_id, content, email, name);
}
 
Example #9
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: CommentAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void loadData4FreshNews() {
    Subscription subscriptions = JDApi.getCommentator4FreshNews(mThread_key, obj -> thread_id = (String) obj)
            .subscribe(comment4FreshNewses -> {
                if (comment4FreshNewses.size() == 0) {
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_NONE, null);
                } else {
                    Comment4FreshNews.generateComment(comment4FreshNewses, mCommentators4FreshNews);
                    notifyDataSetChanged();
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                }
            }, e -> {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET);
            });
    mActivity.addSubscription(subscriptions);
}
 
Example #10
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: Push4FreshCommentParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 包装无父评论的请求参数
 *
 * @return
 */
public static String getRequestURLNoParent(String post_id, String name, String email, String content) {
    //方法1 转义
    //content= MessageFormat.format("%40%3Ca+href%3D%27%23comment-{0}%27%3E{1}%3C%2Fa%3E%3A+{2}",parent_id,parent_name, content);
    //方法2 URLEncoder(更优)
    try {
        name = URLEncoder.encode(name, "utf-8");
        content = URLEncoder.encode(content, "utf-8");
    } catch (Exception ex) {
        KLog.e("URLEncoder error");
    }
    return MessageFormat.format("{0}&post_id={1}&content={2}&email={3}&name={4}",
            Comment4FreshNews.URL_PUSH_COMMENT, post_id, content, email, name);
}
 
Example #11
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Push4FreshCommentParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 包装无父评论的请求参数
 *
 * @return
 */
public static String getRequestURLNoParent(String post_id, String name, String email, String content) {
    //方法1 转义
    //content= MessageFormat.format("%40%3Ca+href%3D%27%23comment-{0}%27%3E{1}%3C%2Fa%3E%3A+{2}",parent_id,parent_name, content);
    //方法2 URLEncoder(更优)
    try {
        name = URLEncoder.encode(name, "utf-8");
        content = URLEncoder.encode(content, "utf-8");
    } catch (Exception ex) {
        Logger.d("URLEncoder error");
    }
    return MessageFormat.format("{0}&post_id={1}&content={2}&email={3}&name={4}",
            Comment4FreshNews.URL_PUSH_COMMENT, post_id, content, email, name);
}
 
Example #12
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4PushFreshComment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 包装无父评论的请求参数
 *
 * @return
 */
public static String getRequestURLNoParent(String post_id, String name, String email, String content) {
    //方法1 转义
    //content= MessageFormat.format("%40%3Ca+href%3D%27%23comment-{0}%27%3E{1}%3C%2Fa%3E%3A+{2}",parent_id,parent_name, content);
    //方法2 URLEncoder(更优)
    try {
        name = URLEncoder.encode(name, "utf-8");
        content = URLEncoder.encode(content, "utf-8");
    } catch (Exception ex) {
        Logger.d("URLEncoder error");
    }
    return MessageFormat.format("{0}&post_id={1}&content={2}&email={3}&name={4}",
            Comment4FreshNews.URL_PUSH_COMMENT, post_id, content, email, name);
}
 
Example #13
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: CommentAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private List<Comment4FreshNews> addFloors4FreshNews(Comment4FreshNews commentator) {
    return commentator.getParentComments();
}
 
Example #14
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
public Request4FreshNewsCommentList(String url, Response.Listener<ArrayList<Comment4FreshNews>> listener,
                                    Response.ErrorListener errorListener, LoadFinishCallBack callBack) {
    super(Method.GET, url, errorListener);
    mListener = listener;
    mCallBack = callBack;
}
 
Example #15
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Comment4FreshNews>> parseNetworkResponse(NetworkResponse response) {

    try {
        String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr,
                    new TypeToken<ArrayList<Comment4FreshNews>>() {
                    }.getType());

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            Logger.d("" + comment4FreshNewses);

            return Response.success(comment4FreshNewses, HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {
            return Response.error(new ParseError(new Exception("request failed")));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #16
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Comment4FreshNews> response) {
    mListener.onResponse(response);
}
 
Example #17
Source Project: JianDan   Author: ZhaoKaiQiang   File: CommentAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private List<Comment4FreshNews> addFloors4FreshNews(Comment4FreshNews commentator) {
    return commentator.getParentComments();
}
 
Example #18
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
public Request4FreshNewsCommentList(String url, Response.Listener<ArrayList<Comment4FreshNews>> listener,
                                    Response.ErrorListener errorListener, LoadFinishCallBack callBack) {
    super(Method.GET, url, errorListener);
    mListener = listener;
    mCallBack = callBack;
}
 
Example #19
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Comment4FreshNews>> parseNetworkResponse(NetworkResponse response) {

    try {
        String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr,
                    new TypeToken<ArrayList<Comment4FreshNews>>() {
                    }.getType());

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            Logger.d("" + comment4FreshNewses);

            return Response.success(comment4FreshNewses, HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {
            return Response.error(new ParseError(new Exception("request failed")));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #20
Source Project: JianDan   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Comment4FreshNews> response) {
    mListener.onResponse(response);
}
 
Example #21
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: CommentAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private List<Comment4FreshNews> addFloors4FreshNews(Comment4FreshNews commentator) {
    return commentator.getParentComments();
}
 
Example #22
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: FreshNewsCommentParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public ArrayList<Comment4FreshNews> parse(Response response) {

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

    try {
        String resultStr = response.body().string();
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            Type type = new TypeToken<ArrayList<Comment4FreshNews>>() {
            }.getType();

            ArrayList<Comment4FreshNews> comment4FreshNewses = new GsonHelper<ArrayList<Comment4FreshNews>>().fromJson(commentsStr, type);

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            return comment4FreshNewses;
        } else {
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #23
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: FreshNewsCommentParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public ArrayList<Comment4FreshNews> parse(Response response) {

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

    try {
        String resultStr = response.body().string();
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr,
                    new TypeToken<ArrayList<Comment4FreshNews>>() {
                    }.getType());

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            Logger.d("" + comment4FreshNewses);
            return comment4FreshNewses;
        } else {
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #24
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: CommentAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private List<Comment4FreshNews> addFloors4FreshNews(Comment4FreshNews commentator) {
    return commentator.getParentComments();
}
 
Example #25
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
public Request4FreshNewsCommentList(String url, Response.Listener<ArrayList<Comment4FreshNews>> listener,
                                    Response.ErrorListener errorListener, LoadFinishCallBack callBack) {
    super(Method.GET, url, errorListener);
    mListener = listener;
    mCallBack = callBack;
}
 
Example #26
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Response<ArrayList<Comment4FreshNews>> parseNetworkResponse(NetworkResponse response) {

    try {
        String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr,
                    new TypeToken<ArrayList<Comment4FreshNews>>() {
                    }.getType());

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            Logger.d("" + comment4FreshNewses);

            return Response.success(comment4FreshNewses, HttpHeaderParser
                    .parseCacheHeaders(response));
        } else {
            return Response.error(new ParseError(new Exception("request failed")));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #27
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: Request4FreshNewsCommentList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void deliverResponse(ArrayList<Comment4FreshNews> response) {
    mListener.onResponse(response);
}