Search in sources :

Example 6 with Comment

use of net.dean.jraw.models.Comment in project Slide by ccrama.

the class PopulateShadowboxInfo method doActionbar.

public static void doActionbar(final CommentNode node, final View rootView, final Activity c, boolean extras) {
    final Comment s = node.getComment();
    TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);
    String distingush = "";
    if (s != null) {
        if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR)
            distingush = "[M]";
        else if (s.getDistinguishedStatus() == DistinguishedStatus.ADMIN)
            distingush = "[A]";
        SpannableStringBuilder commentTitle = new SpannableStringBuilder();
        SpannableStringBuilder level = new SpannableStringBuilder();
        if (!node.isTopLevel()) {
            level.append("[" + node.getDepth() + "] ");
            level.setSpan(new RelativeSizeSpan(0.7f), 0, level.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            commentTitle.append(level);
        }
        commentTitle.append(Html.fromHtml(s.getDataNode().get("body_html").asText().trim()));
        title.setTextHtml(commentTitle);
        title.setMaxLines(3);
        String spacer = c.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        SpannableStringBuilder author = new SpannableStringBuilder(" /u/" + s.getAuthor() + " ");
        int authorcolor = Palette.getFontColorUser(s.getAuthor());
        if (Authentication.name != null && s.getAuthor().toLowerCase(Locale.ENGLISH).equals(Authentication.name.toLowerCase(Locale.ENGLISH))) {
            author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_deep_orange_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (s.getDistinguishedStatus() == DistinguishedStatus.MODERATOR || s.getDistinguishedStatus() == DistinguishedStatus.ADMIN) {
            author.setSpan(new RoundedBackgroundSpan(c, R.color.white, R.color.md_green_300, false), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (authorcolor != 0) {
            author.setSpan(new ForegroundColorSpan(authorcolor), 0, author.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        titleString.append(author);
        titleString.append(distingush);
        titleString.append(spacer);
        titleString.append(TimeUtils.getTimeAgo(s.getCreated().getTime(), c));
        desc.setText(titleString);
        ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
        if (extras) {
            final ImageView downvotebutton = (ImageView) rootView.findViewById(R.id.downvote);
            final ImageView upvotebutton = (ImageView) rootView.findViewById(R.id.upvote);
            if (s.isArchived()) {
                downvotebutton.setVisibility(View.GONE);
                upvotebutton.setVisibility(View.GONE);
            } else if (Authentication.isLoggedIn && Authentication.didOnline) {
                if (SettingValues.actionbarVisible && downvotebutton.getVisibility() != View.VISIBLE) {
                    downvotebutton.setVisibility(View.VISIBLE);
                    upvotebutton.setVisibility(View.VISIBLE);
                }
                switch(ActionStates.getVoteDirection(s)) {
                    case UPVOTE:
                        {
                            ((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
                            upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
                            ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
                            ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : 1))));
                            downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                            break;
                        }
                    case DOWNVOTE:
                        {
                            ((TextView) rootView.findViewById(R.id.score)).setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
                            downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
                            ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
                            ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", (s.getScore() + ((s.getAuthor().equals(Authentication.name)) ? 0 : -1))));
                            upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                            break;
                        }
                    case NO_VOTE:
                        {
                            ((TextView) rootView.findViewById(R.id.score)).setTextColor(((TextView) rootView.findViewById(R.id.comments)).getCurrentTextColor());
                            ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
                            ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
                            downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                            upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                            break;
                        }
                }
            }
            if (Authentication.isLoggedIn && Authentication.didOnline) {
                if (ActionStates.isSaved(s)) {
                    ((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
                } else {
                    ((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                }
                rootView.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                try {
                                    if (ActionStates.isSaved(s)) {
                                        new AccountManager(Authentication.reddit).unsave(s);
                                        ActionStates.setSaved(s, false);
                                    } else {
                                        new AccountManager(Authentication.reddit).save(s);
                                        ActionStates.setSaved(s, true);
                                    }
                                } catch (ApiException e) {
                                    e.printStackTrace();
                                }
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void aVoid) {
                                ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                                if (ActionStates.isSaved(s)) {
                                    ((ImageView) rootView.findViewById(R.id.save)).setColorFilter(ContextCompat.getColor(c, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
                                    AnimateHelper.setFlashAnimation(rootView, rootView.findViewById(R.id.save), ContextCompat.getColor(c, R.color.md_amber_500));
                                } else {
                                    ((ImageView) rootView.findViewById(R.id.save)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                                }
                            }
                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                });
            }
            if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                rootView.findViewById(R.id.save).setVisibility(View.GONE);
            }
            try {
                final TextView points = ((TextView) rootView.findViewById(R.id.score));
                final TextView comments = ((TextView) rootView.findViewById(R.id.comments));
                if (Authentication.isLoggedIn && Authentication.didOnline) {
                    {
                        downvotebutton.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                                if (ActionStates.getVoteDirection(s) != VoteDirection.DOWNVOTE) {
                                    // has not been downvoted
                                    points.setTextColor(ContextCompat.getColor(c, R.color.md_blue_500));
                                    downvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
                                    upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                                    AnimateHelper.setFlashAnimation(rootView, downvotebutton, ContextCompat.getColor(c, R.color.md_blue_500));
                                    ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
                                    // if a post is at 0 votes, keep it at 0 when downvoting
                                    final int downvoteScore = (s.getScore() == 0) ? 0 : s.getScore() - 1;
                                    ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", downvoteScore));
                                    new Vote(false, points, c).execute(s);
                                    ActionStates.setVoteDirection(s, VoteDirection.DOWNVOTE);
                                } else {
                                    points.setTextColor(comments.getCurrentTextColor());
                                    new Vote(points, c).execute(s);
                                    ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
                                    ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
                                    ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
                                    downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                                }
                            }
                        });
                    }
                    {
                        upvotebutton.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                                if (ActionStates.getVoteDirection(s) != VoteDirection.UPVOTE) {
                                    // has not been upvoted
                                    points.setTextColor(ContextCompat.getColor(c, R.color.md_orange_500));
                                    upvotebutton.setColorFilter(ContextCompat.getColor(c, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
                                    downvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                                    AnimateHelper.setFlashAnimation(rootView, upvotebutton, ContextCompat.getColor(c, R.color.md_orange_500));
                                    ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.BOLD);
                                    ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore() + 1));
                                    new Vote(true, points, c).execute(s);
                                    ActionStates.setVoteDirection(s, VoteDirection.UPVOTE);
                                } else {
                                    points.setTextColor(comments.getCurrentTextColor());
                                    new Vote(points, c).execute(s);
                                    ((TextView) rootView.findViewById(R.id.score)).setTypeface(null, Typeface.NORMAL);
                                    ((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.getDefault(), "%d", s.getScore()));
                                    ActionStates.setVoteDirection(s, VoteDirection.NO_VOTE);
                                    upvotebutton.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
                                }
                            }
                        });
                    }
                } else {
                    upvotebutton.setVisibility(View.GONE);
                    downvotebutton.setVisibility(View.GONE);
                }
            } catch (Exception ignored) {
                ignored.printStackTrace();
            }
        }
    }
}
Also used : Comment(net.dean.jraw.models.Comment) Vote(me.ccrama.redditslide.Vote) SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) ForegroundColorSpan(android.text.style.ForegroundColorSpan) AsyncTask(android.os.AsyncTask) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) RelativeSizeSpan(android.text.style.RelativeSizeSpan) ImageView(android.widget.ImageView) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) ApiException(net.dean.jraw.ApiException) RoundedBackgroundSpan(me.ccrama.redditslide.Views.RoundedBackgroundSpan) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) TextView(android.widget.TextView) AccountManager(net.dean.jraw.managers.AccountManager) ImageView(android.widget.ImageView) SpannableStringBuilder(android.text.SpannableStringBuilder) ApiException(net.dean.jraw.ApiException)

