Search in sources :

Example 1 with GalleryComment

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));
    }
}
Also used : Context(android.content.Context) ObservedTextView(com.hippo.widget.ObservedTextView) LayoutInflater(android.view.LayoutInflater) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) URLImageGetter(com.hippo.text.URLImageGetter) TextView(android.widget.TextView) ObservedTextView(com.hippo.widget.ObservedTextView) ImageView(android.widget.ImageView) LoadImageView(com.hippo.widget.LoadImageView) ProgressView(com.hippo.widget.ProgressView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ObservedTextView(com.hippo.widget.ObservedTextView) SuppressLint(android.annotation.SuppressLint)

Example 2 with GalleryComment

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;
    }
}
Also used : Element(org.jsoup.nodes.Element) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) OffensiveException(com.hippo.ehviewer.client.exception.OffensiveException) PiningException(com.hippo.ehviewer.client.exception.PiningException) Nullable(android.support.annotation.Nullable)

Example 3 with GalleryComment

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);
}
Also used : Bundle(android.os.Bundle) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) SuppressLint(android.annotation.SuppressLint)

Example 4 with GalleryComment

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;
    }
}
Also used : Element(org.jsoup.nodes.Element) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) OffensiveException(com.hippo.ehviewer.client.exception.OffensiveException) PiningException(com.hippo.ehviewer.client.exception.PiningException) NonNull(android.support.annotation.NonNull)

Example 5 with GalleryComment

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()]);
}
Also used : Matcher(java.util.regex.Matcher) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) LinkedList(java.util.LinkedList) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Aggregations

GalleryComment (com.hippo.ehviewer.client.data.GalleryComment)6 SuppressLint (android.annotation.SuppressLint)3 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 EhException (com.hippo.ehviewer.client.exception.EhException)2 OffensiveException (com.hippo.ehviewer.client.exception.OffensiveException)2 ParseException (com.hippo.ehviewer.client.exception.ParseException)2 PiningException (com.hippo.ehviewer.client.exception.PiningException)2 ArrayList (java.util.ArrayList)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 ClipboardManager (android.content.ClipboardManager)1 DialogInterface (android.content.DialogInterface)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1