Search in sources :

Example 1 with Submission

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

the class MultiredditOverview method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            try {
                onBackPressed();
            } catch (Exception ignored) {
            }
            return true;
        case R.id.action_edit:
            {
                if (profile.isEmpty() && (UserSubscriptions.multireddits != null) && !UserSubscriptions.multireddits.isEmpty()) {
                    Intent i = new Intent(MultiredditOverview.this, CreateMulti.class);
                    i.putExtra(CreateMulti.EXTRA_MULTI, UserSubscriptions.multireddits.get(pager.getCurrentItem()).getDisplayName());
                    startActivity(i);
                }
            }
            return true;
        case R.id.search:
            {
                UserSubscriptions.MultiCallback m = new UserSubscriptions.MultiCallback() {

                    @Override
                    public void onComplete(List<MultiReddit> multireddits) {
                        if ((multireddits != null) && !multireddits.isEmpty()) {
                            searchMulti = multireddits.get(pager.getCurrentItem());
                            MaterialDialog.Builder builder = new MaterialDialog.Builder(MultiredditOverview.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
                            builder.positiveText(getString(R.string.search_subreddit, "/m/" + searchMulti.getDisplayName())).onPositive(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                                    Intent i = new Intent(MultiredditOverview.this, Search.class);
                                    i.putExtra(Search.EXTRA_TERM, term);
                                    i.putExtra(Search.EXTRA_MULTIREDDIT, searchMulti.getDisplayName());
                                    startActivity(i);
                                }
                            });
                            builder.show();
                        }
                    }
                };
                if (profile.isEmpty()) {
                    UserSubscriptions.getMultireddits(m);
                } else {
                    UserSubscriptions.getPublicMultireddits(m, profile);
                }
            }
            return true;
        case R.id.create:
            if (profile.isEmpty()) {
                Intent i2 = new Intent(MultiredditOverview.this, CreateMulti.class);
                startActivity(i2);
            }
            return true;
        case R.id.action_sort:
            openPopup();
            return true;
        case R.id.subs:
            ((DrawerLayout) findViewById(R.id.drawer_layout)).openDrawer(Gravity.RIGHT);
            return true;
        case R.id.gallery:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Gallery.class);
                    i2.putExtra(Gallery.EXTRA_PROFILE, profile);
                    i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
                    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 = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i2 = new Intent(MultiredditOverview.this, Gallery.class);
                                i2.putExtra(Gallery.EXTRA_PROFILE, profile);
                                i2.putExtra(Gallery.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
                                startActivity(i2);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        case R.id.action_shadowbox:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i = new Intent(this, Shadowbox.class);
                    i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                    i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
                    i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
                    startActivity(i);
                }
            } 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 && adapter != null && ((MultiredditView) adapter.getCurrentFragment()).posts != null && ((MultiredditView) adapter.getCurrentFragment()).posts.posts != null && !((MultiredditView) adapter.getCurrentFragment()).posts.posts.isEmpty()) {
                    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 = ((MultiredditView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i = new Intent(MultiredditOverview.this, Shadowbox.class);
                                i.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                                i.putExtra(Shadowbox.EXTRA_PROFILE, profile);
                                i.putExtra(Shadowbox.EXTRA_MULTIREDDIT, ((MultiredditView) adapter.getCurrentFragment()).posts.multiReddit.getDisplayName());
                                startActivity(i);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        default:
            return false;
    }
}
Also used : DialogInterface(android.content.DialogInterface) MultiReddit(net.dean.jraw.models.MultiReddit) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) NonNull(android.support.annotation.NonNull) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DrawerLayout(android.support.v4.widget.DrawerLayout) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) ActivityNotFoundException(android.content.ActivityNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView)

Example 2 with Submission

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

