Search in sources :

Example 1 with OpenRedditLink

use of me.ccrama.redditslide.OpenRedditLink 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 OpenRedditLink

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

the class OpenContent method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.clear);
    Intent intent = getIntent();
    Uri data = intent.getData();
    Bundle extras = intent.getExtras();
    String url;
    if (data != null) {
        url = data.toString();
    } else if (extras != null) {
        url = extras.getString(EXTRA_URL, "");
    } else {
        Toast.makeText(OpenContent.this, R.string.err_invalid_url, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    url = url.toLowerCase(Locale.ENGLISH);
    new OpenRedditLink(this, url);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) Uri(android.net.Uri) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 3 with OpenRedditLink

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

the class InboxAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (!(viewHolder instanceof ContributionAdapter.EmptyViewHolder) && !(viewHolder instanceof SpacerViewHolder)) {
        final MessageViewHolder messageViewHolder = (MessageViewHolder) viewHolder;
        final Message comment = dataSet.posts.get(i);
        messageViewHolder.time.setText(TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext));
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String author = comment.getAuthor();
        String direction = "from ";
        if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
            author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
            direction = "to ";
        }
        if (comment.getDataNode().has("subreddit") && author == null || author.isEmpty()) {
            direction = "via /r/" + comment.getSubreddit();
        }
        titleString.append(direction);
        if (author != null) {
            titleString.append(author);
            titleString.append(" ");
            if (UserTags.isUserTagged(author)) {
                SpannableStringBuilder pinned = new SpannableStringBuilder(" " + UserTags.getUserTag(author) + " ");
                pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_blue_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                titleString.append(pinned);
                titleString.append(" ");
            }
            if (UserSubscriptions.friends.contains(author)) {
                SpannableStringBuilder pinned = new SpannableStringBuilder(" " + mContext.getString(R.string.profile_friend) + " ");
                pinned.setSpan(new RoundedBackgroundSpan(mContext, R.color.white, R.color.md_deep_orange_500, false), 0, pinned.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                titleString.append(pinned);
                titleString.append(" ");
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        if (comment.getDataNode().has("subreddit") && !comment.getDataNode().get("subreddit").isNull()) {
            titleString.append(spacer);
            String subname = comment.getDataNode().get("subreddit").asText();
            SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
            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);
        }
        messageViewHolder.user.setText(titleString);
        SpannableStringBuilder b = new SpannableStringBuilder();
        if (mContext instanceof Inbox && comment.getCreated().getTime() > ((Inbox) mContext).last && !comment.isRead()) {
            SpannableStringBuilder tagNew = new SpannableStringBuilder("\u00A0NEW\u00A0");
            tagNew.setSpan(new RoundedBackgroundSpan(Color.WHITE, mContext.getResources().getColor(R.color.md_green_400), true, mContext), 0, tagNew.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            b.append(tagNew);
            b.append(" ");
        }
        b.append(comment.getSubject());
        if (comment.getDataNode().has("link_title")) {
            SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
            link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            b.append(link);
        }
        messageViewHolder.title.setText(b);
        if (comment.isRead()) {
            messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
        } else {
            messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
        }
        messageViewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                int[] attrs = new int[] { R.attr.tintColor };
                TypedArray ta = mContext.obtainStyledAttributes(attrs);
                final int color = ta.getColor(0, Color.WHITE);
                Drawable profile = mContext.getResources().getDrawable(R.drawable.profile);
                final Drawable reply = mContext.getResources().getDrawable(R.drawable.reply);
                Drawable unhide = mContext.getResources().getDrawable(R.drawable.ic_visibility);
                Drawable hide = mContext.getResources().getDrawable(R.drawable.hide);
                Drawable copy = mContext.getResources().getDrawable(R.drawable.ic_content_copy);
                Drawable reddit = mContext.getResources().getDrawable(R.drawable.commentchange);
                profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                reply.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                unhide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                ta.recycle();
                BottomSheet.Builder b = new BottomSheet.Builder((Activity) mContext).title(Html.fromHtml(comment.getSubject()));
                String author = comment.getAuthor();
                if (!dataSet.where.contains("mod") && comment.getDataNode().has("dest") && !Authentication.name.equalsIgnoreCase(comment.getDataNode().get("dest").asText()) && !comment.getDataNode().get("dest").asText().equals("reddit")) {
                    author = comment.getDataNode().get("dest").asText().replace("#", "/r/");
                }
                if (comment.getAuthor() != null) {
                    b.sheet(1, profile, "/u/" + author);
                }
                String read = mContext.getString(R.string.mail_mark_read);
                Drawable rDrawable = hide;
                if (comment.isRead()) {
                    read = mContext.getString(R.string.mail_mark_unread);
                    rDrawable = unhide;
                }
                b.sheet(2, rDrawable, read);
                b.sheet(3, reply, mContext.getString(R.string.btn_reply));
                b.sheet(25, copy, mContext.getString(R.string.misc_copy_text));
                if (comment.isComment()) {
                    b.sheet(30, reddit, mContext.getString(R.string.mail_view_full_thread));
                }
                final String finalAuthor = author;
                b.listener(new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch(which) {
                            case 1:
                                {
                                    Intent i = new Intent(mContext, Profile.class);
                                    i.putExtra(Profile.EXTRA_PROFILE, finalAuthor);
                                    mContext.startActivity(i);
                                }
                                break;
                            case 2:
                                {
                                    if (comment.isRead()) {
                                        comment.read = false;
                                        new AsyncSetRead(false).execute(comment);
                                        messageViewHolder.title.setTextColor(ContextCompat.getColor(mContext, R.color.md_red_400));
                                    } else {
                                        comment.read = true;
                                        new AsyncSetRead(true).execute(comment);
                                        messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
                                    }
                                }
                                break;
                            case 3:
                                {
                                    doInboxReply(comment);
                                }
                                break;
                            case 25:
                                {
                                    ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                    ClipData clip = ClipData.newPlainText("Message", comment.getBody());
                                    clipboard.setPrimaryClip(clip);
                                    Toast.makeText(mContext, mContext.getString(R.string.mail_message_copied), Toast.LENGTH_SHORT).show();
                                }
                                break;
                            case 30:
                                {
                                    String context = comment.getDataNode().get("context").asText();
                                    new OpenRedditLink(mContext, "https://reddit.com" + context.substring(0, context.lastIndexOf("/")));
                                }
                                break;
                        }
                    }
                }).show();
                return true;
            }
        });
        messageViewHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (comment.isRead()) {
                    if (comment instanceof PrivateMessage) {
                        DataShare.sharedMessage = (PrivateMessage) comment;
                        Intent i = new Intent(mContext, SendMessage.class);
                        i.putExtra(SendMessage.EXTRA_NAME, comment.getAuthor());
                        i.putExtra(SendMessage.EXTRA_REPLY, true);
                        mContext.startActivity(i);
                    } else {
                        new OpenRedditLink(mContext, comment.getDataNode().get("context").asText());
                    }
                } else {
                    comment.read = true;
                    new AsyncSetRead(true).execute(comment);
                    messageViewHolder.title.setTextColor(messageViewHolder.content.getCurrentTextColor());
                    {
                        SpannableStringBuilder b = new SpannableStringBuilder(comment.getSubject());
                        if (comment.getDataNode().has("link_title")) {
                            SpannableStringBuilder link = new SpannableStringBuilder(" " + Html.fromHtml(comment.getDataNode().get("link_title").asText()) + " ");
                            link.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            link.setSpan(new RelativeSizeSpan(0.8f), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            b.append(link);
                        }
                        messageViewHolder.title.setText(b);
                    }
                }
            }
        });
        // Set typeface for body
        int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, type);
        } else {
            typeface = Typeface.DEFAULT;
        }
        messageViewHolder.content.setTypeface(typeface);
        setViews(comment.getDataNode().get("body_html").asText(), "FORCE_LINK_CLICK", messageViewHolder);
    }
    if (viewHolder instanceof SpacerViewHolder) {
        viewHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(viewHolder.itemView.getWidth(), ((Activity) mContext).findViewById(R.id.header).getHeight()));
    }
}
Also used : SendMessage(me.ccrama.redditslide.Activities.SendMessage) PrivateMessage(net.dean.jraw.models.PrivateMessage) Message(net.dean.jraw.models.Message) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) TypedArray(android.content.res.TypedArray) PrivateMessage(net.dean.jraw.models.PrivateMessage) Inbox(me.ccrama.redditslide.Activities.Inbox) SendMessage(me.ccrama.redditslide.Activities.SendMessage) ClipboardManager(android.content.ClipboardManager) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Typeface(android.graphics.Typeface) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) RoundedBackgroundSpan(me.ccrama.redditslide.Views.RoundedBackgroundSpan) StyleSpan(android.text.style.StyleSpan) ClipData(android.content.ClipData) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 4 with OpenRedditLink

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

