Search in sources :

Example 1 with SubredditView

use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.

the class SubmissionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (holder2 instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
        final Submission submission = dataSet.posts.get(i);
        CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
        holder.itemView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                if (Authentication.didOnline || submission.getComments() != null) {
                    holder.title.setAlpha(0.54f);
                    holder.body.setAlpha(0.54f);
                    if (context instanceof MainActivity) {
                        final MainActivity a = (MainActivity) context;
                        if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getAdapterPosition();
                                a.openingComments = submission;
                                a.toOpenComments = a.pager.getCurrentItem() + 1;
                                a.currentComment = holder.getAdapterPosition() - 1;
                                ((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
                                try {
                                    a.adapter.notifyDataSetChanged();
                                } catch (Exception ignored) {
                                }
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getAdapterPosition();
                        }
                    } else if (context instanceof SubredditView) {
                        final SubredditView a = (SubredditView) context;
                        if (a.singleMode && a.commentPager) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getAdapterPosition();
                                a.openingComments = submission;
                                a.currentComment = holder.getAdapterPosition() - 1;
                                ((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
                                a.adapter.notifyDataSetChanged();
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getAdapterPosition();
                        }
                    }
                } else {
                    if (!Reddit.appRestart.contains("offlinepopup")) {
                        new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.appRestart.edit().putString("offlinepopup", "").apply();
                            }
                        }).show();
                    } else {
                        Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
                        s.setAction(R.string.misc_more_info, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Reddit.appRestart.edit().putString("offlinepopup", "").apply();
                                    }
                                }).show();
                            }
                        });
                        View view = s.getView();
                        TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                }
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
                1);
            }
        };
        handler.post(r);
        if (holder2.itemView.findViewById(R.id.reload) != null) {
            holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((SubmissionsView) displayer).forceRefresh();
                }
            });
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        View header = (context).findViewById(R.id.header);
        int height = header.getHeight();
        if (height == 0) {
            header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            height = header.getMeasuredHeight();
            holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
            if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
                CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
                layoutParams.setFullSpan(true);
                holder2.itemView.setLayoutParams(layoutParams);
            }
        } else {
            holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
            if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
                CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
                layoutParams.setFullSpan(true);
                holder2.itemView.setLayoutParams(layoutParams);
            }
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Example 2 with SubredditView

use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.

the class PopulateNewsViewHolder method addClickFunctions.

private static void addClickFunctions(final View base, final ContentType.Type type, final Activity contextActivity, final Submission submission, final NewsViewHolder holder, final boolean full) {
    base.setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            if (NetworkUtil.isConnected(contextActivity) || (!NetworkUtil.isConnected(contextActivity) && ContentType.fullImage(type))) {
                if (SettingValues.storeHistory && !full) {
                    if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
                        HasSeen.addSeen(submission.getFullName());
                        if (contextActivity instanceof MainActivity || contextActivity instanceof MultiredditOverview || contextActivity instanceof SubredditView || contextActivity instanceof Search || contextActivity instanceof Profile) {
                            holder.title.setAlpha(0.54f);
                        }
                    }
                }
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking() || (base instanceof HeaderImageLinkView && ((HeaderImageLinkView) base).popped)) {
                    if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
                        switch(type) {
                            case VID_ME:
                            case STREAMABLE:
                                if (SettingValues.video) {
                                    Intent myIntent = new Intent(contextActivity, MediaView.class);
                                    myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());
                                    myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
                                    contextActivity.startActivity(myIntent);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case IMGUR:
                                openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
                                break;
                            case EMBEDDED:
                                if (SettingValues.video) {
                                    String data = Html.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
                                    {
                                        Intent i = new Intent(contextActivity, FullscreenVideo.class);
                                        i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                        contextActivity.startActivity(i);
                                    }
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case REDDIT:
                                openRedditContent(submission.getUrl(), contextActivity);
                                break;
                            case LINK:
                                LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), contextActivity, holder.getAdapterPosition(), submission);
                                break;
                            case SELF:
                                if (holder != null) {
                                    OnSingleClickListener.override = true;
                                    holder.itemView.performClick();
                                }
                                break;
                            case ALBUM:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, AlbumPager.class);
                                        i.putExtra(AlbumPager.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    } else {
                                        i = new Intent(contextActivity, Album.class);
                                        i.putExtra(Album.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    }
                                    addAdaptorPosition(i, submission, holder.getAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case TUMBLR:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, TumblrPager.class);
                                        i.putExtra(TumblrPager.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    } else {
                                        i = new Intent(contextActivity, Tumblr.class);
                                        i.putExtra(Tumblr.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    }
                                    addAdaptorPosition(i, submission, holder.getAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case DEVIANTART:
                            case XKCD:
                            case IMAGE:
                                openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
                                break;
                            case GIF:
                                openGif(contextActivity, submission, holder.getAdapterPosition());
                                break;
                            case NONE:
                                if (holder != null) {
                                    holder.itemView.performClick();
                                }
                                break;
                            case VIDEO:
                                if (Reddit.videoPlugin) {
                                    try {
                                        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                        sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
                                        sharingIntent.putExtra("url", submission.getUrl());
                                        contextActivity.startActivity(sharingIntent);
                                    } catch (Exception e) {
                                        LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                    }
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                        }
                    } else {
                        LinkUtil.openExternally(submission.getUrl(), contextActivity);
                    }
                }
            } else {
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking()) {
                    Snackbar s = Snackbar.make(holder.itemView, R.string.go_online_view_content, Snackbar.LENGTH_SHORT);
                    View view = s.getView();
                    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                    tv.setTextColor(Color.WHITE);
                    s.show();
                }
            }
        }
    });
}
Also used : MultiredditOverview(me.ccrama.redditslide.Activities.MultiredditOverview) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) Intent(android.content.Intent) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) 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) Profile(me.ccrama.redditslide.Activities.Profile) MediaView(me.ccrama.redditslide.Activities.MediaView) ApiException(net.dean.jraw.ApiException) Search(me.ccrama.redditslide.Activities.Search) TextView(android.widget.TextView) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Snackbar(android.support.design.widget.Snackbar)

