Search in sources :

Example 1 with Vote

use of me.ccrama.redditslide.Vote in project Slide by ccrama.

the class CommentAdapter method setCommentStateHighlighted.

public void setCommentStateHighlighted(final CommentViewHolder holder, final Comment n, final CommentNode baseNode, boolean isReplying, boolean animate) {
    if (currentlySelected != null && currentlySelected != holder) {
        setCommentStateUnhighlighted(currentlySelected, currentBaseNode, true);
    }
    if (mContext instanceof BaseActivity) {
        ((BaseActivity) mContext).setShareUrl("https://reddit.com" + submission.getPermalink() + n.getFullName() + "?context=3");
    }
    // and expand to show all children comments
    if (SettingValues.swap && holder.firstTextView.getVisibility() == View.GONE && !isReplying) {
        hiddenPersons.remove(n.getFullName());
        unhideAll(baseNode, holder.getAdapterPosition() + 1);
        if (toCollapse.contains(n.getFullName()) && SettingValues.collapseComments) {
            setViews(n.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder);
        }
        CommentAdapterHelper.hideChildrenObject(holder.childrenNumber);
        holder.commentOverflow.setVisibility(View.VISIBLE);
        toCollapse.remove(n.getFullName());
    } else {
        currentlySelected = holder;
        currentBaseNode = baseNode;
        int color = Palette.getColor(n.getSubredditName());
        currentSelectedItem = n.getFullName();
        currentNode = baseNode;
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        resetMenu(holder.menuArea, false);
        final View baseView = (SettingValues.rightHandedCommentMenu) ? inflater.inflate(R.layout.comment_menu_right_handed, holder.menuArea) : inflater.inflate(R.layout.comment_menu, holder.menuArea);
        if (!isReplying) {
            baseView.setVisibility(View.GONE);
            if (animate) {
                expand(baseView);
            } else {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                ViewGroup.LayoutParams layoutParams = baseView.getLayoutParams();
                layoutParams.height = baseView.getMeasuredHeight() - l2.getMeasuredHeight();
                baseView.setLayoutParams(layoutParams);
            }
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
        params.setMargins(0, 0, 0, 0);
        holder.itemView.setLayoutParams(params);
        View reply = baseView.findViewById(R.id.reply);
        View send = baseView.findViewById(R.id.send);
        final View menu = baseView.findViewById(R.id.menu);
        final View replyArea = baseView.findViewById(R.id.replyArea);
        final View more = baseView.findViewById(R.id.more);
        final ImageView upvote = (ImageView) baseView.findViewById(R.id.upvote);
        final ImageView downvote = (ImageView) baseView.findViewById(R.id.downvote);
        View discard = baseView.findViewById(R.id.discard);
        final EditText replyLine = (EditText) baseView.findViewById(R.id.replyLine);
        final Comment comment = baseNode.getComment();
        if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
            upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
        } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
            downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
        } else {
            downvote.clearColorFilter();
            upvote.clearColorFilter();
        }
        {
            final ImageView mod = (ImageView) baseView.findViewById(R.id.mod);
            try {
                if (UserSubscriptions.modOf.contains(submission.getSubredditName())) {
                    // todo
                    mod.setVisibility(View.GONE);
                } else {
                    mod.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                Log.d(LogUtil.getTag(), "Error loading mod " + e.toString());
            }
        }
        if (UserSubscriptions.modOf != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
            baseView.findViewById(R.id.mod).setVisibility(View.VISIBLE);
            final Map<String, Integer> reports = comment.getUserReports();
            final Map<String, String> reports2 = comment.getModeratorReports();
            if (reports.size() + reports2.size() > 0) {
                ((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
            } else {
                ((ImageView) baseView.findViewById(R.id.mod)).setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
            }
            baseView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.showModBottomSheet(CommentAdapter.this, mContext, baseNode, comment, holder, reports, reports2);
                }
            });
        } else {
            baseView.findViewById(R.id.mod).setVisibility(View.GONE);
        }
        final ImageView edit = (ImageView) baseView.findViewById(R.id.edit);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            edit.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.doCommentEdit(CommentAdapter.this, mContext, fm, baseNode, baseNode.isTopLevel() ? submission.getSelftext() : baseNode.getParent().getComment().getBody(), holder);
                }
            });
        } else {
            edit.setVisibility(View.GONE);
        }
        final ImageView delete = (ImageView) baseView.findViewById(R.id.delete);
        if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(comment.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
            delete.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    CommentAdapterHelper.deleteComment(CommentAdapter.this, mContext, baseNode, holder);
                }
            });
        } else {
            delete.setVisibility(View.GONE);
        }
        if (Authentication.isLoggedIn && !submission.isArchived() && !submission.isLocked() && !deleted.contains(n.getFullName()) && !comment.getAuthor().equals("[deleted]") && Authentication.didOnline) {
            if (isReplying) {
                baseView.setVisibility(View.VISIBLE);
                final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                baseView.measure(widthSpec, heightSpec);
                View l2 = baseView.findViewById(R.id.replyArea) == null ? baseView.findViewById(R.id.innerSend) : baseView.findViewById(R.id.replyArea);
                final int widthSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                final int heightSpec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                l2.measure(widthSpec2, heightSpec2);
                RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) baseView.getLayoutParams();
                params2.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
                params2.addRule(RelativeLayout.BELOW, R.id.commentOverflow);
                baseView.setLayoutParams(params2);
                replyArea.setVisibility(View.VISIBLE);
                menu.setVisibility(View.GONE);
                currentlyEditing = replyLine;
                currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            mPage.fastScroll.setVisibility(View.GONE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.GONE);
                            }
                            mPage.overrideFab = true;
                        } else if (SettingValues.fastscroll) {
                            mPage.fastScroll.setVisibility(View.VISIBLE);
                            if (mPage.fab != null) {
                                mPage.fab.setVisibility(View.VISIBLE);
                            }
                            mPage.overrideFab = false;
                        }
                    }
                });
                final TextView profile = (TextView) baseView.findViewById(R.id.profile);
                changedProfile = Authentication.name;
                profile.setText("/u/" + changedProfile);
                profile.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final HashMap<String, String> accounts = new HashMap<>();
                        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                            if (s.contains(":")) {
                                accounts.put(s.split(":")[0], s.split(":")[1]);
                            } else {
                                accounts.put(s, "");
                            }
                        }
                        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                        final int i = keys.indexOf(changedProfile);
                        AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                        builder.setTitle(R.string.sorting_choose);
                        builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                changedProfile = keys.get(which);
                                profile.setText("/u/" + changedProfile);
                            }
                        });
                        builder.alwaysCallSingleChoiceCallback();
                        builder.setNegativeButton(R.string.btn_cancel, null);
                        builder.show();
                    }
                });
                replyLine.requestFocus();
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                currentlyEditingId = n.getFullName();
                replyLine.setText(backedText);
                replyLine.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        backedText = s.toString();
                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                    }
                });
                editingPosition = holder.getAdapterPosition();
            }
            reply.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    expandAndSetParams(baseView);
                    // If the base theme is Light or Sepia, tint the Editor actions to be white
                    if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
                        ((ImageView) replyArea.findViewById(R.id.savedraft)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.draft)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.imagerep)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.link)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.bold)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.italics)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.bulletlist)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.numlist)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.draw)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.quote)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.size)).setColorFilter(Color.WHITE);
                        ((ImageView) replyArea.findViewById(R.id.strike)).setColorFilter(Color.WHITE);
                        ((TextView) replyArea.findViewById(R.id.author)).setTextColor(Color.WHITE);
                        replyLine.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
                    }
                    replyArea.setVisibility(View.VISIBLE);
                    menu.setVisibility(View.GONE);
                    currentlyEditing = replyLine;
                    DoEditorActions.doActions(currentlyEditing, replyArea, fm, (Activity) mContext, comment.getBody(), getParents(baseNode));
                    currentlyEditing.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus) {
                                mPage.fastScroll.setVisibility(View.GONE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.GONE);
                                mPage.overrideFab = true;
                            } else if (SettingValues.fastscroll) {
                                mPage.fastScroll.setVisibility(View.VISIBLE);
                                if (mPage.fab != null)
                                    mPage.fab.setVisibility(View.VISIBLE);
                                mPage.overrideFab = false;
                            }
                        }
                    });
                    final TextView profile = (TextView) baseView.findViewById(R.id.profile);
                    changedProfile = Authentication.name;
                    profile.setText("/u/" + changedProfile);
                    profile.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            final HashMap<String, String> accounts = new HashMap<>();
                            for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
                                if (s.contains(":")) {
                                    accounts.put(s.split(":")[0], s.split(":")[1]);
                                } else {
                                    accounts.put(s, "");
                                }
                            }
                            final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
                            final int i = keys.indexOf(changedProfile);
                            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                            builder.setTitle(R.string.sorting_choose);
                            builder.setSingleChoiceItems(keys.toArray(new String[keys.size()]), i, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    changedProfile = keys.get(which);
                                    profile.setText("/u/" + changedProfile);
                                }
                            });
                            builder.alwaysCallSingleChoiceCallback();
                            builder.setNegativeButton(R.string.btn_cancel, null);
                            builder.show();
                        }
                    });
                    replyLine.requestFocus();
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    currentlyEditingId = n.getFullName();
                    replyLine.addTextChangedListener(new TextWatcher() {

                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            backedText = s.toString();
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                        }
                    });
                    editingPosition = holder.getAdapterPosition();
                }
            });
            send.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditingId = "";
                    backedText = "";
                    doShowMenu(baseView);
                    if (SettingValues.fastscroll) {
                        mPage.fastScroll.setVisibility(View.VISIBLE);
                        if (mPage.fab != null)
                            mPage.fab.setVisibility(View.VISIBLE);
                        mPage.overrideFab = false;
                    }
                    dataSet.refreshLayout.setRefreshing(true);
                    if (currentlyEditing != null) {
                        String text = currentlyEditing.getText().toString();
                        new ReplyTaskComment(n, baseNode, holder, changedProfile).execute(text);
                        currentlyEditing = null;
                        editingPosition = -1;
                    }
                    // Hide soft keyboard
                    View view = ((Activity) mContext).getCurrentFocus();
                    if (view != null) {
                        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }
                }
            });
            discard.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    currentlyEditing = null;
                    editingPosition = -1;
                    currentlyEditingId = "";
                    backedText = "";
                    mPage.overrideFab = false;
                    View view = ((Activity) mContext).getCurrentFocus();
                    if (view != null) {
                        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }
                    doShowMenu(baseView);
                }
            });
        } else {
            if (reply.getVisibility() == View.VISIBLE) {
                reply.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && upvote.getVisibility() == View.VISIBLE) {
                upvote.setVisibility(View.GONE);
            }
            if ((submission.isArchived() || deleted.contains(n.getFullName()) || comment.getAuthor().equals("[deleted]")) && Authentication.isLoggedIn && Authentication.didOnline && downvote.getVisibility() == View.VISIBLE) {
                downvote.setVisibility(View.GONE);
            }
        }
        more.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                CommentAdapterHelper.showOverflowBottomSheet(CommentAdapter.this, mContext, holder, baseNode);
            }
        });
        upvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    upvote.clearColorFilter();
                } else {
                    new Vote(true, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.UPVOTE);
                    // reset colour
                    downvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    upvote.setColorFilter(holder.textColorUp, PorterDuff.Mode.MULTIPLY);
                }
            }
        });
        downvote.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                setCommentStateUnhighlighted(holder, comment, baseNode, true);
                if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                    new Vote(v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.NO_VOTE);
                    doScoreText(holder, n, CommentAdapter.this);
                    downvote.clearColorFilter();
                } else {
                    new Vote(false, v, mContext).execute(n);
                    ActionStates.setVoteDirection(comment, VoteDirection.DOWNVOTE);
                    // reset colour
                    upvote.clearColorFilter();
                    doScoreText(holder, n, CommentAdapter.this);
                    downvote.setColorFilter(holder.textColorDown, PorterDuff.Mode.MULTIPLY);
                }
            }
        });
        menu.setBackgroundColor(color);
        replyArea.setBackgroundColor(color);
        if (!isReplying) {
            menu.setVisibility(View.VISIBLE);
            replyArea.setVisibility(View.GONE);
        }
        holder.itemView.findViewById(R.id.background).setBackgroundColor(Color.argb(50, Color.red(color), Color.green(color), Color.blue(color)));
    }
}
Also used : HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) Activity(android.app.Activity) InputMethodManager(android.view.inputmethod.InputMethodManager) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HashSet(java.util.HashSet) EditText(android.widget.EditText) Comment(net.dean.jraw.models.Comment) Vote(me.ccrama.redditslide.Vote) ViewGroup(android.view.ViewGroup) 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) LayoutInflater(android.view.LayoutInflater) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with Vote