the class ModeratorAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHold, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (firstHold instanceof SubmissionViewHolder) {
        SubmissionViewHolder holder = (SubmissionViewHolder) firstHold;
        final Submission submission = (Submission) dataSet.posts.get(i);
        CreateCardView.resetColorCard(holder.itemView);
        CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                LayoutInflater inflater = mContext.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(Html.fromHtml(submission.getTitle()));
                ((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
                dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSaved()) {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
                        } else {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                        }
                        new AsyncSave(firstHold.itemView).execute(submission);
                    }
                });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (submission.isSaved()) {
                    ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                }
                dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String urlString = "https://reddit.com" + submission.getPermalink();
                        Intent i = new Intent(mContext, Website.class);
                        i.putExtra(Website.EXTRA_URL, urlString);
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSelfPost()) {
                            if (SettingValues.shareLongLink) {
                                Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
                            } else {
                                Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
                            }
                        } else {
                            new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch(which) {
                                        case R.id.reddit_url:
                                            if (SettingValues.shareLongLink) {
                                                Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
                                            } else {
                                                Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                                            }
                                            break;
                                        case R.id.link_url:
                                            Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
                                            break;
                                    }
                                }
                            }).show();
                        }
                    }
                });
                if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                    dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                    dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final int pos = dataSet.posts.indexOf(submission);
                        final Contribution old = dataSet.posts.get(pos);
                        dataSet.posts.remove(submission);
                        notifyItemRemoved(pos + 1);
                        d.dismiss();
                        Hidden.setHidden(old);
                        Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                dataSet.posts.add(pos, (PublicContribution) old);
                                notifyItemInserted(pos + 1);
                                Hidden.undoHidden(old);
                            }
                        });
                        View view = s.getView();
                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                });
                return true;
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
        final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
        if (hideButton != null) {
            hideButton.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = "www.reddit.com" + submission.getPermalink();
                url = url.replace("?ref=search_posts", "");
                new OpenRedditLink(mContext, url);
            }
        });
    } else if (firstHold instanceof ProfileCommentViewHolder) {
        // IS COMMENT
        final ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHold;
        final Comment comment = (Comment) dataSet.posts.get(i);
        holder.score.setText(comment.getScore() + " " + mContext.getResources().getQuantityString(R.plurals.points, comment.getScore()));
        if (Authentication.isLoggedIn) {
            if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
            } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
            } else {
                holder.score.setTextColor(holder.time.getCurrentTextColor());
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
        // some users were crashing here
        String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
        time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
        titleString.append(time);
        titleString.append(spacer);
        {
            final ImageView mod = (ImageView) holder.itemView.findViewById(R.id.mod);
            try {
                if (UserSubscriptions.modOf.contains(comment.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(comment.getSubredditName().toLowerCase(Locale.ENGLISH))) {
            holder.itemView.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) holder.itemView.findViewById(R.id.mod)).setColorFilter(ContextCompat.getColor(mContext, R.color.md_red_300), PorterDuff.Mode.SRC_ATOP);
            } else {
                int[] attrs = new int[] { R.attr.tintColor };
                TypedArray ta = mContext.obtainStyledAttributes(attrs);
                int color = ta.getColor(0, Color.WHITE);
                ((ImageView) holder.itemView.findViewById(R.id.mod)).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                ta.recycle();
            }
            holder.itemView.findViewById(R.id.mod).setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    showModBottomSheet(mContext, comment, holder, reports, reports2);
                }
            });
        } else {
            holder.itemView.findViewById(R.id.mod).setVisibility(View.GONE);
        }
        if (comment.getSubredditName() != null) {
            String subname = comment.getSubredditName();
            SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
            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);
        }
        holder.time.setText(titleString);
        setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
        if (comment.getTimesGilded() > 0) {
            holder.gild.setVisibility(View.VISIBLE);
            ((TextView) holder.gild).setText(Integer.toString(comment.getTimesGilded()));
        } else if (holder.gild.getVisibility() == View.VISIBLE)
            holder.gild.setVisibility(View.GONE);
        if (comment.getSubmissionTitle() != null)
            holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
        else
            holder.title.setText(Html.fromHtml(comment.getAuthor()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
        holder.content.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
    }
    if (firstHold instanceof SpacerViewHolder) {
        firstHold.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(firstHold.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
    }
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) ImageView(android.widget.ImageView) Comment(net.dean.jraw.models.Comment) Submission(net.dean.jraw.models.Submission) ForegroundColorSpan(android.text.style.ForegroundColorSpan) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Intent(android.content.Intent) PublicContribution(net.dean.jraw.models.PublicContribution) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) ApiException(net.dean.jraw.ApiException) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Map(java.util.Map) Contribution(net.dean.jraw.models.Contribution) PublicContribution(net.dean.jraw.models.PublicContribution) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 5 with OpenRedditLink

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