the class SubredditView method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
        case R.id.filter:
            filterContent(subreddit);
            return true;
        case R.id.submit:
            Intent i = new Intent(this, Submit.class);
            if (canSubmit)
                i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
            startActivity(i);
            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 = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                tv.setTextColor(Color.WHITE);
                s.show();
            } else {
                openPopup();
            }
            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 {
                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();
                    }
                }).show();
            }
            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();
                }
            }).neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                    Intent i = new Intent(SubredditView.this, Search.class);
                    i.putExtra(Search.EXTRA_TERM, term);
                    startActivity(i);
                }
            });
            // Add "search current sub" if it is not frontpage/all/random
            if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equals("myrandom") && !subreddit.equals("randnsfw") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod")) {
                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(SubredditView.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.show();
            return true;
        case R.id.sidebar:
            drawerLayout.openDrawer(Gravity.RIGHT);
            return true;
        case R.id.hide_posts:
            ((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
            return true;
        case R.id.action_shadowbox:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((SubmissionsView) ((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Shadowbox.class);
                    i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                    i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                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();
                    }
                }).show();
            }
            return true;
        default:
            return false;
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Snackbar(android.support.design.widget.Snackbar)

Example 3 with Submission

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

the class ModeratorAdapter method onBindViewHolder.

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

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

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

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

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

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

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

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

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

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

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

                @Override
                public void onSingleClick(View v) {
                    showModBottomSheet(mContext, comment, holder, reports, reports2);
                }
            });
        } else {
            holder.itemView.findViewById(R.id.mod).setVisibility(View.GONE);
        }
        if (comment.getSubredditName() != null) {
            String subname = comment.getSubredditName();
            SpannableStringBuilder subreddit = new SpannableStringBuilder("/r/" + subname);
            if ((SettingValues.colorSubName && Palette.getColor(subname) != Palette.getDefaultColor())) {
                subreddit.setSpan(new ForegroundColorSpan(Palette.getColor(subname)), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                subreddit.setSpan(new StyleSpan(Typeface.BOLD), 0, subreddit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            titleString.append(subreddit);
        }
        holder.time.setText(titleString);
        setViews(comment.getDataNode().get("body_html").asText(), comment.getSubredditName(), holder);
        if (comment.getTimesGilded() > 0) {
            holder.gild.setVisibility(View.VISIBLE);
            ((TextView) holder.gild).setText(Integer.toString(comment.getTimesGilded()));
        } else if (holder.gild.getVisibility() == View.VISIBLE)
            holder.gild.setVisibility(View.GONE);
        if (comment.getSubmissionTitle() != null)
            holder.title.setText(Html.fromHtml(comment.getSubmissionTitle()));
        else
            holder.title.setText(Html.fromHtml(comment.getAuthor()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {

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

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

Example 4 with Submission

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

the class SubmissionAdapter method onBindViewHolder.

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

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

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

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

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

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

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

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

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

Example 5 with Submission

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

the class SubredditPosts method doMainActivityOffline.

public void doMainActivityOffline(final Context c, final SubmissionDisplay displayer) {
    LogUtil.v(subreddit);
    if (all == null) {
        all = OfflineSubreddit.getAll(subreddit);
    }
    // Move 0, or "submission only", to the end
    Collections.rotate(all, -1);
    offline = true;
    final String[] titles = new String[all.size()];
    final String[] base = new String[all.size()];
    int i = 0;
    for (String s : all) {
        String[] split = s.split(",");
        titles[i] = (Long.valueOf(split[1]) == 0 ? c.getString(R.string.settings_backup_submission_only) : TimeUtils.getTimeAgo(Long.valueOf(split[1]), c) + c.getString(R.string.settings_backup_comments));
        base[i] = s;
        i++;
    }
    ((MainActivity) c).getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ((MainActivity) c).getSupportActionBar().setListNavigationCallbacks(new OfflineSubAdapter(c, android.R.layout.simple_list_item_1, titles), new ActionBar.OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            final String[] s2 = base[itemPosition].split(",");
            OfflineSubreddit.currentid = Long.valueOf(s2[1]);
            currentid = OfflineSubreddit.currentid;
            new AsyncTask<Void, Void, Void>() {

                OfflineSubreddit cached;

                @Override
                protected Void doInBackground(Void... params) {
                    cached = OfflineSubreddit.getSubreddit(subreddit, Long.valueOf(s2[1]), true, c);
                    List<Submission> finalSubs = new ArrayList<>();
                    for (Submission s : cached.submissions) {
                        if (!PostMatch.doesMatch(s, subreddit, force18)) {
                            finalSubs.add(s);
                        }
                    }
                    posts = finalSubs;
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    if (cached.submissions.isEmpty()) {
                        displayer.updateOfflineError();
                    }
                    // update offline
                    displayer.updateOffline(posts, Long.valueOf(s2[1]));
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        }
    });
}
Also used : Submission(net.dean.jraw.models.Submission) AsyncTask(android.os.AsyncTask) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) ArrayList(java.util.ArrayList) ActionBar(android.support.v7.app.ActionBar)

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