use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.
the class GalleryDetailScene method bindComments.
private void bindComments(GalleryComment[] comments) {
Context context = getContext2();
LayoutInflater inflater = getLayoutInflater2();
if (null == context || null == inflater || null == mComments || null == mCommentsText) {
return;
}
mComments.removeViews(0, mComments.getChildCount() - 1);
final int maxShowCount = 2;
if (comments == null || comments.length == 0) {
mCommentsText.setText(R.string.no_comments);
return;
} else if (comments.length <= maxShowCount) {
mCommentsText.setText(R.string.no_more_comments);
} else {
mCommentsText.setText(R.string.more_comment);
}
int length = Math.min(maxShowCount, comments.length);
for (int i = 0; i < length; i++) {
GalleryComment comment = comments[i];
View v = inflater.inflate(R.layout.item_gallery_comment, mComments, false);
mComments.addView(v, i);
TextView user = (TextView) v.findViewById(R.id.user);
user.setText(comment.user);
TextView time = (TextView) v.findViewById(R.id.time);
time.setText(ReadableTime.getTimeAgo(comment.time));
ObservedTextView c = (ObservedTextView) v.findViewById(R.id.comment);
c.setMaxLines(5);
c.setText(Html.fromHtml(comment.comment, new URLImageGetter(c, EhApplication.getConaco(context)), null));
}
}
use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.
the class GalleryDetailParser method parseComment.
@Nullable
@SuppressWarnings("ConstantConditions")
public static GalleryComment parseComment(Element element) {
try {
GalleryComment comment = new GalleryComment();
// Id
Element a = element.previousElementSibling();
String name = a.attr("name");
comment.id = Integer.parseInt(StringUtils.trim(name).substring(1));
// Vote up and vote down
Element c4 = JsoupUtils.getElementByClass(element, "c4");
if (null != c4) {
Elements es = c4.children();
if (2 == es.size()) {
comment.voteUp = !TextUtils.isEmpty(StringUtils.trim(es.get(0).attr("style")));
comment.voteDown = !TextUtils.isEmpty(StringUtils.trim(es.get(1).attr("style")));
}
}
// Vote state
Element c7 = JsoupUtils.getElementByClass(element, "c7");
if (null != c7) {
comment.voteState = StringUtils.trim(c7.text());
}
// Score
Element c5 = JsoupUtils.getElementByClass(element, "c5");
if (null != c5) {
Elements es = c5.children();
if (!es.isEmpty()) {
comment.score = NumberUtils.parseIntSafely(StringUtils.trim(es.get(0).text()), 0);
}
}
// time
Element c3 = JsoupUtils.getElementByClass(element, "c3");
String temp = c3.ownText();
temp = temp.substring("Posted on ".length(), temp.length() - " by:".length());
comment.time = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
// user
comment.user = c3.child(0).text();
// comment
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
return comment;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.
the class GalleryCommentsScene method onVoteCommentSuccess.
private void onVoteCommentSuccess(VoteCommentParser.Result result) {
if (null == mAdapter || null == mComments) {
return;
}
int position = -1;
for (int i = 0, n = mComments.length; i < n; i++) {
GalleryComment comment = mComments[i];
if (comment.id == result.id) {
position = i;
break;
}
}
if (-1 == position) {
Log.d(TAG, "Can't find comment with id " + result.id);
return;
}
// Update comment
GalleryComment comment = mComments[position];
comment.score = result.score;
if (result.expectVote > 0) {
comment.voteUp = 0 != result.vote;
comment.voteDown = false;
} else {
comment.voteDown = 0 != result.vote;
comment.voteUp = false;
}
mAdapter.notifyItemChanged(position);
Bundle re = new Bundle();
re.putParcelableArray(KEY_COMMENTS, mComments);
setResult(SceneFragment.RESULT_OK, re);
}
use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.
the class GalleryDetailParser method parseComments.
/**
* Parse comments with html parser
*/
@NonNull
public static GalleryComment[] parseComments(Document document) {
try {
Element cdiv = document.getElementById("cdiv");
Elements c1s = cdiv.getElementsByClass("c1");
List<GalleryComment> list = new ArrayList<>(c1s.size());
for (int i = 0, n = c1s.size(); i < n; i++) {
GalleryComment comment = parseComment(c1s.get(i));
if (null != comment) {
list.add(comment);
}
}
return list.toArray(new GalleryComment[list.size()]);
} catch (Exception e) {
e.printStackTrace();
return EMPTY_GALLERY_COMMENT_ARRAY;
}
}
use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.
the class GalleryDetailParser method parseComments.
/**
* Parse comments with regular expressions
*/
@NonNull
public static GalleryComment[] parseComments(String body) {
List<GalleryComment> list = new LinkedList<>();
Matcher m = PATTERN_COMMENT.matcher(body);
while (m.find()) {
String webDateString = ParserUtils.trim(m.group(1));
Date date;
try {
date = WEB_COMMENT_DATE_FORMAT.parse(webDateString);
} catch (java.text.ParseException e) {
date = new Date(0L);
}
GalleryComment comment = new GalleryComment();
comment.time = date.getTime();
comment.user = ParserUtils.trim(m.group(2));
comment.comment = m.group(3);
list.add(comment);
}
return list.toArray(new GalleryComment[list.size()]);
}
Aggregations