Search in sources :

Example 1 with IntList

use of com.hippo.yorozuya.collect.IntList 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

SuppressLint (android.annotation.SuppressLint)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Resources (android.content.res.Resources)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 GalleryComment (com.hippo.ehviewer.client.data.GalleryComment)1 IntList (com.hippo.yorozuya.collect.IntList)1 ArrayList (java.util.ArrayList)1