Example 3 with SubredditView

use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.

the class SettingsSubAdapter method showSubThemeEditor.

/**
 * Displays the subreddit color chooser
 * It is possible to color multiple subreddits at the same time
 *
 * @param subreddits   Subreddits as an array
 * @param context      Context for getting colors
 * @param dialoglayout The subchooser layout (R.layout.colorsub)
 */
public static void showSubThemeEditor(final ArrayList<String> subreddits, final Activity context, View dialoglayout) {
    if (subreddits.isEmpty()) {
        return;
    }
    final boolean multipleSubs = (subreddits.size() > 1);
    boolean isAlternateLayout;
    int currentColor;
    int currentAccentColor;
    final ColorPreferences colorPrefs = new ColorPreferences(context);
    final String subreddit = multipleSubs ? null : subreddits.get(0);
    final SwitchCompat bigPics = (SwitchCompat) dialoglayout.findViewById(R.id.bigpics);
    final SwitchCompat selftext = (SwitchCompat) dialoglayout.findViewById(R.id.selftext);
    // Selected multiple subreddits
    if (multipleSubs) {
        // Check if all selected subs have the same settings
        int previousSubColor = 0;
        int previousSubAccent = 0;
        bigPics.setChecked(SettingValues.bigPicEnabled);
        selftext.setChecked(SettingValues.cardText);
        boolean sameMainColor = true;
        boolean sameAccentColor = true;
        for (String sub : subreddits) {
            int currentSubColor = Palette.getColor(sub);
            int currentSubAccent = colorPrefs.getColor("");
            if (previousSubColor != 0 && previousSubAccent != 0) {
                if (currentSubColor != previousSubColor) {
                    sameMainColor = false;
                } else if (currentSubAccent != previousSubAccent) {
                    sameAccentColor = false;
                }
            }
            if (!sameMainColor && !sameAccentColor) {
                break;
            }
            previousSubAccent = currentSubAccent;
            previousSubColor = currentSubColor;
        }
        currentColor = Palette.getDefaultColor();
        currentAccentColor = colorPrefs.getColor("");
        isAlternateLayout = false;
        // If all selected subs have the same settings, display them
        if (sameMainColor) {
            currentColor = previousSubColor;
        }
        if (sameAccentColor) {
            currentAccentColor = previousSubAccent;
        }
    } else {
        // Is only one selected sub
        currentColor = Palette.getColor(subreddit);
        isAlternateLayout = SettingValues.prefs.contains(Reddit.PREF_LAYOUT + subreddit);
        currentAccentColor = colorPrefs.getColor(subreddit);
        bigPics.setChecked(SettingValues.isPicsEnabled(subreddit));
        selftext.setChecked(SettingValues.isSelftextEnabled(subreddit));
    }
    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
    final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
    title.setBackgroundColor(currentColor);
    if (multipleSubs) {
        String titleString = "";
        for (String sub : subreddits) {
            // if the subreddit is the frontpage, don't put "/r/" in front of it
            if (sub.equals("frontpage")) {
                titleString += sub + ", ";
            } else {
                if (sub.contains("/m/")) {
                    titleString += sub + ", ";
                } else {
                    titleString += "/r/" + sub + ", ";
                }
            }
        }
        titleString = titleString.substring(0, titleString.length() - 2);
        title.setMaxLines(3);
        title.setText(titleString);
    } else {
        if (subreddit.contains("/m/")) {
            title.setText(subreddit);
        } else {
            // if the subreddit is the frontpage, don't put "/r/" in front of it
            title.setText(((subreddit.equals("frontpage")) ? "frontpage" : "/r/" + subreddit));
        }
    }
    {
        // Primary color pickers
        final LineColorPicker colorPickerPrimary = (LineColorPicker) dialoglayout.findViewById(R.id.picker);
        // shades of primary colors
        final LineColorPicker colorPickerPrimaryShades = (LineColorPicker) dialoglayout.findViewById(R.id.picker2);
        colorPickerPrimary.setColors(ColorPreferences.getBaseColors(context));
        // Iterate through all colors and check if it matches the current color of the sub, then select it
        for (int i : colorPickerPrimary.getColors()) {
            for (int i2 : ColorPreferences.getColors(context, i)) {
                if (i2 == currentColor) {
                    colorPickerPrimary.setSelectedColor(i);
                    colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, i));
                    colorPickerPrimaryShades.setSelectedColor(i2);
                    break;
                }
            }
        }
        // Base color changed
        colorPickerPrimary.setOnColorChangedListener(new OnColorChangedListener() {

            @Override
            public void onColorChanged(int c) {
                // Show variations of the base color
                colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, c));
                colorPickerPrimaryShades.setSelectedColor(c);
            }
        });
        colorPickerPrimaryShades.setOnColorChangedListener(new OnColorChangedListener() {

            @Override
            public void onColorChanged(int i) {
                if (context instanceof MainActivity) {
                    ((MainActivity) context).updateColor(colorPickerPrimaryShades.getColor(), subreddit);
                }
                title.setBackgroundColor(colorPickerPrimaryShades.getColor());
            }
        });
        {
        /* TODO   TextView dialogButton = (TextView) dialoglayout.findViewById(R.id.reset);

                            // if button is clicked, close the custom dialog
                            dialogButton.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Palette.removeColor(subreddit);
                                    hea.setBackgroundColor(Palette.getDefaultColor());
                                    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        Window window = getWindow();
                                        window.setStatusBarColor(Palette.getDarkerColor(Palette.getDefaultColor()));
                                        context.setTaskDescription(new ActivityManager.TaskDescription(subreddit, ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher)).getBitmap(), colorPicker2.getColor()));

                                    }
                                    title.setBackgroundColor(Palette.getDefaultColor());


                                    int cx = center.getWidth() / 2;
                                    int cy = center.getHeight() / 2;

                                    int initialRadius = body.getWidth();
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                                        Animator anim =
                                                ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);

                                        anim.addListener(new AnimatorListenerAdapter() {
                                            @Override
                                            public void onAnimationEnd(Animator animation) {
                                                super.onAnimationEnd(animation);
                                                body.setVisibility(View.GONE);
                                            }
                                        });
                                        anim.start();

                                    } else {
                                        body.setVisibility(View.GONE);

                                    }

                                }
                            });*/
        }
        // Accent color picker
        final LineColorPicker colorPickerAcc = (LineColorPicker) dialoglayout.findViewById(R.id.picker3);
        {
            // Get all possible accent colors (for day theme)
            int[] arrs = new int[ColorPreferences.getNumColorsFromThemeType(0)];
            int i = 0;
            for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                if (type.getThemeType() == 0) {
                    arrs[i] = ContextCompat.getColor(context, type.getColor());
                    i++;
                }
                colorPickerAcc.setColors(arrs);
                colorPickerAcc.setSelectedColor(currentAccentColor);
            }
        }
        builder.setView(dialoglayout);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof MainActivity) {
                    ((MainActivity) context).updateColor(Palette.getColor(subreddit), subreddit);
                }
            }
        }).setNeutralButton(R.string.btn_reset, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                String subTitles = "";
                if (multipleSubs) {
                    for (String sub : subreddits) {
                        // if the subreddit is the frontpage, don't put "/r/" in front of it
                        if (sub.equals("frontpage")) {
                            subTitles += sub + ", ";
                        } else {
                            subTitles += "/r/" + sub + ", ";
                        }
                    }
                    subTitles = subTitles.substring(0, subTitles.length() - 2);
                } else {
                    // if the subreddit is the frontpage, don't put "/r/" in front of it
                    subTitles = (subreddit.equals("frontpage") ? "frontpage" : "/r/" + subreddit);
                }
                String titleStart = context.getString(R.string.settings_delete_sub_settings, subTitles);
                titleStart = titleStart.replace("/r//r/", "/r/");
                if (titleStart.contains("/r/frontpage")) {
                    titleStart = titleStart.replace("/r/frontpage", "frontpage");
                }
                new AlertDialogWrapper.Builder(context).setTitle(titleStart).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        for (String sub : subreddits) {
                            Palette.removeColor(sub);
                            // Remove layout settings
                            SettingValues.prefs.edit().remove(Reddit.PREF_LAYOUT + sub).apply();
                            // Remove accent / font color settings
                            new ColorPreferences(context).removeFontStyle(sub);
                            SettingValues.resetPicsEnabled(sub);
                            SettingValues.resetSelftextEnabled(sub);
                        }
                        if (context instanceof MainActivity) {
                            ((MainActivity) context).reloadSubs();
                        } else if (context instanceof SettingsSubreddit) {
                            ((SettingsSubreddit) context).reloadSubList();
                        } else if (context instanceof SubredditView) {
                            ((SubredditView) context).restartTheme();
                        }
                    }
                }).setNegativeButton(R.string.btn_no, null).show();
            }
        }).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                final int newPrimaryColor = colorPickerPrimaryShades.getColor();
                final int newAccentColor = colorPickerAcc.getColor();
                for (String sub : subreddits) {
                    // Set main color
                    if (bigPics.isChecked() != SettingValues.isPicsEnabled(sub)) {
                        SettingValues.setPicsEnabled(sub, bigPics.isChecked());
                    }
                    if (selftext.isChecked() != SettingValues.isSelftextEnabled(sub)) {
                        SettingValues.setSelftextEnabled(sub, selftext.isChecked());
                    }
                    // Only do set colors if either subreddit theme color has changed
                    if (Palette.getColor(sub) != newPrimaryColor || Palette.getDarkerColor(sub) != newAccentColor) {
                        if (newPrimaryColor != Palette.getDefaultColor()) {
                            Palette.setColor(sub, newPrimaryColor);
                        } else {
                            Palette.removeColor(sub);
                        }
                        // Set accent color
                        ColorPreferences.Theme t = null;
                        // Do not save accent color if it matches the default accent color
                        if (newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyle().getColor()) || newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyleSubreddit(sub).getColor())) {
                            LogUtil.v("Accent colors not equal");
                            int back = new ColorPreferences(context).getFontStyle().getThemeType();
                            for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                                if (ContextCompat.getColor(context, type.getColor()) == newAccentColor && back == type.getThemeType()) {
                                    t = type;
                                    LogUtil.v("Setting accent color to " + t.getTitle());
                                    break;
                                }
                            }
                        } else {
                            new ColorPreferences(context).removeFontStyle(sub);
                        }
                        if (t != null) {
                            colorPrefs.setFontStyle(t, sub);
                        }
                    }
                    // Set layout
                    SettingValues.prefs.edit().putBoolean(Reddit.PREF_LAYOUT + sub, true).apply();
                }
                // Only refresh stuff if the user changed something
                if (Palette.getColor(subreddit) != newPrimaryColor || Palette.getDarkerColor(subreddit) != newAccentColor) {
                    if (context instanceof MainActivity) {
                        ((MainActivity) context).reloadSubs();
                    } else if (context instanceof SettingsSubreddit) {
                        ((SettingsSubreddit) context).reloadSubList();
                    } else if (context instanceof SubredditView) {
                        ((SubredditView) context).restartTheme();
                    }
                }
            }
        }).show();
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) LineColorPicker(uz.shift.colorpicker.LineColorPicker) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) OnColorChangedListener(uz.shift.colorpicker.OnColorChangedListener) SettingsSubreddit(me.ccrama.redditslide.Activities.SettingsSubreddit) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 4 with SubredditView

