Search in sources :

Example 21 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final String subreddit = usedArray.get(Reddit.currentPosition);
    switch(item.getItemId()) {
        case R.id.filter:
            filterContent(shouldLoad);
            return true;
        case R.id.sidebar:
            if (!subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.contains(".") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
                drawerLayout.openDrawer(GravityCompat.END);
            } else {
                Toast.makeText(this, R.string.sidebar_notfound, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.night:
            {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(MainActivity.this);
                final TextView title = dialoglayout.findViewById(R.id.title);
                title.setBackgroundColor(Palette.getDefaultColor());
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                back = new ColorPreferences(MainActivity.this).getFontStyle().getThemeType();
                if (SettingValues.isNight()) {
                    dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
                }
                dialoglayout.findViewById(R.id.black).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 2) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.blacklighter).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 4) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.deep).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 8) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.sepia).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 5) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.pixel).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 7) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.red).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 6) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.light).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 1) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.dark).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 0) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.blue).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 3) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
            }
            return true;
        case R.id.action_refresh:
            if (adapter != null && adapter.getCurrentFragment() != null) {
                ((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
            }
            return true;
        case R.id.action_sort:
            if (subreddit.equalsIgnoreCase("friends")) {
                Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
                View view = s.getView();
                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                tv.setTextColor(Color.WHITE);
                s.show();
            } else {
                openPopup();
            }
            return true;
        case R.id.search:
            MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {

                @Override
                public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
                    term = charSequence.toString();
                }
            });
            // Add "search current sub" if it is not frontpage/all/random
            if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.contains(".") && !subreddit.contains("/m/") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equalsIgnoreCase("myrandom") && !subreddit.equalsIgnoreCase("randnsfw")) {
                builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
                        Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
                        startActivity(i);
                    }
                });
                builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            } else {
                builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            }
            builder.show();
            return true;
        case R.id.save:
            saveOffline(((SubmissionsView) adapter.getCurrentFragment()).posts.posts, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
            return true;
        case R.id.hide_posts:
            ((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
            return true;
        case R.id.share:
            Reddit.defaultShareText("Slide for Reddit", "https://play.google.com/store/apps/details?id=me.ccrama.redditslide", MainActivity.this);
            return true;
        case R.id.submit:
            {
                Intent i = new Intent(MainActivity.this, Submit.class);
                i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
                startActivity(i);
            }
            return true;
        case R.id.gallery:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Gallery.class);
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_gallerymode_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
                if (SettingValues.previews > 0) {
                    b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                            SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                            List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i2 = new Intent(MainActivity.this, Gallery.class);
                                i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                                i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                                startActivity(i2);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        case R.id.action_shadowbox:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Shadowbox.class);
                    i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_shadowbox_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
                if (SettingValues.previews > 0) {
                    b.setNeutralButton("Preview (" + SettingValues.previews + ")", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                            SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                            List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i2 = new Intent(MainActivity.this, Shadowbox.class);
                                i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                                i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                                i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                                startActivity(i2);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        default:
            return false;
    }
}
Also used : DialogInterface(android.content.DialogInterface) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) List(java.util.List) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Snackbar(android.support.design.widget.Snackbar)

Example 22 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class MultiredditAdapter 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, "multi" + dataSet.multiReddit.getDisplayName(), true);
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (Authentication.didOnline || submission.getComments() != null) {
                    holder.title.setAlpha(0.65f);
                    holder.leadImage.setAlpha(0.65f);
                    holder.thumbimage.setAlpha(0.65f);
                    Intent i2 = new Intent(context, CommentsScreen.class);
                    i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
                    i2.putExtra(CommentsScreen.EXTRA_MULTIREDDIT, dataSet.multiReddit.getDisplayName());
                    context.startActivityForResult(i2, 940);
                    i2.putExtra("fullname", submission.getFullName());
                    clicked = holder2.getAdapterPosition();
                } else {
                    Snackbar s = Snackbar.make(holder.itemView, R.string.offline_comments_not_loaded, 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();
                }
            }
        });
        final boolean saved = submission.isSaved();
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, true, false, "multi" + dataSet.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), null);
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                // the loading spinner to replaced by nomoreposts.xml
                notifyItemChanged(dataSet.posts.size() + 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) {
                    dataSet.loadMore(context, baseView, true, MultiredditAdapter.this);
                }
            });
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        final int height = (context).findViewById(R.id.header).getHeight();
        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 : CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Example 23 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class HeaderImageLinkView method doImageAndText.