use of me.ccrama.redditslide.Vote 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 3 with Vote

use of me.ccrama.redditslide.Vote in project Slide by ccrama.

the class PopulateShadowboxInfo method doActionbar.

public static void doActionbar(final Submission s, final View rootView, final Activity c, boolean extras) {
    TextView title = (TextView) 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]";
        title.setText(Html.fromHtml(s.getTitle()));
        String spacer = c.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        SpannableStringBuilder subreddit = new SpannableStringBuilder(" /r/" + s.getSubredditName() + " ");
        String subname = s.getSubredditName().toLowerCase(Locale.ENGLISH);
        if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
            subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        titleString.append(subreddit);
        titleString.append(distingush);
        titleString.append(spacer);
        titleString.append(TimeUtils.getTimeAgo(s.getCreated().getTime(), c));
        desc.setText(titleString);
        ((TextView) rootView.findViewById(R.id.comments)).setText(String.format(Locale.getDefault(), "%d", s.getCommentCount()));
        ((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() || s.isLocked()) {
                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 (SettingValues.storeHistory) {
                                    if (!s.isNsfw() || SettingValues.storeNSFWHistory) {
                                        HasSeen.addSeen(s.getFullName());
                                    }
                                }
                                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 (SettingValues.storeHistory) {
                                    if (!s.isNsfw() || SettingValues.storeNSFWHistory) {
                                        HasSeen.addSeen(s.getFullName());
                                    }
                                }
                                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();
            }
            rootView.findViewById(R.id.menu).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    showBottomSheet(c, s, rootView);
                }
            });
        }
    }
}
Also used : Vote(me.ccrama.redditslide.Vote) SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) ForegroundColorSpan(android.text.style.ForegroundColorSpan) AsyncTask(android.os.AsyncTask) 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) StyleSpan(android.text.style.StyleSpan) 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 4 with Vote