use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.

the class PopulateNewsViewHolder method showBottomSheet.

public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final NewsViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.profile, null);
    final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.sub, null);
    Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null);
    Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null);
    final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.report, null);
    Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
    final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.save, null);
    Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.openexternal, null);
    Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.link, null);
    Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null);
    Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.filter, null);
    profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    sub.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    saved.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    link.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    readLater.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    filter.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    ta.recycle();
    final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
    final boolean isReadLater = mContext instanceof PostReadLater;
    final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
        String save = mContext.getString(R.string.btn_save);
        if (ActionStates.isSaved(submission)) {
            save = mContext.getString(R.string.comment_unsave);
        }
        if (Authentication.isLoggedIn) {
            b.sheet(3, saved, save);
        }
    }
    if (isAddedToReadLaterList) {
        b.sheet(28, readLater, "Mark As Read");
    } else {
        b.sheet(28, readLater, "Read later");
    }
    if (Authentication.didOnline) {
        if (Authentication.isLoggedIn) {
            b.sheet(12, report, mContext.getString(R.string.btn_report));
        }
    }
    if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
        b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
    }
    boolean hidden = submission.isHidden();
    if (!full && Authentication.didOnline) {
        if (!hidden) {
            b.sheet(5, hide, mContext.getString(R.string.submission_hide));
        } else {
            b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
        }
    }
    b.sheet(7, open, mContext.getString(R.string.submission_link_extern));
    b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
    if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
        b.sheet(10, filter, mContext.getString(R.string.filter_content));
    }
    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, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 2:
                    {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivityForResult(i, 14);
                    }
                    break;
                case 10:
                    String[] choices;
                    final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
                    if (flair.isEmpty()) {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
                        chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
                        oldChosen = chosen.clone();
                    } else {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
                    }
                    ;
                    chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(baseSub + ":" + flair) };
                    oldChosen = chosen.clone();
                    new AlertDialogWrapper.Builder(mContext).setTitle(R.string.filter_title).alwaysCallMultiChoiceCallback().setMultiChoiceItems(choices, chosen, new DialogInterface.OnMultiChoiceClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            chosen[which] = isChecked;
                        }
                    }).setPositiveButton(R.string.filter_btn, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            boolean filtered = false;
                            SharedPreferences.Editor e = SettingValues.prefs.edit();
                            if (chosen[0] && chosen[0] != oldChosen[0]) {
                                SettingValues.subredditFilters = SettingValues.subredditFilters + ((SettingValues.subredditFilters.isEmpty() || SettingValues.subredditFilters.endsWith(",")) ? "" : ",") + submission.getSubredditName();
                                filtered = true;
                                e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                                PostMatch.subreddits = null;
                            } else if (!chosen[0] && chosen[0] != oldChosen[0]) {
                                SettingValues.subredditFilters = SettingValues.subredditFilters.replace(submission.getSubredditName(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                                e.apply();
                                PostMatch.subreddits = null;
                            }
                            if (chosen[1] && chosen[1] != oldChosen[1]) {
                                SettingValues.userFilters = SettingValues.userFilters + ((SettingValues.userFilters.isEmpty() || SettingValues.userFilters.endsWith(",")) ? "" : ",") + submission.getAuthor();
                                filtered = true;
                                e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                                PostMatch.users = null;
                            } else if (!chosen[1] && chosen[1] != oldChosen[1]) {
                                SettingValues.userFilters = SettingValues.userFilters.replace(submission.getAuthor(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                                e.apply();
                                PostMatch.users = null;
                            }
                            if (chosen[2] && chosen[2] != oldChosen[2]) {
                                SettingValues.domainFilters = SettingValues.domainFilters + ((SettingValues.domainFilters.isEmpty() || SettingValues.domainFilters.endsWith(",")) ? "" : ",") + submission.getDomain();
                                filtered = true;
                                e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                                PostMatch.domains = null;
                            } else if (!chosen[2] && chosen[2] != oldChosen[2]) {
                                SettingValues.domainFilters = SettingValues.domainFilters.replace(submission.getDomain(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                                e.apply();
                                PostMatch.domains = null;
                            }
                            if (chosen[3] && chosen[3] != oldChosen[3]) {
                                SettingValues.alwaysExternal = SettingValues.alwaysExternal + ((SettingValues.alwaysExternal.isEmpty() || SettingValues.alwaysExternal.endsWith(",")) ? "" : ",") + submission.getDomain();
                                e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                                e.apply();
                            } else if (!chosen[3] && chosen[3] != oldChosen[3]) {
                                SettingValues.alwaysExternal = SettingValues.alwaysExternal.replace(submission.getDomain(), "");
                                e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                                e.apply();
                            }
                            if (chosen.length > 4) {
                                if (chosen[4] && chosen[4] != oldChosen[4]) {
                                    SettingValues.flairFilters = SettingValues.flairFilters + ((SettingValues.flairFilters.isEmpty() || SettingValues.flairFilters.endsWith(",")) ? "" : ",") + (baseSub + ":" + flair);
                                    e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                    e.apply();
                                    PostMatch.flairs = null;
                                    filtered = true;
                                } else if (!chosen[4] && chosen[4] != oldChosen[4]) {
                                    SettingValues.flairFilters = SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).replace((baseSub + ":" + flair).toLowerCase(Locale.ENGLISH), "");
                                    e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                    e.apply();
                                    PostMatch.flairs = null;
                                }
                            }
                            if (filtered) {
                                e.apply();
                                PostMatch.domains = null;
                                PostMatch.subreddits = null;
                                PostMatch.users = null;
                                ArrayList<Contribution> toRemove = new ArrayList<>();
                                for (Contribution s : posts) {
                                    if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
                                        toRemove.add(s);
                                    }
                                }
                                OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
                                for (Contribution remove : toRemove) {
                                    final int pos = posts.indexOf(remove);
                                    posts.remove(pos);
                                    if (baseSub != null) {
                                        s.hideMulti(pos);
                                    }
                                }
                                s.writeToMemoryNoStorage();
                                recyclerview.getAdapter().notifyDataSetChanged();
                            }
                        }
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                    break;
                case 5:
                    {
                        hideSubmission(submission, posts, baseSub, recyclerview, mContext);
                    }
                    break;
                case 7:
                    LinkUtil.openExternally(submission.getUrl(), mContext);
                    if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
                    // Do nothing if the post is NSFW and storeNSFWHistory is not enabled
                    } else if (SettingValues.storeHistory) {
                        HasSeen.addSeen(submission.getFullName());
                    }
                    break;
                case 28:
                    if (!isAddedToReadLaterList) {
                        ReadLater.setReadLater(submission, true);
                        Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
                        View view = s.getView();
                        TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ReadLater.setReadLater(submission, false);
                                Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                                View view2 = s2.getView();
                                TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
                                tv2.setTextColor(Color.WHITE);
                                s2.show();
                            }
                        });
                        if (NetworkUtil.isConnected(mContext)) {
                            new CommentCacheAsync(Arrays.asList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                        s.show();
                    } else {
                        ReadLater.setReadLater(submission, false);
                        if (isReadLater || !Authentication.didOnline) {
                            final int pos = posts.indexOf(submission);
                            posts.remove(submission);
                            recyclerview.getAdapter().notifyItemRemoved(holder.getAdapterPosition());
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
                            tv2.setTextColor(Color.WHITE);
                            s2.setAction(R.string.btn_undo, new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    posts.add(pos, (T) submission);
                                    recyclerview.getAdapter().notifyDataSetChanged();
                                }
                            });
                        } else {
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = (TextView) view2.findViewById(android.support.design.R.id.snackbar_text);
                            s2.show();
                        }
                        OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
                    }
                    break;
                case 4:
                    Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
                    break;
                case 12:
                    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_post).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 AsyncTask<Void, Void, Void>() {

                                @Override
                                protected Void doInBackground(Void... params) {
                                    try {
                                        new AccountManager(Authentication.reddit).report(submission, reportReason);
                                    } catch (ApiException e) {
                                        e.printStackTrace();
                                    }
                                    return null;
                                }

                                @Override
                                protected void onPostExecute(Void aVoid) {
                                    if (holder.itemView != null) {
                                        try {
                                            Snackbar s = Snackbar.make(holder.itemView, R.string.msg_report_sent, Snackbar.LENGTH_SHORT);
                                            View view = s.getView();
                                            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                                            tv.setTextColor(Color.WHITE);
                                            s.show();
                                        } catch (Exception ignored) {
                                        }
                                    }
                                }
                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                    }).show();
                    break;
                case 8:
                    Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), "https://reddit.com" + submission.getPermalink(), mContext);
                    break;
                case 6:
                    {
                        ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Link", submission.getUrl());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                    }
                    break;
                case 25:
                    final TextView showText = new TextView(mContext);
                    showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                    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 SELECTED", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                            if (!selected.isEmpty()) {
                                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                ClipData clip = ClipData.newPlainText("Selftext", selected);
                                clipboard.setPrimaryClip(clip);
                                Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                            } else {
                                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                                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("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                        }
                    }).show();
                    break;
            }
        }
    });
    b.show();
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) 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) DialogAction(com.afollestad.materialdialogs.DialogAction) AccountManager(net.dean.jraw.managers.AccountManager) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ClipData(android.content.ClipData) Contribution(net.dean.jraw.models.Contribution) Snackbar(android.support.design.widget.Snackbar) ApiException(net.dean.jraw.ApiException)