public void doImageAndText(final Submission submission, boolean full, String baseSub, boolean news) {
    boolean fullImage = ContentType.fullImage(type);
    thumbUsed = false;
    setVisibility(View.VISIBLE);
    String url = "";
    boolean forceThumb = false;
    thumbImage2.setImageResource(android.R.color.transparent);
    boolean loadLq = (((!NetworkUtil.isConnectedWifi(getContext()) && SettingValues.lowResMobile) || SettingValues.lowResAlways));
    if (type == ContentType.Type.SELF && SettingValues.hideSelftextLeadImage || SettingValues.noImages && submission.isSelfPost()) {
        setVisibility(View.GONE);
        if (wrapArea != null)
            wrapArea.setVisibility(View.GONE);
        thumbImage2.setVisibility(View.GONE);
    } else {
        if (submission.getThumbnails() != null) {
            int height = submission.getThumbnails().getSource().getHeight();
            int width = submission.getThumbnails().getSource().getWidth();
            if (full) {
                if (!fullImage && height < dpToPx(50) && type != ContentType.Type.SELF) {
                    forceThumb = true;
                } else if (SettingValues.cropImage) {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                } else {
                    double h = getHeightFromAspectRatio(height, width);
                    if (h != 0) {
                        if (h > 3200) {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                        } else {
                            backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                        }
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                    }
                }
            } else if (SettingValues.bigPicCropped) {
                if (!fullImage && height < dpToPx(50)) {
                    forceThumb = true;
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPx(200)));
                }
            } else if (fullImage || height >= dpToPx(50)) {
                double h = getHeightFromAspectRatio(height, width);
                if (h != 0) {
                    if (h > 3200) {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3200));
                    } else {
                        backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) h));
                    }
                } else {
                    backdrop.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                }
            } else {
                forceThumb = true;
            }
        }
        JsonNode thumbnail = submission.getDataNode().get("thumbnail");
        Submission.ThumbnailType thumbnailType;
        if (!submission.getDataNode().get("thumbnail").isNull()) {
            thumbnailType = submission.getThumbnailType();
        } else {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        JsonNode node = submission.getDataNode();
        if (!SettingValues.ignoreSubSetting && node != null && node.has("sr_detail") && node.get("sr_detail").has("show_media") && !node.get("sr_detail").get("show_media").asBoolean()) {
            thumbnailType = Submission.ThumbnailType.NONE;
        }
        if (SettingValues.noImages && loadLq) {
            setVisibility(View.GONE);
            if (!full && !submission.isSelfPost()) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                if (full && !submission.isSelfPost())
                    wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
        } else if (submission.isNsfw() && SettingValues.getIsNSFWEnabled() || (baseSub != null && submission.isNsfw() && SettingValues.hideNSFWCollection && (baseSub.equals("frontpage") || baseSub.equals("all") || baseSub.contains("+") || baseSub.equals("popular")))) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.nsfw));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (submission.getDataNode().get("spoiler").asBoolean()) {
            setVisibility(View.GONE);
            if (!full || forceThumb) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            if (submission.isSelfPost() && full) {
                wrapArea.setVisibility(View.GONE);
            } else {
                thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.spoiler));
                thumbUsed = true;
            }
            loadedUrl = submission.getUrl();
        } else if (type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && (!thumbnail.isNull() && (thumbnailType != Submission.ThumbnailType.URL)) || thumbnail.asText().isEmpty() && !submission.isSelfPost()) {
            setVisibility(View.GONE);
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            thumbImage2.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.web));
            thumbUsed = true;
            loadedUrl = submission.getUrl();
        } else if (type == ContentType.Type.IMAGE && !thumbnail.isNull() && !thumbnail.asText().isEmpty()) {
            if (loadLq && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    int length = submission.getThumbnails().getVariations().length;
                    if (SettingValues.lqLow && length >= 3) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                    } else if (SettingValues.lqMid && length >= 4) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                    } else if (length >= 5) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                }
                lq = true;
            } else {
                if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
                    // Load the preview image which has probably already been cached in memory instead of the direct link
                    url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                } else {
                    url = submission.getUrl();
                }
            }
            if (!full && !SettingValues.isPicsEnabled(baseSub) || forceThumb) {
                if (!submission.isSelfPost() || full) {
                    if (!full) {
                        thumbImage2.setVisibility(View.VISIBLE);
                    } else {
                        wrapArea.setVisibility(View.VISIBLE);
                    }
                    loadedUrl = url;
                    if (!full) {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                    } else {
                        ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2, bigOptions);
                    }
                } else {
                    thumbImage2.setVisibility(View.GONE);
                }
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (submission.getThumbnails() != null) {
            if (loadLq && submission.getThumbnails().getVariations().length != 0) {
                if (ContentType.isImgurImage(submission.getUrl())) {
                    url = submission.getUrl();
                    url = url.substring(0, url.lastIndexOf(".")) + (SettingValues.lqLow ? "m" : (SettingValues.lqMid ? "l" : "h")) + url.substring(url.lastIndexOf("."), url.length());
                } else {
                    int length = submission.getThumbnails().getVariations().length;
                    if (SettingValues.lqLow && length >= 3) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
                    } else if (SettingValues.lqMid && length >= 4) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
                    } else if (length >= 5) {
                        url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
                    } else {
                        url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
                    }
                }
                lq = true;
            } else {
                url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
            }
            if (!SettingValues.isPicsEnabled(baseSub) && !full || forceThumb || (news && submission.getScore() < 5000)) {
                if (!full) {
                    thumbImage2.setVisibility(View.VISIBLE);
                } else {
                    wrapArea.setVisibility(View.VISIBLE);
                }
                loadedUrl = url;
                ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
                setVisibility(View.GONE);
            } else {
                loadedUrl = url;
                if (!full) {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop);
                } else {
                    ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, backdrop, bigOptions);
                }
                setVisibility(View.VISIBLE);
                if (!full) {
                    thumbImage2.setVisibility(View.GONE);
                } else {
                    wrapArea.setVisibility(View.GONE);
                }
            }
        } else if (!thumbnail.isNull() && submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || (!thumbnail.isNull() && submission.isNsfw() && SettingValues.getIsNSFWEnabled()))) {
            if (!full) {
                thumbImage2.setVisibility(View.VISIBLE);
            } else {
                wrapArea.setVisibility(View.VISIBLE);
            }
            loadedUrl = url;
            ((Reddit) getContext().getApplicationContext()).getImageLoader().displayImage(url, thumbImage2);
            setVisibility(View.GONE);
        } else {
            if (!full) {
                thumbImage2.setVisibility(View.GONE);
            } else {
                wrapArea.setVisibility(View.GONE);
            }
            setVisibility(View.GONE);
        }
        if (full) {
            if (wrapArea.getVisibility() == View.VISIBLE) {
                title = secondTitle;
                info = secondSubTitle;
                setBottomSheet(wrapArea, submission, full);
            } else {
                title = findViewById(R.id.textimage);
                info = findViewById(R.id.subtextimage);
                if (forceThumb || (submission.isNsfw() && submission.getThumbnailType() == Submission.ThumbnailType.NSFW || type != ContentType.Type.IMAGE && type != ContentType.Type.SELF && !submission.getDataNode().get("thumbnail").isNull() && (submission.getThumbnailType() != Submission.ThumbnailType.URL))) {
                    setBottomSheet(thumbImage2, submission, full);
                } else {
                    setBottomSheet(this, submission, full);
                }
            }
        } else {
            title = findViewById(R.id.textimage);
            info = findViewById(R.id.subtextimage);
            setBottomSheet(thumbImage2, submission, full);
            setBottomSheet(this, submission, full);
        }
        if (SettingValues.smallTag && !full && !news) {
            title = (TextView) findViewById(R.id.tag);
            findViewById(R.id.tag).setVisibility(View.VISIBLE);
            info = null;
        } else {
            findViewById(R.id.tag).setVisibility(View.GONE);
            title.setVisibility(View.VISIBLE);
            info.setVisibility(View.VISIBLE);
        }
        if (SettingValues.smallTag && !full && !news) {
            ((TransparentTagTextView) title).init(getContext());
        }
        title.setText(ContentType.getContentDescription(submission, getContext()));
        if (info != null)
            info.setText(submission.getDomain());
    }
}
Also used : Submission(net.dean.jraw.models.Submission) Reddit(me.ccrama.redditslide.Reddit) RelativeLayout(android.widget.RelativeLayout) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransparentTagTextView(me.ccrama.redditslide.Views.TransparentTagTextView)

Example 24 with Submission

use of net.dean.jraw.models.Submission 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 25 with Submission

use of net.dean.jraw.models.Submission 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

Submission (net.dean.jraw.models.Submission)32 Intent (android.content.Intent)15 View (android.view.View)14 DialogInterface (android.content.DialogInterface)10 Snackbar (android.support.design.widget.Snackbar)10 TextView (android.widget.TextView)10 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)10 ArrayList (java.util.ArrayList)10 RecyclerView (android.support.v7.widget.RecyclerView)9 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)9 ImageView (android.widget.ImageView)8 SubredditView (me.ccrama.redditslide.Activities.SubredditView)8 OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)8 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 TypedArray (android.content.res.TypedArray)5 LinearLayout (android.widget.LinearLayout)5 DialogAction (com.afollestad.materialdialogs.DialogAction)5 BottomSheet (com.cocosw.bottomsheet.BottomSheet)5 CommentsScreen (me.ccrama.redditslide.Activities.CommentsScreen)5