Example 7 with Comment

use of net.dean.jraw.models.Comment in project Slide by ccrama.

the class CommentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int old) {
    int pos = old != 0 ? old - 1 : old;
    if (firstHolder instanceof CommentViewHolder) {
        final CommentViewHolder holder = (CommentViewHolder) firstHolder;
        int datasetPosition = pos - 1;
        datasetPosition = getRealPosition(datasetPosition);
        if (pos > toShiftTo) {
            shifted = 0;
        }
        if (pos < shiftFrom) {
            shifted = 0;
        }
        final CommentNode baseNode = currentComments.get(datasetPosition).comment;
        final Comment comment = baseNode.getComment();
        if (pos == getItemCount() - 1) {
            holder.itemView.setPadding(0, 0, 0, (int) mContext.getResources().getDimension(R.dimen.overview_top_padding_single));
        } else {
            holder.itemView.setPadding(0, 0, 0, 0);
        }
        doScoreText(holder, comment, this);
        // Long click listeners
        View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (SettingValues.swap) {
                    doOnClick(holder, comment, baseNode);
                } else {
                    doLongClick(holder, comment, baseNode);
                }
                return true;
            }
        };
        holder.firstTextView.setOnLongClickListener(onLongClickListener);
        holder.commentOverflow.setOnLongClickListener(onLongClickListener);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                if (!currentlyEditingId.equals(comment.getFullName())) {
                    if (SettingValues.swap) {
                        doOnClick(holder, comment, baseNode);
                    } else {
                        doLongClick(holder, comment, baseNode);
                    }
                }
                return true;
            }
        });
        // Single click listeners
        OnSingleClickListener singleClick = new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                if (!currentlyEditingId.equals(comment.getFullName())) {
                    if (SettingValues.swap) {
                        doLongClick(holder, comment, baseNode);
                    } else {
                        doOnClick(holder, comment, baseNode);
                    }
                }
            }
        };
        holder.itemView.setOnClickListener(singleClick);
        holder.commentOverflow.setOnClickListener(singleClick);
        if (!toCollapse.contains(comment.getFullName()) && SettingValues.collapseComments || !SettingValues.collapseComments) {
            setViews(comment.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder, singleClick, onLongClickListener);
        }
        holder.firstTextView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                SpoilerRobotoTextView SpoilerRobotoTextView = (SpoilerRobotoTextView) v;
                if (SettingValues.swap) {
                    if (!SpoilerRobotoTextView.isSpoilerClicked()) {
                        doLongClick(holder, comment, baseNode);
                    } else if (SpoilerRobotoTextView.isSpoilerClicked()) {
                        SpoilerRobotoTextView.resetSpoilerClicked();
                    }
                } else if (!SpoilerRobotoTextView.isSpoilerClicked()) {
                    doOnClick(holder, comment, baseNode);
                } else if (SpoilerRobotoTextView.isSpoilerClicked()) {
                    SpoilerRobotoTextView.resetSpoilerClicked();
                }
            }
        });
        if (ImageFlairs.isSynced(comment.getSubredditName()) && comment.getAuthorFlair() != null && !comment.getAuthorFlair().getText().isEmpty() && !comment.getAuthorFlair().getCssClass().isEmpty()) {
            boolean set = false;
            for (String s : comment.getAuthorFlair().getCssClass().split(" ")) {
                File file = DiskCacheUtils.findInCache(comment.getSubredditName().toLowerCase(Locale.ENGLISH) + ":" + s.toLowerCase(Locale.ENGLISH), ImageFlairs.getFlairImageLoader(mContext).getInstance().getDiskCache());
                if (file != null && file.exists()) {
                    set = true;
                    holder.imageFlair.setVisibility(View.VISIBLE);
                    String decodedImgUri = Uri.fromFile(file).toString();
                    ImageFlairs.getFlairImageLoader(mContext).displayImage(decodedImgUri, holder.imageFlair);
                    break;
                }
            }
            if (!set) {
                holder.imageFlair.setImageDrawable(null);
                holder.imageFlair.setVisibility(View.GONE);
            }
        } else {
            holder.imageFlair.setVisibility(View.GONE);
        }
        // Set typeface for body
        int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, type);
        } else {
            typeface = Typeface.DEFAULT;
        }
        holder.firstTextView.setTypeface(typeface);
        // Show padding on top
        if (baseNode.isTopLevel()) {
            holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
        } else if (holder.itemView.findViewById(R.id.next).getVisibility() == View.VISIBLE) {
            holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
        }
        // Should be collapsed?
        if (hiddenPersons.contains(comment.getFullName()) || toCollapse.contains(comment.getFullName())) {
            int childnumber = getChildNumber(baseNode);
            if (hiddenPersons.contains(comment.getFullName()) && childnumber > 0) {
                holder.childrenNumber.setVisibility(View.VISIBLE);
                holder.childrenNumber.setText("+" + childnumber);
            } else {
                holder.childrenNumber.setVisibility(View.GONE);
            }
            if (SettingValues.collapseComments && toCollapse.contains(comment.getFullName())) {
                holder.firstTextView.setVisibility(View.GONE);
                holder.commentOverflow.setVisibility(View.GONE);
            }
        } else {
            holder.childrenNumber.setVisibility(View.GONE);
            holder.commentOverflow.setVisibility(View.VISIBLE);
        }
        holder.dot.setVisibility(View.VISIBLE);
        int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
        int width = 0;
        // Padding on the left, starting with the third comment
        for (int i = 2; i < baseNode.getDepth(); i++) {
            width += dwidth;
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(width, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
        RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) holder.dot.getLayoutParams();
        params2.width = dwidth;
        holder.dot.setLayoutParams(params2);
        if (baseNode.getDepth() - 1 > 0) {
            int i22 = baseNode.getDepth() - 2;
            String commentOp = dataSet.commentOPs.get(comment.getId());
            if (SettingValues.highlightCommentOP && commentOp != null && comment != null && commentOp.equals(comment.getAuthor())) {
                holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_purple_500));
            } else {
                if (i22 % 5 == 0) {
                    holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_700 : R.color.md_blue_500));
                } else if (i22 % 4 == 0) {
                    holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_600 : R.color.md_green_500));
                } else if (i22 % 3 == 0) {
                    holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_500 : R.color.md_yellow_500));
                } else if (i22 % 2 == 0) {
                    holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_400 : R.color.md_orange_500));
                } else {
                    holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_300 : R.color.md_red_500));
                }
            }
        } else {
            holder.dot.setVisibility(View.GONE);
        }
        if (currentSelectedItem != null && comment.getFullName().contains(currentSelectedItem) && !currentSelectedItem.isEmpty() && !currentlyEditingId.equals(comment.getFullName())) {
            doHighlighted(holder, comment, baseNode, false);
        } else if (!currentlyEditingId.equals(comment.getFullName())) {
            setCommentStateUnhighlighted(holder, baseNode, false);
        }
        if (deleted.contains(comment.getFullName())) {
            holder.firstTextView.setText(R.string.comment_deleted);
            holder.content.setText(R.string.comment_deleted);
        }
        if (currentlyEditingId.equals(comment.getFullName())) {
            setCommentStateUnhighlighted(holder, baseNode, false);
            setCommentStateHighlighted(holder, comment, baseNode, true, false);
        }
    } else if (firstHolder instanceof SubmissionViewHolder && submission != null) {
        submissionViewHolder = (SubmissionViewHolder) firstHolder;
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder((SubmissionViewHolder) firstHolder, submission, (Activity) mContext, true, true, null, listView, false, false, null, this);
        if (Authentication.isLoggedIn && Authentication.didOnline) {
            if (submission.isArchived() || submission.isLocked()) {
                firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
            } else {
                firstHolder.itemView.findViewById(R.id.reply).setOnClickListener(new OnSingleClickListener() {

                    @Override
                    public void onSingleClick(View v) {
                        doReplySubmission(firstHolder);
                    }
                });
                firstHolder.itemView.findViewById(R.id.discard).setOnClickListener(new OnSingleClickListener() {

                    @Override
                    public void onSingleClick(View v) {
                        firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
                        currentlyEditing = null;
                        editingPosition = -1;
                        if (SettingValues.fastscroll) {
                            mPage.fastScroll.setVisibility(View.VISIBLE);
                        }
                        if (mPage.fab != null)
                            mPage.fab.setVisibility(View.VISIBLE);
                        mPage.overrideFab = false;
                        currentlyEditingId = "";
                        backedText = "";
                        View view = ((Activity) mContext).getCurrentFocus();
                        if (view != null) {
                            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                        }
                    }
                });
            }
        } else {
            firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
            firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
        }
        firstHolder.itemView.findViewById(R.id.more).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                firstHolder.itemView.findViewById(R.id.menu).callOnClick();
            }
        });
    } else if (firstHolder instanceof MoreCommentViewHolder) {
        final MoreCommentViewHolder holder = (MoreCommentViewHolder) firstHolder;
        int nextPos = pos - 1;
        nextPos = getRealPosition(nextPos);
        final MoreChildItem baseNode = (MoreChildItem) currentComments.get(nextPos);
        if (baseNode.children.getCount() > 0) {
            try {
                holder.content.setText(mContext.getString(R.string.comment_load_more_string_new, baseNode.children.getLocalizedCount()));
            } catch (Exception e) {
                holder.content.setText(R.string.comment_load_more_number_unknown);
            }
        } else if (!baseNode.children.getChildrenIds().isEmpty()) {
            holder.content.setText(R.string.comment_load_more_number_unknown);
        } else {
            holder.content.setText(R.string.thread_continue);
        }
        int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
        int width = 0;
        for (int i = 1; i < baseNode.comment.getDepth(); i++) {
            width += dwidth;
        }
        final View progress = holder.loading;
        progress.setVisibility(View.GONE);
        final int finalNextPos = nextPos;
        holder.content.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                if (baseNode.children.getChildrenIds().isEmpty()) {
                    String toGoTo = "https://reddit.com" + submission.getPermalink() + baseNode.comment.getComment().getId() + "?context=0";
                    new OpenRedditLink(mContext, toGoTo, true);
                } else if (progress.getVisibility() == View.GONE) {
                    progress.setVisibility(View.VISIBLE);
                    holder.content.setText(R.string.comment_loading_more);
                    currentLoading = new AsyncLoadMore(getRealPosition(holder.getAdapterPosition() - 2), holder.getAdapterPosition(), holder, finalNextPos, baseNode.comment.getComment().getFullName());
                    currentLoading.execute(baseNode);
                }
            }
        });
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(width, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
    }
    if (firstHolder instanceof SpacerViewHolder) {
        // Make a space the size of the toolbar minus 1 so there isn't a gap
        firstHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (Constants.SINGLE_HEADER_VIEW_OFFSET - Reddit.dpToPxVertical(1) + mPage.shownHeaders)));
    }
}
Also used : OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) Activity(android.app.Activity) InputMethodManager(android.view.inputmethod.InputMethodManager) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Comment(net.dean.jraw.models.Comment) Typeface(android.graphics.Typeface) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CommentNode(net.dean.jraw.models.CommentNode) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ApiException(net.dean.jraw.ApiException) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) File(java.io.File) LinearLayout(android.widget.LinearLayout) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 8 with Comment

