Search in sources :

Example 1 with TitleTextView

use of me.ccrama.redditslide.Views.TitleTextView in project Slide by ccrama.

the class Announcement method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overridePendingTransition(R.anim.fade_in_real, 0);
    disableSwipeBackLayout();
    applyColorTheme();
    setTheme(R.style.popup);
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    super.onCreate(savedInstance);
    setContentView(R.layout.submission_dialog);
    setViews(Reddit.appRestart.getString("page", ""), "NO SUB", (SpoilerRobotoTextView) findViewById(R.id.firstTextView), (CommentOverflow) findViewById(R.id.commentOverflow));
    ((TitleTextView) findViewById(R.id.title)).setText(Reddit.appRestart.getString("title", ""));
    findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    findViewById(R.id.comments).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new OpenRedditLink(Announcement.this, Reddit.appRestart.getString("url", ""));
            finish();
        }
    });
}
Also used : TitleTextView(me.ccrama.redditslide.Views.TitleTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) View(android.view.View) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 2 with TitleTextView

use of me.ccrama.redditslide.Views.TitleTextView 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)

Aggregations

View (android.view.View)2 TitleTextView (me.ccrama.redditslide.Views.TitleTextView)2 AsyncTask (android.os.AsyncTask)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SlidingUpPanelLayout (com.sothree.slidinguppanel.SlidingUpPanelLayout)1 SubredditView (me.ccrama.redditslide.Activities.SubredditView)1 OpenRedditLink (me.ccrama.redditslide.OpenRedditLink)1 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)1 RoundedBackgroundSpan (me.ccrama.redditslide.Views.RoundedBackgroundSpan)1 Vote (me.ccrama.redditslide.Vote)1 ApiException (net.dean.jraw.ApiException)1 AccountManager (net.dean.jraw.managers.AccountManager)1 Comment (net.dean.jraw.models.Comment)1