Search in sources :

Example 6 with OpenRedditLink

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

the class SettingsAbout method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_about);
    setupAppBar(R.id.toolbar, R.string.settings_title_about, true, true);
    View report = findViewById(R.id.report);
    View libs = findViewById(R.id.libs);
    View changelog = findViewById(R.id.changelog);
    final TextView version = (TextView) findViewById(R.id.version);
    version.setText("Slide v" + BuildConfig.VERSION_NAME);
    // Copy the latest stacktrace with a long click on the version number
    if (BuildConfig.DEBUG) {
        version.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                SharedPreferences prefs = getSharedPreferences("STACKTRACE", Context.MODE_PRIVATE);
                String stacktrace = prefs.getString("stacktrace", null);
                if (stacktrace != null) {
                    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("Stacktrace", stacktrace);
                    clipboard.setPrimaryClip(clip);
                }
                prefs.edit().clear().apply();
                return true;
            }
        });
    }
    version.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String versionNumber = version.getText().toString();
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Version", versionNumber);
            clipboard.setPrimaryClip(clip);
            Toast.makeText(SettingsAbout.this, R.string.settings_about_version_copied_toast, Toast.LENGTH_SHORT).show();
        }
    });
    report.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LinkUtil.openExternally("https://github.com/ccrama/Slide/issues", SettingsAbout.this);
        }
    });
    findViewById(R.id.sub).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new OpenRedditLink(SettingsAbout.this, "https://reddit.com/r/slideforreddit");
        }
    });
    findViewById(R.id.rate).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.redditslide")));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.redditslide")));
            }
        }
    });
    changelog.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LinkUtil.openExternally("https://github.com/ccrama/Slide/blob/master/CHANGELOG.md", SettingsAbout.this);
        }
    });
    libs.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(SettingsAbout.this, SettingsLibs.class);
            startActivity(i);
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) ClipData(android.content.ClipData) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 7 with OpenRedditLink

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

the class AlbumFullComments method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.submission_albumcard, container, false);
    PopulateShadowboxInfo.doActionbar(s.comment, rootView, getActivity(), true);
    String url = s.url;
    if (url.contains("gallery")) {
        gallery = true;
    }
    list = rootView.findViewById(R.id.images);
    list.setVisibility(View.VISIBLE);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    ((RecyclerView) list).setLayoutManager(layoutManager);
    ((RecyclerView) list).setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            ValueAnimator va = null;
            if (dy > 0 && !hidden) {
                hidden = true;
                if (va != null && va.isRunning())
                    va.cancel();
                final View base = rootView.findViewById(R.id.base);
                va = ValueAnimator.ofFloat(1.0f, 0.2f);
                // in millis
                int mDuration = 250;
                va.setDuration(mDuration);
                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    public void onAnimationUpdate(ValueAnimator animation) {
                        Float value = (Float) animation.getAnimatedValue();
                        base.setAlpha(value);
                    }
                });
                va.start();
            } else if (hidden && dy <= 0) {
                final View base = rootView.findViewById(R.id.base);
                if (va != null && va.isRunning())
                    va.cancel();
                hidden = false;
                va = ValueAnimator.ofFloat(0.2f, 1.0f);
                // in millis
                int mDuration = 250;
                va.setDuration(mDuration);
                va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    public void onAnimationUpdate(ValueAnimator animation) {
                        Float value = (Float) animation.getAnimatedValue();
                        base.setAlpha(value);
                    }
                });
                va.start();
            }
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
    final View.OnClickListener openClick = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
        }
    };
    rootView.findViewById(R.id.base).setOnClickListener(openClick);
    final View title = rootView.findViewById(R.id.title);
    title.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).setPanelHeight(title.getMeasuredHeight());
            title.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
    ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout)).addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {

        @Override
        public void onPanelSlide(View panel, float slideOffset) {
        }

        @Override
        public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
            if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
                final Comment c = s.comment.getComment();
                rootView.findViewById(R.id.base).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String url = "https://reddit.com" + "/r/" + c.getSubredditName() + "/comments/" + c.getDataNode().get("link_id").asText().substring(3, c.getDataNode().get("link_id").asText().length()) + "/nothing/" + c.getId() + "?context=3";
                        new OpenRedditLink(getActivity(), url);
                    }
                });
            } else {
                rootView.findViewById(R.id.base).setOnClickListener(openClick);
            }
        }
    });
    new LoadIntoRecycler(url, getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    return rootView;
}
Also used : Comment(net.dean.jraw.models.Comment) SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) AlbumView(me.ccrama.redditslide.Adapters.AlbumView) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ViewTreeObserver(android.view.ViewTreeObserver) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

Example 8 with OpenRedditLink

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

the class CommentAdapter method onBindViewHolder.

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

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

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

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

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

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

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

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

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

Example 9 with OpenRedditLink

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

the class CommentAdapterHelper method showOverflowBottomSheet.

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

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

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

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

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

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

Example 10 with OpenRedditLink

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

the class OpenContent method onNewIntent.

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    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);
    Log.v(LogUtil.getTag(), url);
    new OpenRedditLink(this, url);
}
Also used : Bundle(android.os.Bundle) Uri(android.net.Uri) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink)

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