use of net.dean.jraw.models.Comment in project Slide by ccrama.

the class CommentAdapter method setCommentStateUnhighlighted.

public void setCommentStateUnhighlighted(final CommentViewHolder holder, final CommentNode baseNode, boolean animate) {
    if (animate) {
        collapseAndRemove(holder.menuArea);
    } else {
        resetMenu(holder.menuArea, true);
    }
    int color;
    Comment c = baseNode.getComment();
    if (lastSeen != 0 && lastSeen < c.getCreated().getTime() && !dataSet.single && SettingValues.commentLastVisit && !Authentication.name.equals(c.getAuthor())) {
        color = Palette.getColor(baseNode.getComment().getSubredditName());
        color = Color.argb(20, Color.red(color), Color.green(color), Color.blue(color));
    } else {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = mContext.getTheme();
        theme.resolveAttribute(R.attr.card_background, typedValue, true);
        color = typedValue.data;
    }
    int dwidth = (int) (3 * Resources.getSystem().getDisplayMetrics().density);
    int width = 0;
    // Padding on the left, starting with the third comment
    for (int i = 2; i < baseNode.getDepth(); i++) {
        width += dwidth;
    }
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
    params.setMargins(width, 0, 0, 0);
    holder.itemView.setLayoutParams(params);
    holder.itemView.findViewById(R.id.background).setBackgroundColor(color);
}
Also used : Comment(net.dean.jraw.models.Comment) RecyclerView(android.support.v7.widget.RecyclerView) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 9 with Comment