the class ContributionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (firstHolder instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) firstHolder;
        final Submission submission = (Submission) dataSet.posts.get(i);
        CreateCardView.resetColorCard(holder.itemView);
        if (submission.getSubredditName() != null)
            CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, "no_subreddit", false);
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                LayoutInflater inflater = mContext.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(Html.fromHtml(submission.getTitle()));
                ((TextView) dialoglayout.findViewById(R.id.userpopup)).setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup)).setText("/r/" + submission.getSubredditName());
                dialoglayout.findViewById(R.id.sidebar).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, Profile.class);
                        i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.wiki).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSaved()) {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_save);
                        } else {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                        }
                        new AsyncSave(firstHolder.itemView).execute(submission);
                    }
                });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (submission.isSaved()) {
                    ((TextView) dialoglayout.findViewById(R.id.savedtext)).setText(R.string.submission_post_saved);
                }
                dialoglayout.findViewById(R.id.gild).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String urlString = "https://reddit.com" + submission.getPermalink();
                        Intent i = new Intent(mContext, Website.class);
                        i.putExtra(Website.EXTRA_URL, urlString);
                        mContext.startActivity(i);
                    }
                });
                dialoglayout.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (submission.isSelfPost()) {
                            if (SettingValues.shareLongLink) {
                                Reddit.defaultShareText("", "htts://reddit.com" + submission.getPermalink(), mContext);
                            } else {
                                Reddit.defaultShareText("", "https://redd.it/" + submission.getId(), mContext);
                            }
                        } else {
                            new BottomSheet.Builder(mContext).title(R.string.submission_share_title).grid().sheet(R.menu.share_menu).listener(new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch(which) {
                                        case R.id.reddit_url:
                                            if (SettingValues.shareLongLink) {
                                                Reddit.defaultShareText(submission.getTitle(), "htts://reddit.com" + submission.getPermalink(), mContext);
                                            } else {
                                                Reddit.defaultShareText(submission.getTitle(), "https://redd.it/" + submission.getId(), mContext);
                                            }
                                            break;
                                        case R.id.link_url:
                                            Reddit.defaultShareText(submission.getTitle(), submission.getUrl(), mContext);
                                            break;
                                    }
                                }
                            }).show();
                        }
                    }
                });
                if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                    dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                    dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                dialoglayout.findViewById(R.id.hide).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final int pos = dataSet.posts.indexOf(submission);
                        final Contribution old = dataSet.posts.get(pos);
                        dataSet.posts.remove(submission);
                        notifyItemRemoved(pos + 1);
                        d.dismiss();
                        Hidden.setHidden(old);
                        Snackbar s = Snackbar.make(listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                dataSet.posts.add(pos, old);
                                notifyItemInserted(pos + 1);
                                Hidden.undoHidden(old);
                            }
                        });
                        View view = s.getView();
                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                });
                return true;
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, mContext, false, false, dataSet.posts, listView, false, false, null, null);
        final ImageView hideButton = (ImageView) holder.itemView.findViewById(R.id.hide);
        if (hideButton != null && isHiddenPost) {
            hideButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final int pos = dataSet.posts.indexOf(submission);
                    final Contribution old = dataSet.posts.get(pos);
                    dataSet.posts.remove(submission);
                    notifyItemRemoved(pos + 1);
                    Hidden.undoHidden(old);
                }
            });
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = "www.reddit.com" + submission.getPermalink();
                url = url.replace("?ref=search_posts", "");
                new OpenRedditLink(mContext, url);
                if (SettingValues.storeHistory) {
                    if (SettingValues.storeNSFWHistory && submission.isNsfw() || !submission.isNsfw())
                        HasSeen.addSeen(submission.getFullName());
                }
                notifyItemChanged(pos);
            }
        });
    } else if (firstHolder instanceof ProfileCommentViewHolder) {
        // IS COMMENT
        ProfileCommentViewHolder holder = (ProfileCommentViewHolder) firstHolder;
        final Comment comment = (Comment) dataSet.posts.get(i);
        String scoreText;
        if (comment.isScoreHidden()) {
            scoreText = "[" + mContext.getString(R.string.misc_score_hidden).toUpperCase() + "]";
        } else {
            scoreText = String.format(Locale.getDefault(), "%d", comment.getScore());
        }
        SpannableStringBuilder score = new SpannableStringBuilder(scoreText);
        if (score == null || score.toString().isEmpty()) {
            score = new SpannableStringBuilder("0");
        }
        if (!scoreText.contains("[")) {
            score.append(String.format(Locale.getDefault(), " %s", mContext.getResources().getQuantityString(R.plurals.points, comment.getScore())));
        }
        holder.score.setText(score);
        if (Authentication.isLoggedIn) {
            if (ActionStates.getVoteDirection(comment) == VoteDirection.UPVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_orange_500));
            } else if (ActionStates.getVoteDirection(comment) == VoteDirection.DOWNVOTE) {
                holder.score.setTextColor(mContext.getResources().getColor(R.color.md_blue_500));
            } else {
                holder.score.setTextColor(holder.time.getCurrentTextColor());
            }
        }
        String spacer = mContext.getString(R.string.submission_properties_seperator);
        SpannableStringBuilder titleString = new SpannableStringBuilder();
        String timeAgo = TimeUtils.getTimeAgo(comment.getCreated().getTime(), mContext);
        // some users were crashing here
        String time = ((timeAgo == null || timeAgo.isEmpty()) ? "just now" : timeAgo);
        time = time + (((comment.getEditDate() != null) ? " (edit " + TimeUtils.getTimeAgo(comment.getEditDate().getTime(), mContext) + ")" : ""));
        titleString.append(time);
        titleString.append(spacer);
        if (comment.getSubredditName() != null) {
            String subname = comment.getSubredditName();
            SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
            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);
        }
        holder.time.setText(titleString);
        setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
        int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
        Typeface typeface;
        if (type >= 0) {
            typeface = RobotoTypefaces.obtainTypeface(mContext, type);
        } else {
            typeface = Typeface.DEFAULT;
        }
        holder.content.setTypeface(typeface);
        if (comment.getTimesGilded() > 0) {
            final String timesGilded = (comment.getTimesGilded() == 1) ? "" : "\u200Ax" + Integer.toString(comment.getTimesGilded());
            SpannableStringBuilder gilded = new SpannableStringBuilder("\u00A0★" + timesGilded + "\u00A0");
            TypedArray a = mContext.obtainStyledAttributes(new FontPreferences(mContext).getPostFontStyle().getResId(), R.styleable.FontStyle);
            int fontsize = (int) (a.getDimensionPixelSize(R.styleable.FontStyle_font_cardtitle, -1) * .75);
            a.recycle();
            Bitmap image = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gold);
            float aspectRatio = (float) (1.00 * image.getWidth() / image.getHeight());
            image = Bitmap.createScaledBitmap(image, (int) Math.ceil(fontsize * aspectRatio), (int) Math.ceil(fontsize), true);
            gilded.setSpan(new ImageSpan(mContext, image, ImageSpan.ALIGN_BASELINE), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            gilded.setSpan(new RelativeSizeSpan(0.75f), 3, gilded.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            holder.gild.setVisibility(View.VISIBLE);
            ((TextView) holder.gild).setText(gilded);
        } else if (holder.gild.getVisibility() == View.VISIBLE)
            holder.gild.setVisibility(View.GONE);
        if (comment.getSubmissionTitle() != null)
            holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
        else
            holder.title.setText(Html.fromHtml(comment.getAuthor()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
        holder.content.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new OpenRedditLink(mContext, comment.getSubmissionId(), comment.getSubredditName(), comment.getId());
            }
        });
    } else if (firstHolder instanceof SpacerViewHolder) {
        firstHolder.itemView.setLayoutParams(new LinearLayout.LayoutParams(firstHolder.itemView.getWidth(), mContext.findViewById(R.id.header).getHeight()));
        if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
            CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.findViewById(R.id.header).getHeight());
            layoutParams.setFullSpan(true);
            firstHolder.itemView.setLayoutParams(layoutParams);
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Bitmap(android.graphics.Bitmap) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) ImageView(android.widget.ImageView) Comment(net.dean.jraw.models.Comment) Submission(net.dean.jraw.models.Submission) ForegroundColorSpan(android.text.style.ForegroundColorSpan) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Typeface(android.graphics.Typeface) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) LayoutInflater(android.view.LayoutInflater) StyleSpan(android.text.style.StyleSpan) BottomSheet(com.cocosw.bottomsheet.BottomSheet) Contribution(net.dean.jraw.models.Contribution) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) ImageSpan(android.text.style.ImageSpan)

Aggregations

OpenRedditLink (me.ccrama.redditslide.OpenRedditLink)11 View (android.view.View)8 Intent (android.content.Intent)6 TextView (android.widget.TextView)6 Comment (net.dean.jraw.models.Comment)6 RecyclerView (android.support.v7.widget.RecyclerView)5 DialogInterface (android.content.DialogInterface)4 TypedArray (android.content.res.TypedArray)4 SpannableStringBuilder (android.text.SpannableStringBuilder)4 ImageView (android.widget.ImageView)4 LinearLayout (android.widget.LinearLayout)4 ClipData (android.content.ClipData)3 ClipboardManager (android.content.ClipboardManager)3 Typeface (android.graphics.Typeface)3 ForegroundColorSpan (android.text.style.ForegroundColorSpan)3 StyleSpan (android.text.style.StyleSpan)3 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)3 BottomSheet (com.cocosw.bottomsheet.BottomSheet)3 PopulateSubmissionViewHolder (me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder)3 FontPreferences (me.ccrama.redditslide.Visuals.FontPreferences)3