Example 5 with SubredditView

use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.

the class PopulateSubmissionViewHolder method showBottomSheet.

public <T extends Contribution> void showBottomSheet(final Activity mContext, final Submission submission, final SubmissionViewHolder holder, final List<T> posts, final String baseSub, final RecyclerView recyclerview, final boolean full) {
    int[] attrs = new int[] { R.attr.tintColor };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    int color = ta.getColor(0, Color.WHITE);
    Drawable profile = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.profile, null);
    final Drawable sub = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.sub, null);
    Drawable saved = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.iconstarfilled, null);
    Drawable hide = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.hide, null);
    final Drawable report = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.report, null);
    Drawable copy = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_content_copy, null);
    final Drawable readLater = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.save, null);
    Drawable open = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.openexternal, null);
    Drawable link = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.link, null);
    Drawable reddit = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.commentchange, null);
    Drawable filter = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.filter, null);
    Drawable crosspost = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.forward, null);
    profile.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    sub.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    saved.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    hide.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    report.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    open.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    link.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    reddit.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    readLater.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    filter.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    crosspost.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    ta.recycle();
    final BottomSheet.Builder b = new BottomSheet.Builder(mContext).title(Html.fromHtml(submission.getTitle()));
    final boolean isReadLater = mContext instanceof PostReadLater;
    final boolean isAddedToReadLaterList = ReadLater.isToBeReadLater(submission);
    if (Authentication.didOnline) {
        b.sheet(1, profile, "/u/" + submission.getAuthor()).sheet(2, sub, "/r/" + submission.getSubredditName());
        String save = mContext.getString(R.string.btn_save);
        if (ActionStates.isSaved(submission)) {
            save = mContext.getString(R.string.comment_unsave);
        }
        if (Authentication.isLoggedIn) {
            b.sheet(3, saved, save);
        }
    }
    if (isAddedToReadLaterList) {
        b.sheet(28, readLater, "Mark As Read");
    } else {
        b.sheet(28, readLater, "Read later");
    }
    if (Authentication.didOnline) {
        if (Authentication.isLoggedIn) {
            b.sheet(12, report, mContext.getString(R.string.btn_report));
            b.sheet(13, crosspost, mContext.getString(R.string.btn_crosspost));
        }
    }
    if (submission.getSelftext() != null && !submission.getSelftext().isEmpty() && full) {
        b.sheet(25, copy, mContext.getString(R.string.submission_copy_text));
    }
    boolean hidden = submission.isHidden();
    if (!full && Authentication.didOnline) {
        if (!hidden) {
            b.sheet(5, hide, mContext.getString(R.string.submission_hide));
        } else {
            b.sheet(5, hide, mContext.getString(R.string.submission_unhide));
        }
    }
    b.sheet(7, open, mContext.getString(R.string.submission_link_extern));
    b.sheet(4, link, mContext.getString(R.string.submission_share_permalink)).sheet(8, reddit, mContext.getString(R.string.submission_share_reddit_url));
    if ((mContext instanceof MainActivity) || (mContext instanceof SubredditView)) {
        b.sheet(10, filter, mContext.getString(R.string.filter_content));
    }
    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, submission.getAuthor());
                        mContext.startActivity(i);
                    }
                    break;
                case 2:
                    {
                        Intent i = new Intent(mContext, SubredditView.class);
                        i.putExtra(SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                        mContext.startActivityForResult(i, 14);
                    }
                    break;
                case 10:
                    String[] choices;
                    final String flair = submission.getSubmissionFlair().getText() != null ? submission.getSubmissionFlair().getText() : "";
                    if (flair.isEmpty()) {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()) };
                        chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)) };
                        oldChosen = chosen.clone();
                    } else {
                        choices = new String[] { mContext.getString(R.string.filter_posts_sub, submission.getSubredditName()), mContext.getString(R.string.filter_posts_user, submission.getAuthor()), mContext.getString(R.string.filter_posts_urls, submission.getDomain()), mContext.getString(R.string.filter_open_externally, submission.getDomain()), mContext.getString(R.string.filter_posts_flair, flair, baseSub) };
                    }
                    chosen = new boolean[] { Arrays.asList(SettingValues.subredditFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getSubredditName().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.userFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getAuthor().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.domainFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.alwaysExternal.toLowerCase(Locale.ENGLISH).split(",")).contains(submission.getDomain().toLowerCase(Locale.ENGLISH)), Arrays.asList(SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).split(",")).contains(baseSub + ":" + flair) };
                    oldChosen = chosen.clone();
                    new AlertDialogWrapper.Builder(mContext).setTitle(R.string.filter_title).alwaysCallMultiChoiceCallback().setMultiChoiceItems(choices, chosen, new DialogInterface.OnMultiChoiceClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            chosen[which] = isChecked;
                        }
                    }).setPositiveButton(R.string.filter_btn, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            boolean filtered = false;
                            SharedPreferences.Editor e = SettingValues.prefs.edit();
                            if (chosen[0] && chosen[0] != oldChosen[0]) {
                                SettingValues.subredditFilters = SettingValues.subredditFilters + ((SettingValues.subredditFilters.isEmpty() || SettingValues.subredditFilters.endsWith(",")) ? "" : ",") + submission.getSubredditName();
                                filtered = true;
                                e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                                PostMatch.subreddits = null;
                            } else if (!chosen[0] && chosen[0] != oldChosen[0]) {
                                SettingValues.subredditFilters = SettingValues.subredditFilters.replace(submission.getSubredditName(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_SUBREDDIT_FILTERS, SettingValues.subredditFilters);
                                e.apply();
                                PostMatch.subreddits = null;
                            }
                            if (chosen[1] && chosen[1] != oldChosen[1]) {
                                SettingValues.userFilters = SettingValues.userFilters + ((SettingValues.userFilters.isEmpty() || SettingValues.userFilters.endsWith(",")) ? "" : ",") + submission.getAuthor();
                                filtered = true;
                                e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                                PostMatch.users = null;
                            } else if (!chosen[1] && chosen[1] != oldChosen[1]) {
                                SettingValues.userFilters = SettingValues.userFilters.replace(submission.getAuthor(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_USER_FILTERS, SettingValues.userFilters);
                                e.apply();
                                PostMatch.users = null;
                            }
                            if (chosen[2] && chosen[2] != oldChosen[2]) {
                                SettingValues.domainFilters = SettingValues.domainFilters + ((SettingValues.domainFilters.isEmpty() || SettingValues.domainFilters.endsWith(",")) ? "" : ",") + submission.getDomain();
                                filtered = true;
                                e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                                PostMatch.domains = null;
                            } else if (!chosen[2] && chosen[2] != oldChosen[2]) {
                                SettingValues.domainFilters = SettingValues.domainFilters.replace(submission.getDomain(), "");
                                filtered = false;
                                e.putString(SettingValues.PREF_DOMAIN_FILTERS, SettingValues.domainFilters);
                                e.apply();
                                PostMatch.domains = null;
                            }
                            if (chosen[3] && chosen[3] != oldChosen[3]) {
                                SettingValues.alwaysExternal = SettingValues.alwaysExternal + ((SettingValues.alwaysExternal.isEmpty() || SettingValues.alwaysExternal.endsWith(",")) ? "" : ",") + submission.getDomain();
                                e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                                e.apply();
                            } else if (!chosen[3] && chosen[3] != oldChosen[3]) {
                                SettingValues.alwaysExternal = SettingValues.alwaysExternal.replace(submission.getDomain(), "");
                                e.putString(SettingValues.PREF_ALWAYS_EXTERNAL, SettingValues.alwaysExternal);
                                e.apply();
                            }
                            if (chosen.length > 4) {
                                if (chosen[4] && chosen[4] != oldChosen[4]) {
                                    SettingValues.flairFilters = SettingValues.flairFilters + ((SettingValues.flairFilters.isEmpty() || SettingValues.flairFilters.endsWith(",")) ? "" : ",") + (baseSub + ":" + flair);
                                    e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                    e.apply();
                                    PostMatch.flairs = null;
                                    filtered = true;
                                } else if (!chosen[4] && chosen[4] != oldChosen[4]) {
                                    SettingValues.flairFilters = SettingValues.flairFilters.toLowerCase(Locale.ENGLISH).replace((baseSub + ":" + flair).toLowerCase(Locale.ENGLISH), "");
                                    e.putString(SettingValues.PREF_FLAIR_FILTERS, SettingValues.flairFilters);
                                    e.apply();
                                    PostMatch.flairs = null;
                                }
                            }
                            if (filtered) {
                                e.apply();
                                PostMatch.domains = null;
                                PostMatch.subreddits = null;
                                PostMatch.users = null;
                                ArrayList<Contribution> toRemove = new ArrayList<>();
                                for (Contribution s : posts) {
                                    if (s instanceof Submission && PostMatch.doesMatch((Submission) s)) {
                                        toRemove.add(s);
                                    }
                                }
                                OfflineSubreddit s = OfflineSubreddit.getSubreddit(baseSub, false, mContext);
                                for (Contribution remove : toRemove) {
                                    final int pos = posts.indexOf(remove);
                                    posts.remove(pos);
                                    if (baseSub != null) {
                                        s.hideMulti(pos);
                                    }
                                }
                                s.writeToMemoryNoStorage();
                                recyclerview.getAdapter().notifyDataSetChanged();
                            }
                        }
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                    break;
                case 3:
                    saveSubmission(submission, mContext, holder, full);
                    break;
                case 5:
                    {
                        hideSubmission(submission, posts, baseSub, recyclerview, mContext);
                    }
                    break;
                case 7:
                    LinkUtil.openExternally(submission.getUrl(), mContext);
                    if (submission.isNsfw() && !SettingValues.storeNSFWHistory) {
                    // Do nothing if the post is NSFW and storeNSFWHistory is not enabled
                    } else if (SettingValues.storeHistory) {
                        HasSeen.addSeen(submission.getFullName());
                    }
                    break;
                case 13:
                    LinkUtil.crosspost(submission, mContext);
                    break;
                case 28:
                    if (!isAddedToReadLaterList) {
                        ReadLater.setReadLater(submission, true);
                        Snackbar s = Snackbar.make(holder.itemView, "Added to read later!", Snackbar.LENGTH_SHORT);
                        View view = s.getView();
                        TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.setAction(R.string.btn_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                ReadLater.setReadLater(submission, false);
                                Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                                View view2 = s2.getView();
                                TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
                                tv2.setTextColor(Color.WHITE);
                                s2.show();
                            }
                        });
                        if (NetworkUtil.isConnected(mContext)) {
                            new CommentCacheAsync(Arrays.asList(submission), mContext, CommentCacheAsync.SAVED_SUBMISSIONS, new boolean[] { true, true }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                        s.show();
                    } else {
                        ReadLater.setReadLater(submission, false);
                        if (isReadLater || !Authentication.didOnline) {
                            final int pos = posts.indexOf(submission);
                            posts.remove(submission);
                            recyclerview.getAdapter().notifyItemRemoved(holder.getAdapterPosition());
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
                            tv2.setTextColor(Color.WHITE);
                            s2.setAction(R.string.btn_undo, new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    posts.add(pos, (T) submission);
                                    recyclerview.getAdapter().notifyDataSetChanged();
                                }
                            });
                        } else {
                            Snackbar s2 = Snackbar.make(holder.itemView, "Removed from read later", Snackbar.LENGTH_SHORT);
                            View view2 = s2.getView();
                            TextView tv2 = view2.findViewById(android.support.design.R.id.snackbar_text);
                            s2.show();
                        }
                        OfflineSubreddit.newSubreddit(CommentCacheAsync.SAVED_SUBMISSIONS).deleteFromMemory(submission.getFullName());
                    }
                    break;
                case 4:
                    Reddit.defaultShareText(Html.fromHtml(submission.getTitle()).toString(), StringEscapeUtils.escapeHtml4(submission.getUrl()), mContext);
                    break;
                case 12:
                    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_post).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 AsyncTask<Void, Void, Void>() {

                                @Override
                                protected Void doInBackground(Void... params) {
                                    try {
                                        new AccountManager(Authentication.reddit).report(submission, reportReason);
                                    } catch (ApiException e) {
                                        e.printStackTrace();
                                    }
                                    return null;
                                }

                                @Override
                                protected void onPostExecute(Void aVoid) {
                                    if (holder.itemView != null) {
                                        try {
                                            Snackbar s = Snackbar.make(holder.itemView, R.string.msg_report_sent, Snackbar.LENGTH_SHORT);
                                            View view = s.getView();
                                            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                            tv.setTextColor(Color.WHITE);
                                            s.show();
                                        } catch (Exception ignored) {
                                        }
                                    }
                                }
                            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        }
                    }).show();
                    break;
                case 8:
                    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 6:
                    {
                        ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Link", submission.getUrl());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.submission_link_copied, Toast.LENGTH_SHORT).show();
                    }
                    break;
                case 25:
                    final TextView showText = new TextView(mContext);
                    showText.setText(StringEscapeUtils.unescapeHtml4(submission.getTitle() + "\n\n" + submission.getSelftext()));
                    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 SELECTED", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
                            if (!selected.isEmpty()) {
                                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                ClipData clip = ClipData.newPlainText("Selftext", selected);
                                clipboard.setPrimaryClip(clip);
                                Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                            } else {
                                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                                ClipData clip = ClipData.newPlainText("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                                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("Selftext", Html.fromHtml(submission.getTitle() + "\n\n" + submission.getSelftext()));
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(mContext, R.string.submission_comment_copied, Toast.LENGTH_SHORT).show();
                        }
                    }).show();
                    break;
            }
        }
    });
    b.show();
}
Also used : DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) PostReadLater(me.ccrama.redditslide.Activities.PostReadLater) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) ClipboardManager(android.content.ClipboardManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) ApiException(net.dean.jraw.ApiException) DialogAction(com.afollestad.materialdialogs.DialogAction) AccountManager(net.dean.jraw.managers.AccountManager) BottomSheet(com.cocosw.bottomsheet.BottomSheet) ClipData(android.content.ClipData) Contribution(net.dean.jraw.models.Contribution) Snackbar(android.support.design.widget.Snackbar) ApiException(net.dean.jraw.ApiException)

Aggregations

TextView (android.widget.TextView)9 MainActivity (me.ccrama.redditslide.Activities.MainActivity)9 SubredditView (me.ccrama.redditslide.Activities.SubredditView)9 Intent (android.content.Intent)8 Snackbar (android.support.design.widget.Snackbar)8 RecyclerView (android.support.v7.widget.RecyclerView)8 View (android.view.View)8 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)8 DialogInterface (android.content.DialogInterface)7 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)7 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)6 Handler (android.os.Handler)4 ImageView (android.widget.ImageView)4 MediaView (me.ccrama.redditslide.Activities.MediaView)4 OnSingleClickListener (me.ccrama.redditslide.util.OnSingleClickListener)4 ApiException (net.dean.jraw.ApiException)4 Submission (net.dean.jraw.models.Submission)4 ColorPreferences (me.ccrama.redditslide.ColorPreferences)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2