use of net.dean.jraw.models.Comment in project Slide by ccrama.

the class CommentAdapterHelper method showOverflowBottomSheet.

public static void showOverflowBottomSheet(final CommentAdapter adapter, final Context mContext, final CommentViewHolder holder, final CommentNode baseNode) {
    int[] attrs = new int[] { R.attr.tintColor };
    final Comment n = baseNode.getComment();
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
    Drawable saved = mContext.getResources().getDrawable(R.drawable.iconstarfilled);
    Drawable gild = mContext.getResources().getDrawable(R.drawable.gild);
    Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
    Drawable share = mContext.getResources().getDrawable(R.drawable.share);
    Drawable parent = mContext.getResources().getDrawable(R.drawable.commentchange);
    Drawable permalink = mContext.getResources().getDrawable(R.drawable.link);
    Drawable report = mContext.getResources().getDrawable(R.drawable.report);
    profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    saved.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    gild.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    share.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    parent.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    permalink.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    ta.recycle();
    BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(Html.fromHtml(n.getBody()));
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + n.getAuthor());
        String save = mContext.getString(R.string.btn_save);
        if (ActionStates.isSaved(n)) {
            save = mContext.getString(R.string.comment_unsave);
        }
        if (Authentication.isLoggedIn) {
            b.sheet(3, saved, save);
            b.sheet(16, report, mContext.getString(R.string.btn_report));
        }
    }
    b.sheet(5, gild, mContext.getString(R.string.comment_gild)).sheet(7, copy, mContext.getString(R.string.misc_copy_text)).sheet(23, permalink, mContext.getString(R.string.comment_permalink)).sheet(4, share, mContext.getString(R.string.comment_share));
    if (!adapter.currentBaseNode.isTopLevel()) {
        b.sheet(10, parent, mContext.getString(R.string.comment_parent));
    }
    b.listener(new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch(which) {
                case 1:
                    {
                        // Go to author
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, n.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 3:
                    // Save comment
                    saveComment(n, mContext, holder);
                    break;
                case 23:
                    {
                        // Go to comment permalink
                        String s = "https://reddit.com" + adapter.submission.getPermalink() + n.getFullName().substring(3, n.getFullName().length()) + "?context=3";
                        new OpenRedditLink(mContext, s);
                    }
                    break;
                case 5:
                    {
                        // Gild comment
                        Intent i = new Intent(mContext, Website.class);
                        i.putExtra(Website.EXTRA_URL, "https://reddit.com" + adapter.submission.getPermalink() + n.getFullName().substring(3, n.getFullName().length()) + "?context=3&inapp=false");
                        i.putExtra(Website.EXTRA_COLOR, Palette.getColor(n.getSubredditName()));
                        mContext.startActivity(i);
                    }
                    break;
                case 16:
                    // report
                    reportReason = "";
                    new MaterialDialog.Builder(mContext).input(mContext.getString(R.string.input_reason_for_report), null, true, new MaterialDialog.InputCallback() {

                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            reportReason = input.toString();
                        }
                    }).title(R.string.report_comment).alwaysCallInputCallback().inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES).positiveText(R.string.btn_report).negativeText(R.string.btn_cancel).onNegative(null).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            new AsyncReportTask(adapter.currentBaseNode, adapter.listView).execute();
                        }
                    }).show();
                    break;
                case 10:
                    // View comment parent
                    viewCommentParent(adapter, holder, mContext, baseNode);
                    break;
                case 7:
                    // Show select and copy text to clipboard
                    final TextView showText = new TextView(mContext);
                    showText.setText(StringEscapeUtils.unescapeHtml4(n.getBody()));
                    showText.setTextIsSelectable(true);
                    int sixteen = Reddit.dpToPxVertical(24);
                    showText.setPadding(sixteen, 0, sixteen, 0);
                    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                    builder.setView(showText).setTitle("Select text to copy").setCancelable(true).setPositiveButton("COPY", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                            ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Comment text", selected);
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton(R.string.btn_cancel, null).setNeutralButton("COPY ALL", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Comment text", Html.fromHtml(n.getBody()));
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                        }
                    }).show();
                    break;
                case 4:
                    // Share comment
                    Reddit.defaultShareText(adapter.submission.getTitle(), "https://reddit.com" + adapter.submission.getPermalink() + n.getFullName().substring(3, n.getFullName().length()) + "?context=3", mContext);
                    break;
            }
        }
    });
    b.show();
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) Activity(android.app.Activity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TypedArray(android.content.res.TypedArray) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) Comment(net.dean.jraw.models.Comment) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) DialogAction(com.afollestad.materialdialogs.DialogAction) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ClipData(android.content.ClipData) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 10 with Comment

