Search in sources :

Example 6 with GalleryComment

use of com.hippo.ehviewer.client.data.GalleryComment in project EhViewer by seven332.

the class GalleryCommentsScene method showCommentDialog.

private void showCommentDialog(int position) {
    final Context context = getContext2();
    if (null == context || null == mComments || position >= mComments.length || position < 0) {
        return;
    }
    final GalleryComment comment = mComments[position];
    List<String> menu = new ArrayList<>();
    final IntList menuId = new IntList();
    Resources resources = context.getResources();
    if (0 == comment.id || mApiUid < 0) {
        // 0 id is uploader comment, can't vote
        // Not sign in, can't vote
        menu.add(resources.getString(R.string.copy_comment_text));
        menuId.add(R.id.copy);
    } else {
        menu.add(resources.getString(R.string.copy_comment_text));
        menuId.add(R.id.copy);
        menu.add(resources.getString(comment.voteUp ? R.string.cancel_vote_up : R.string.vote_up));
        menuId.add(R.id.vote_up);
        menu.add(resources.getString(comment.voteDown ? R.string.cancel_vote_down : R.string.vote_down));
        menuId.add(R.id.vote_down);
    }
    if (!TextUtils.isEmpty(comment.voteState)) {
        menu.add(resources.getString(R.string.check_vote_status));
        menuId.add(R.id.check_vote_status);
    }
    new AlertDialog.Builder(context).setItems(menu.toArray(new String[menu.size()]), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which < 0 || which >= menuId.size()) {
                return;
            }
            int id = menuId.get(which);
            switch(id) {
                case R.id.copy:
                    ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                    cmb.setPrimaryClip(ClipData.newPlainText(null, comment.comment));
                    showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
                    break;
                case R.id.vote_up:
                    voteComment(comment.id, 1);
                    break;
                case R.id.vote_down:
                    voteComment(comment.id, -1);
                    break;
                case R.id.check_vote_status:
                    showVoteStatusDialog(context, comment.voteState);
                    break;
            }
        }
    }).show();
}
Also used : Context(android.content.Context) ClipboardManager(android.content.ClipboardManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) Resources(android.content.res.Resources) SuppressLint(android.annotation.SuppressLint) IntList(com.hippo.yorozuya.collect.IntList)

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