use of me.ccrama.redditslide.Vote in project Slide by ccrama.

the class PopulateSubmissionViewHolder method populateSubmissionViewHolder.

public <T extends Contribution> void populateSubmissionViewHolder(final SubmissionViewHolder holder, final Submission submission, final Activity mContext, boolean fullscreen, final boolean full, final List<T> posts, final RecyclerView recyclerview, final boolean same, final boolean offline, final String baseSub, @Nullable final CommentAdapter adapter) {
    holder.itemView.findViewById(R.id.vote).setVisibility(View.GONE);
    if (!offline && UserSubscriptions.modOf != null && submission.getSubredditName() != null && UserSubscriptions.modOf.contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH))) {
        holder.mod.setVisibility(View.VISIBLE);
        final Map<String, Integer> reports = submission.getUserReports();
        final Map<String, String> reports2 = submission.getModeratorReports();
        if (reports.size() + reports2.size() > 0) {
            ((ImageView) holder.mod).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
        } else {
            ((ImageView) holder.mod).setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
        }
        holder.mod.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showModBottomSheet(mContext, submission, posts, holder, recyclerview, reports, reports2);
            }
        });
    } else {
        holder.mod.setVisibility(View.GONE);
    }
    holder.menu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            showBottomSheet(mContext, submission, holder, posts, baseSub, recyclerview, full);
        }
    });
    // Use this to offset the submission score
    int submissionScore = submission.getScore();
    final int commentCount = submission.getCommentCount();
    final int more = LastComments.commentsSince(submission);
    holder.comments.setText(String.format(Locale.getDefault(), "%d %s", commentCount, ((more > 0 && SettingValues.commentLastVisit) ? "(+" + more + ")" : "")));
    String scoreRatio = (SettingValues.upvotePercentage && full && submission.getUpvoteRatio() != null) ? "(" + (int) (submission.getUpvoteRatio() * 100) + "%)" : "";
    if (!scoreRatio.isEmpty()) {
        TextView percent = holder.itemView.findViewById(R.id.percent);
        percent.setVisibility(View.VISIBLE);
        percent.setText(scoreRatio);
        final double numb = (submission.getUpvoteRatio());
        if (numb <= .5) {
            if (numb <= .1) {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
            } else if (numb <= .3) {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_400));
            } else {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_300));
            }
        } else {
            if (numb >= .9) {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
            } else if (numb >= .7) {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_400));
            } else {
                percent.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_300));
            }
        }
    }
    final ImageView downvotebutton = (ImageView) holder.downvote;
    final ImageView upvotebutton = (ImageView) holder.upvote;
    if (submission.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);
        }
    }
    // Set the colors and styles for the score text depending on what state it is in
    switch(ActionStates.getVoteDirection(submission)) {
        case UPVOTE:
            {
                holder.score.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
                upvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
                holder.score.setTypeface(null, Typeface.BOLD);
                downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                if (submission.getVote() != VoteDirection.UPVOTE) {
                    if (submission.getVote() == VoteDirection.DOWNVOTE)
                        ++submissionScore;
                    // offset the score by +1
                    ++submissionScore;
                }
                break;
            }
        case DOWNVOTE:
            {
                holder.score.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
                downvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
                holder.score.setTypeface(null, Typeface.BOLD);
                upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                if (submission.getVote() != VoteDirection.DOWNVOTE) {
                    if (submission.getVote() == VoteDirection.UPVOTE)
                        --submissionScore;
                    // offset the score by +1
                    --submissionScore;
                }
                break;
            }
        case NO_VOTE:
            {
                holder.score.setTextColor(holder.comments.getCurrentTextColor());
                holder.score.setTypeface(null, Typeface.NORMAL);
                downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                break;
            }
    }
    // if the submission is already at 0pts, keep it at 0pts
    submissionScore = ((submissionScore < 0) ? 0 : submissionScore);
    if (submissionScore >= 10000 && SettingValues.abbreviateScores) {
        holder.score.setText(String.format(Locale.getDefault(), "%.1fk", (((double) submissionScore) / 1000)));
    } else {
        holder.score.setText(String.format(Locale.getDefault(), "%d", submissionScore));
    }
    // Save the score so we can use it in the OnClickListeners for the vote buttons
    final int SUBMISSION_SCORE = submissionScore;
    final ImageView hideButton = (ImageView) holder.hide;
    if (hideButton != null) {
        if (SettingValues.hideButton && Authentication.isLoggedIn) {
            hideButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    hideSubmission(submission, posts, baseSub, recyclerview, mContext);
                }
            });
        } else {
            hideButton.setVisibility(View.GONE);
        }
    }
    if (Authentication.isLoggedIn && Authentication.didOnline) {
        if (ActionStates.isSaved(submission)) {
            ((ImageView) holder.save).setColorFilter(ContextCompat.getColor(mContext, R.color.md_amber_500), PorterDuff.Mode.SRC_ATOP);
        } else {
            ((ImageView) holder.save).setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
        }
        holder.save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                saveSubmission(submission, mContext, holder, full);
            }
        });
    }
    if (!SettingValues.saveButton && !full || !Authentication.isLoggedIn || !Authentication.didOnline) {
        holder.save.setVisibility(View.GONE);
    }
    ImageView thumbImage2 = ((ImageView) holder.thumbimage);
    if (holder.leadImage.thumbImage2 == null) {
        holder.leadImage.setThumbnail(thumbImage2);
    }
    final ContentType.Type type = ContentType.getContentType(submission);
    addClickFunctions(holder.leadImage, type, mContext, submission, holder, full);
    if (thumbImage2 != null) {
        addClickFunctions(thumbImage2, type, mContext, submission, holder, full);
    }
    if (full) {
        addClickFunctions(holder.itemView.findViewById(R.id.wraparea), type, mContext, submission, holder, full);
    }
    if (full) {
        holder.leadImage.setWrapArea(holder.itemView.findViewById(R.id.wraparea));
    }
    boolean crosspost = submission.getDataNode().has("crosspost_parent_list");
    if (full && crosspost) {
        holder.itemView.findViewById(R.id.crosspost).setVisibility(View.VISIBLE);
        ((TextView) holder.itemView.findViewById(R.id.crossinfo)).setText(SubmissionCache.getCrosspostLine(submission, mContext));
        ((Reddit) mContext.getApplicationContext()).getImageLoader().displayImage(submission.getDataNode().get("crosspost_parent_list").get(0).get("thumbnail").asText(), ((ImageView) holder.itemView.findViewById(R.id.crossthumb)));
        holder.itemView.findViewById(R.id.crosspost).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                OpenRedditLink.openUrl(mContext, submission.getDataNode().get("crosspost_parent_list").get(0).get("permalink").asText(), true);
            }
        });
    }
    holder.leadImage.setSubmission(submission, full, baseSub, type);
    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (offline) {
                Snackbar s = Snackbar.make(holder.itemView, mContext.getString(R.string.offline_msg), Snackbar.LENGTH_SHORT);
                View view = s.getView();
                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                tv.setTextColor(Color.WHITE);
                s.show();
            } else {
                if (SettingValues.actionbarTap && !full) {
                    CreateCardView.toggleActionbar(holder.itemView);
                } else {
                    holder.itemView.findViewById(R.id.menu).callOnClick();
                }
            }
            return true;
        }
    });
    doText(holder, submission, mContext, baseSub, full);
    if (!full && SettingValues.isSelftextEnabled(baseSub) && submission.isSelfPost() && !submission.getSelftext().isEmpty() && !submission.isNsfw() && !submission.getDataNode().get("spoiler").asBoolean() && !submission.getDataNode().get("selftext_html").asText().trim().isEmpty()) {
        holder.body.setVisibility(View.VISIBLE);
        String text = submission.getDataNode().get("selftext_html").asText();
        int typef = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (typef >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, typef);
        } else {
            typeface = Typeface.DEFAULT;
        }
        holder.body.setTypeface(typeface);
        holder.body.setTextHtml(Html.fromHtml(text.substring(0, text.contains("\n") ? text.indexOf("\n") : text.length())).toString().replace("<sup>", "<sup><small>").replace("</sup>", "</small></sup>"), "none ");
        holder.body.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                holder.itemView.callOnClick();
            }
        });
        holder.body.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                holder.menu.callOnClick();
                return true;
            }
        });
    } else if (!full) {
        holder.body.setVisibility(View.GONE);
    }
    if (full) {
        if (!submission.getSelftext().isEmpty()) {
            int typef = new FontPreferences(mContext).getFontTypeComment().getTypeface();
            Typeface typeface;
            if (typef >= 0) {
                typeface = RobotoTypefaces.obtainTypeface(mContext, typef);
            } else {
                typeface = Typeface.DEFAULT;
            }
            holder.firstTextView.setTypeface(typeface);
            setViews(submission.getDataNode().get("selftext_html").asText(), submission.getSubredditName() == null ? "all" : submission.getSubredditName(), holder);
            holder.itemView.findViewById(R.id.body_area).setVisibility(View.VISIBLE);
        } else {
            holder.itemView.findViewById(R.id.body_area).setVisibility(View.GONE);
        }
    }
    try {
        final TextView points = holder.score;
        final TextView comments = holder.comments;
        if (Authentication.isLoggedIn && !offline && Authentication.didOnline) {
            {
                downvotebutton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (SettingValues.storeHistory && !full) {
                            if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
                                HasSeen.addSeen(submission.getFullName());
                                if (mContext instanceof MainActivity) {
                                    holder.title.setAlpha(0.54f);
                                    holder.body.setAlpha(0.54f);
                                }
                            }
                        }
                        if (ActionStates.getVoteDirection(submission) != VoteDirection.DOWNVOTE) {
                            // has not been downvoted
                            points.setTextColor(ContextCompat.getColor(mContext, R.color.md_blue_500));
                            downvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_blue_500), PorterDuff.Mode.SRC_ATOP);
                            upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                            AnimateHelper.setFlashAnimation(holder.itemView, downvotebutton, ContextCompat.getColor(mContext, R.color.md_blue_500));
                            holder.score.setTypeface(null, Typeface.BOLD);
                            final int DOWNVOTE_SCORE = (SUBMISSION_SCORE == 0) ? 0 : SUBMISSION_SCORE - // if a post is at 0 votes, keep it at 0 when downvoting
                            1;
                            new Vote(false, points, mContext).execute(submission);
                            ActionStates.setVoteDirection(submission, VoteDirection.DOWNVOTE);
                            setSubmissionScoreText(submission, holder);
                        } else {
                            // un-downvoted a post
                            points.setTextColor(comments.getCurrentTextColor());
                            new Vote(points, mContext).execute(submission);
                            holder.score.setTypeface(null, Typeface.NORMAL);
                            ActionStates.setVoteDirection(submission, VoteDirection.NO_VOTE);
                            downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                            setSubmissionScoreText(submission, holder);
                        }
                        if (!full && !SettingValues.actionbarVisible && SettingValues.defaultCardView != CreateCardView.CardEnum.DESKTOP) {
                            CreateCardView.toggleActionbar(holder.itemView);
                        }
                    }
                });
            }
            {
                upvotebutton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (SettingValues.storeHistory && !full) {
                            if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
                                HasSeen.addSeen(submission.getFullName());
                                if (mContext instanceof MainActivity) {
                                    holder.title.setAlpha(0.54f);
                                    holder.body.setAlpha(0.54f);
                                }
                            }
                        }
                        if (ActionStates.getVoteDirection(submission) != VoteDirection.UPVOTE) {
                            // has not been upvoted
                            points.setTextColor(ContextCompat.getColor(mContext, R.color.md_orange_500));
                            upvotebutton.setColorFilter(ContextCompat.getColor(mContext, R.color.md_orange_500), PorterDuff.Mode.SRC_ATOP);
                            downvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                            AnimateHelper.setFlashAnimation(holder.itemView, upvotebutton, ContextCompat.getColor(mContext, R.color.md_orange_500));
                            holder.score.setTypeface(null, Typeface.BOLD);
                            new Vote(true, points, mContext).execute(submission);
                            ActionStates.setVoteDirection(submission, VoteDirection.UPVOTE);
                            setSubmissionScoreText(submission, holder);
                        } else {
                            // un-upvoted a post
                            points.setTextColor(comments.getCurrentTextColor());
                            new Vote(points, mContext).execute(submission);
                            holder.score.setTypeface(null, Typeface.NORMAL);
                            ActionStates.setVoteDirection(submission, VoteDirection.NO_VOTE);
                            upvotebutton.setColorFilter((((holder.itemView.getTag(holder.itemView.getId())) != null && holder.itemView.getTag(holder.itemView.getId()).equals("none") || full)) ? getCurrentTintColor(mContext) : getWhiteTintColor(), PorterDuff.Mode.SRC_ATOP);
                            setSubmissionScoreText(submission, holder);
                        }
                        if (!full && !SettingValues.actionbarVisible && SettingValues.defaultCardView != CreateCardView.CardEnum.DESKTOP) {
                            CreateCardView.toggleActionbar(holder.itemView);
                        }
                    }
                });
            }
        } else {
            upvotebutton.setVisibility(View.GONE);
            downvotebutton.setVisibility(View.GONE);
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    final View edit = holder.edit;
    if (Authentication.name != null && Authentication.name.toLowerCase(Locale.ENGLISH).equals(submission.getAuthor().toLowerCase(Locale.ENGLISH)) && Authentication.didOnline) {
        edit.setVisibility(View.VISIBLE);
        edit.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                new AsyncTask<Void, Void, ArrayList<String>>() {

                    List<FlairTemplate> flairlist;

                    @Override
                    protected ArrayList<String> doInBackground(Void... params) {
                        FlairReference allFlairs = new FluentRedditClient(Authentication.reddit).subreddit(submission.getSubredditName()).flair();
                        try {
                            flairlist = allFlairs.options(submission);
                            final ArrayList<String> finalFlairs = new ArrayList<>();
                            for (FlairTemplate temp : flairlist) {
                                finalFlairs.add(temp.getText());
                            }
                            return finalFlairs;
                        } catch (Exception e) {
                            e.printStackTrace();
                        // sub probably has no flairs?
                        }
                        return null;
                    }

                    @Override
                    public void onPostExecute(final ArrayList<String> data) {
                        final boolean flair = (data != null && !data.isEmpty());
                        int[] attrs = new int[] { R.attr.tintColor };
                        TypedArray ta = mContext.obtainStyledAttributes(attrs);
                        final int color2 = ta.getColor(0, Color.WHITE);
                        Drawable edit_drawable = mContext.getResources().getDrawable(R.drawable.edit);
                        Drawable nsfw_drawable = mContext.getResources().getDrawable(R.drawable.hide);
                        Drawable delete_drawable = mContext.getResources().getDrawable(R.drawable.delete);
                        Drawable flair_drawable = mContext.getResources().getDrawable(R.drawable.fontsizedarker);
                        edit_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
                        nsfw_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
                        delete_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
                        flair_drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP);
                        ta.recycle();
                        BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
                        if (submission.isSelfPost()) {
                            b.sheet(1, edit_drawable, mContext.getString(R.string.edit_selftext));
                        }
                        if (submission.isNsfw()) {
                            b.sheet(4, nsfw_drawable, mContext.getString(R.string.mod_btn_unmark_nsfw));
                        } else {
                            b.sheet(4, nsfw_drawable, mContext.getString(R.string.mod_btn_mark_nsfw));
                        }
                        b.sheet(2, delete_drawable, mContext.getString(R.string.delete_submission));
                        if (flair) {
                            b.sheet(3, flair_drawable, mContext.getString(R.string.set_submission_flair));
                        }
                        b.listener(new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                switch(which) {
                                    case 1:
                                        {
                                            LayoutInflater inflater = mContext.getLayoutInflater();
                                            final View dialoglayout = inflater.inflate(R.layout.edit_comment, null);
                                            final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                                            final EditText e = dialoglayout.findViewById(R.id.entry);
                                            e.setText(StringEscapeUtils.unescapeHtml4(submission.getSelftext()));
                                            DoEditorActions.doActions(e, dialoglayout, ((AppCompatActivity) mContext).getSupportFragmentManager(), mContext, null, null);
                                            builder.setCancelable(false).setView(dialoglayout);
                                            final Dialog d = builder.create();
                                            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                                            d.show();
                                            dialoglayout.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

                                                @Override
                                                public void onClick(View v) {
                                                    d.dismiss();
                                                }
                                            });
                                            dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {

                                                @Override
                                                public void onClick(View v) {
                                                    final String text = e.getText().toString();
                                                    new AsyncTask<Void, Void, Void>() {

                                                        @Override
                                                        protected Void doInBackground(Void... params) {
                                                            try {
                                                                new AccountManager(Authentication.reddit).updateContribution(submission, text);
                                                                if (adapter != null) {
                                                                    adapter.dataSet.reloadSubmission(adapter);
                                                                }
                                                                d.dismiss();
                                                            } catch (Exception e) {
                                                                (mContext).runOnUiThread(new Runnable() {

                                                                    @Override
                                                                    public void run() {
                                                                        new AlertDialogWrapper.Builder(mContext).setTitle(R.string.comment_delete_err).setMessage(R.string.comment_delete_err_msg).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                                                                            @Override
                                                                            public void onClick(DialogInterface dialog, int which) {
                                                                                dialog.dismiss();
                                                                                doInBackground();
                                                                            }
                                                                        }).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {

                                                                            @Override
                                                                            public void onClick(DialogInterface dialog, int which) {
                                                                                dialog.dismiss();
                                                                            }
                                                                        }).show();
                                                                    }
                                                                });
                                                            }
                                                            return null;
                                                        }

                                                        @Override
                                                        protected void onPostExecute(Void aVoid) {
                                                            if (adapter != null) {
                                                                adapter.notifyItemChanged(1);
                                                            }
                                                        }
                                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                                }
                                            });
                                        }
                                        break;
                                    case 2:
                                        {
                                            new AlertDialogWrapper.Builder(mContext).setTitle(R.string.really_delete_submission).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    new AsyncTask<Void, Void, Void>() {

                                                        @Override
                                                        protected Void doInBackground(Void... params) {
                                                            try {
                                                                new ModerationManager(Authentication.reddit).delete(submission);
                                                            } catch (ApiException e) {
                                                                e.printStackTrace();
                                                            }
                                                            return null;
                                                        }

                                                        @Override
                                                        protected void onPostExecute(Void aVoid) {
                                                            (mContext).runOnUiThread(new Runnable() {

                                                                @Override
                                                                public void run() {
                                                                    (holder.title).setTextHtml(mContext.getString(R.string.content_deleted));
                                                                    if (holder.firstTextView != null) {
                                                                        holder.firstTextView.setText(R.string.content_deleted);
                                                                        holder.commentOverflow.setVisibility(View.GONE);
                                                                    } else {
                                                                        if (holder.itemView.findViewById(R.id.body) != null) {
                                                                            ((TextView) holder.itemView.findViewById(R.id.body)).setText(R.string.content_deleted);
                                                                        }
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                                }
                                            }).setNegativeButton(R.string.btn_cancel, null).show();
                                        }
                                        break;
                                    case 3:
                                        {
                                            new MaterialDialog.Builder(mContext).items(data).title(R.string.sidebar_select_flair).itemsCallback(new MaterialDialog.ListCallback() {

                                                @Override
                                                public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                                    final FlairTemplate t = flairlist.get(which);
                                                    if (t.isTextEditable()) {
                                                        new MaterialDialog.Builder(mContext).title(R.string.mod_btn_submission_flair_text).input(mContext.getString(R.string.mod_flair_hint), t.getText(), true, new MaterialDialog.InputCallback() {

                                                            @Override
                                                            public void onInput(MaterialDialog dialog, CharSequence input) {
                                                            }
                                                        }).positiveText(R.string.btn_set).onPositive(new MaterialDialog.SingleButtonCallback() {

                                                            @Override
                                                            public void onClick(MaterialDialog dialog, DialogAction which) {
                                                                final String flair = dialog.getInputEditText().getText().toString();
                                                                new AsyncTask<Void, Void, Boolean>() {

                                                                    @Override
                                                                    protected Boolean doInBackground(Void... params) {
                                                                        try {
                                                                            new ModerationManager(Authentication.reddit).setFlair(submission.getSubredditName(), t, flair, submission);
                                                                            return true;
                                                                        } catch (ApiException e) {
                                                                            e.printStackTrace();
                                                                            return false;
                                                                        }
                                                                    }

                                                                    @Override
                                                                    protected void onPostExecute(Boolean done) {
                                                                        Snackbar s = null;
                                                                        if (done) {
                                                                            if (holder.itemView != null) {
                                                                                s = Snackbar.make(holder.itemView, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
                                                                                SubmissionCache.updateTitleFlair(submission, flair, mContext);
                                                                                holder.title.setText(SubmissionCache.getTitleLine(submission, mContext));
                                                                            }
                                                                        } else {
                                                                            if (holder.itemView != null) {
                                                                                s = Snackbar.make(holder.itemView, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
                                                                            }
                                                                        }
                                                                        if (s != null) {
                                                                            View view = s.getView();
                                                                            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                                                            tv.setTextColor(Color.WHITE);
                                                                            s.show();
                                                                        }
                                                                    }
                                                                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                                            }
                                                        }).negativeText(R.string.btn_cancel).show();
                                                    } else {
                                                        new AsyncTask<Void, Void, Boolean>() {

                                                            @Override
                                                            protected Boolean doInBackground(Void... params) {
                                                                try {
                                                                    new ModerationManager(Authentication.reddit).setFlair(submission.getSubredditName(), t, null, submission);
                                                                    return true;
                                                                } catch (ApiException e) {
                                                                    e.printStackTrace();
                                                                    return false;
                                                                }
                                                            }

                                                            @Override
                                                            protected void onPostExecute(Boolean done) {
                                                                Snackbar s = null;
                                                                if (done) {
                                                                    if (holder.itemView != null) {
                                                                        s = Snackbar.make(holder.itemView, R.string.snackbar_flair_success, Snackbar.LENGTH_SHORT);
                                                                        SubmissionCache.updateTitleFlair(submission, t.getCssClass(), mContext);
                                                                        holder.title.setText(SubmissionCache.getTitleLine(submission, mContext));
                                                                    }
                                                                } else {
                                                                    if (holder.itemView != null) {
                                                                        s = Snackbar.make(holder.itemView, R.string.snackbar_flair_error, Snackbar.LENGTH_SHORT);
                                                                    }
                                                                }
                                                                if (s != null) {
                                                                    View view = s.getView();
                                                                    TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                                                    tv.setTextColor(Color.WHITE);
                                                                    s.show();
                                                                }
                                                            }
                                                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                                    }
                                                }
                                            }).show();
                                        }
                                        break;
                                    case 4:
                                        if (submission.isNsfw()) {
                                            unNsfwSubmission(mContext, submission, holder);
                                        } else {
                                            setPostNsfw(mContext, submission, holder);
                                        }
                                        break;
                                }
                            }
                        }).show();
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        });
    } else {
        edit.setVisibility(View.GONE);
    }
    if (HasSeen.getSeen(submission) && !full) {
        holder.title.setAlpha(0.54f);
        holder.body.setAlpha(0.54f);
    } else {
        holder.title.setAlpha(1f);
        if (!full) {
            holder.body.setAlpha(1f);
        }
    }
}
Also used : FluentRedditClient(net.dean.jraw.fluent.FluentRedditClient) ContentType(me.ccrama.redditslide.ContentType) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) FlairReference(net.dean.jraw.fluent.FlairReference) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) EditText(android.widget.EditText) Vote(me.ccrama.redditslide.Vote) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Typeface(android.graphics.Typeface) FlairTemplate(net.dean.jraw.models.FlairTemplate) AsyncTask(android.os.AsyncTask) Drawable(android.graphics.drawable.Drawable) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) AccountManager(net.dean.jraw.managers.AccountManager) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Snackbar(android.support.design.widget.Snackbar) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ModerationManager(net.dean.jraw.managers.ModerationManager) AppCompatActivity(android.support.v7.app.AppCompatActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) ApiException(net.dean.jraw.ApiException) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ApiException(net.dean.jraw.ApiException)

Aggregations

View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Vote (me.ccrama.redditslide.Vote)4 ApiException (net.dean.jraw.ApiException)4 AsyncTask (android.os.AsyncTask)3 SpannableStringBuilder (android.text.SpannableStringBuilder)3 SubredditView (me.ccrama.redditslide.Activities.SubredditView)3 AccountManager (net.dean.jraw.managers.AccountManager)3 DialogInterface (android.content.DialogInterface)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ForegroundColorSpan (android.text.style.ForegroundColorSpan)2 LayoutInflater (android.view.LayoutInflater)2 EditText (android.widget.EditText)2 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2 SlidingUpPanelLayout (com.sothree.slidinguppanel.SlidingUpPanelLayout)2 ArrayList (java.util.ArrayList)2 TitleTextView (me.ccrama.redditslide.Views.TitleTextView)2 OnSingleClickListener (me.ccrama.redditslide.util.OnSingleClickListener)2 Comment (net.dean.jraw.models.Comment)2