use of net.dean.jraw.models.Comment in project Slide by ccrama.

the class CommentAdapterSearch method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int pos) {
    final CommentViewHolder holder = (CommentViewHolder) firstHolder;
    final CommentNode baseNode = dataSet.get(pos);
    final Comment comment = baseNode.getComment();
    doScoreText(holder, comment, 0);
    if (baseNode.isTopLevel()) {
        holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
    } else {
        holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
    }
    String body = comment.getDataNode().get("body_html").asText();
    if (!search.isEmpty() && StringUtils.isAlphanumericSpace(search)) {
        body = body.replaceAll(search, "[[h[" + search + "]h]]");
    }
    int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
    Typeface typeface;
    if (type >= 0) {
        typeface = RobotoTypefaces.obtainTypeface(mContext, type);
    } else {
        typeface = Typeface.DEFAULT;
    }
    holder.firstTextView.setTypeface(typeface);
    setViews(body, comment.getSubredditName(), holder);
    holder.childrenNumber.setVisibility(View.GONE);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle conData = new Bundle();
            conData.putString("fullname", comment.getFullName());
            Intent intent = new Intent();
            intent.putExtras(conData);
            ((Activity) mContext).setResult(Activity.RESULT_OK, intent);
            ((Activity) mContext).finish();
        }
    });
    holder.firstTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle conData = new Bundle();
            conData.putString("fullname", comment.getFullName());
            Intent intent = new Intent();
            intent.putExtras(conData);
            ((Activity) mContext).setResult(Activity.RESULT_OK, intent);
            ((Activity) mContext).finish();
        }
    });
    holder.itemView.findViewById(R.id.dot).setVisibility(View.VISIBLE);
    if (baseNode.getDepth() - 1 > 0) {
        View v = holder.itemView.findViewById(R.id.dot);
        int i22 = baseNode.getDepth() - 2;
        if (i22 % 5 == 0) {
            holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
        } else if (i22 % 4 == 0) {
            holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_green_500));
        } else if (i22 % 3 == 0) {
            holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_yellow_500));
        } else if (i22 % 2 == 0) {
            holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
        } else {
            holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_red_500));
        }
    } else {
        holder.itemView.findViewById(R.id.dot).setVisibility(View.GONE);
    }
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) Comment(net.dean.jraw.models.Comment) Typeface(android.graphics.Typeface) Bundle(android.os.Bundle) CommentNode(net.dean.jraw.models.CommentNode) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

Comment (net.dean.jraw.models.Comment)11 View (android.view.View)9 RecyclerView (android.support.v7.widget.RecyclerView)7 TextView (android.widget.TextView)7 ImageView (android.widget.ImageView)6 OpenRedditLink (me.ccrama.redditslide.OpenRedditLink)6 SpannableStringBuilder (android.text.SpannableStringBuilder)5 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)5 Activity (android.app.Activity)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 LayoutInflater (android.view.LayoutInflater)4 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)4 ApiException (net.dean.jraw.ApiException)4 TypedArray (android.content.res.TypedArray)3 Typeface (android.graphics.Typeface)3 ForegroundColorSpan (android.text.style.ForegroundColorSpan)3 LinearLayout (android.widget.LinearLayout)3 BottomSheet (com.cocosw.bottomsheet.BottomSheet)3 SlidingUpPanelLayout (com.sothree.slidinguppanel.SlidingUpPanelLayout)3