Search in sources :

Example 1 with CommentObject

use of me.ccrama.redditslide.Adapters.CommentObject in project Slide by ccrama.

the class CommentPage method doResult.

public void doResult(Intent data) {
    if (data.hasExtra("fullname")) {
        String fullname = data.getExtras().getString("fullname");
        adapter.currentSelectedItem = fullname;
        adapter.reset(getContext(), comments, rv, comments.submission, true);
        adapter.notifyDataSetChanged();
        int i = 2;
        for (CommentObject n : comments.comments) {
            if (n instanceof CommentItem && n.comment.getComment().getFullName().contains(fullname)) {
                ((PreCachingLayoutManagerComments) rv.getLayoutManager()).scrollToPositionWithOffset(i, toolbar.getHeight());
                break;
            }
            i++;
        }
    }
}
Also used : CommentItem(me.ccrama.redditslide.Adapters.CommentItem) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments) CommentObject(me.ccrama.redditslide.Adapters.CommentObject)

Example 2 with CommentObject

use of me.ccrama.redditslide.Adapters.CommentObject in project Slide by ccrama.

the class CommentPage method doGoUp.

public void doGoUp(int old) {
    int depth = -1;
    if (adapter.currentlySelected != null) {
        depth = adapter.currentNode.getDepth();
    }
    int pos = (old < 2) ? 0 : old - 1;
    for (int i = pos - 1; i >= 0; i--) {
        try {
            CommentObject o = adapter.currentComments.get(adapter.getRealPosition(i));
            if (o instanceof CommentItem && pos - 1 != i) {
                boolean matches = false;
                switch(currentSort) {
                    case PARENTS:
                        matches = o.comment.isTopLevel();
                        break;
                    case CHILDREN:
                        if (depth == -1) {
                            matches = o.comment.isTopLevel();
                        } else {
                            matches = o.comment.getDepth() == depth;
                            if (matches) {
                                adapter.currentNode = o.comment;
                                adapter.currentSelectedItem = o.comment.getComment().getFullName();
                            }
                        }
                        break;
                    case TIME:
                        matches = (o.comment.getComment() != null && o.comment.getComment().getCreated().getTime() > sortTime);
                        break;
                    case GILDED:
                        matches = o.comment.getComment().getTimesGilded() > 0;
                        break;
                    case OP:
                        matches = adapter.submission != null && o.comment.getComment().getAuthor().equals(adapter.submission.getAuthor());
                        break;
                    case YOU:
                        matches = adapter.submission != null && o.comment.getComment().getAuthor().equals(Authentication.name);
                        break;
                    case LINK:
                        matches = o.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a");
                        break;
                }
                if (matches) {
                    if (i + 2 == old) {
                        doGoUp(old - 1);
                    } else {
                        (((PreCachingLayoutManagerComments) rv.getLayoutManager())).scrollToPositionWithOffset(i + 2, ((View) toolbar.getParent()).getTranslationY() != 0 ? 0 : (v.findViewById(R.id.header)).getHeight());
                    }
                    break;
                }
            }
        } catch (Exception ignored) {
        }
    }
}
Also used : CommentItem(me.ccrama.redditslide.Adapters.CommentItem) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) IOException(java.io.IOException) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException)

Example 3 with CommentObject

use of me.ccrama.redditslide.Adapters.CommentObject in project Slide by ccrama.

the class CommentPage method doGoDown.

public void doGoDown(int old) {
    int depth = -1;
    if (adapter.currentlySelected != null) {
        depth = adapter.currentNode.getDepth();
    }
    int pos = old - 2;
    if (pos < 0)
        pos = 0;
    String original = adapter.currentComments.get(adapter.getRealPosition(pos)).getName();
    if (old < 2) {
        (((PreCachingLayoutManagerComments) rv.getLayoutManager())).scrollToPositionWithOffset(2, ((View) toolbar.getParent()).getTranslationY() != 0 ? 0 : (v.findViewById(R.id.header).getHeight()));
    } else {
        for (int i = pos + 1; i < adapter.currentComments.size(); i++) {
            try {
                CommentObject o = adapter.currentComments.get(adapter.getRealPosition(i));
                if (o instanceof CommentItem) {
                    boolean matches = false;
                    switch(currentSort) {
                        case PARENTS:
                            matches = o.comment.isTopLevel();
                            break;
                        case CHILDREN:
                            if (depth == -1) {
                                matches = o.comment.isTopLevel();
                            } else {
                                matches = o.comment.getDepth() == depth;
                                if (matches) {
                                    adapter.currentNode = o.comment;
                                    adapter.currentSelectedItem = o.comment.getComment().getFullName();
                                }
                            }
                            break;
                        case TIME:
                            matches = o.comment.getComment().getCreated().getTime() > sortTime;
                            break;
                        case GILDED:
                            matches = o.comment.getComment().getTimesGilded() > 0;
                            break;
                        case OP:
                            matches = adapter.submission != null && o.comment.getComment().getAuthor().equals(adapter.submission.getAuthor());
                            break;
                        case YOU:
                            matches = adapter.submission != null && o.comment.getComment().getAuthor().equals(Authentication.name);
                            break;
                        case LINK:
                            matches = o.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a");
                            break;
                    }
                    if (matches) {
                        if (o.getName().equals(original)) {
                            doGoDown(i + 2);
                        } else {
                            (((PreCachingLayoutManagerComments) rv.getLayoutManager())).scrollToPositionWithOffset(i + 2, ((View) toolbar.getParent()).getTranslationY() != 0 ? 0 : (v.findViewById(R.id.header).getHeight()));
                        }
                        break;
                    }
                }
            } catch (Exception ignored) {
            }
        }
    }
}
Also used : CommentItem(me.ccrama.redditslide.Adapters.CommentItem) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) IOException(java.io.IOException) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException)

Example 4 with CommentObject

use of me.ccrama.redditslide.Adapters.CommentObject in project Slide by ccrama.

the class CommentPage method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
    v = localInflater.inflate(R.layout.fragment_verticalcontenttoolbar, container, false);
    rv = (RecyclerView) v.findViewById(R.id.vertical_content);
    rv.setLayoutManager(mLayoutManager);
    rv.getLayoutManager().scrollToPosition(0);
    toolbar = (Toolbar) v.findViewById(R.id.toolbar);
    toolbar.setPopupTheme(new ColorPreferences(getActivity()).getFontStyle().getBaseId());
    if (!SettingValues.fabComments) {
        v.findViewById(R.id.comment_floating_action_button).setVisibility(View.GONE);
    } else {
        fab = (FloatingActionButton) v.findViewById(R.id.comment_floating_action_button);
        if (SettingValues.fastscroll) {
            FrameLayout.LayoutParams fabs = (FrameLayout.LayoutParams) fab.getLayoutParams();
            fabs.setMargins(fabs.leftMargin, fabs.topMargin, fabs.rightMargin, fabs.bottomMargin * 3);
            fab.setLayoutParams(fabs);
        }
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                LayoutInflater inflater = getActivity().getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.edit_comment, null);
                final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                final EditText e = (EditText) dialoglayout.findViewById(R.id.entry);
                // Tint the replyLine appropriately if the base theme is Light or Sepia
                if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
                    final int TINT = ContextCompat.getColor(getContext(), R.color.md_grey_600);
                    e.setHintTextColor(TINT);
                    e.getBackground().setColorFilter(TINT, PorterDuff.Mode.SRC_IN);
                }
                DoEditorActions.doActions(e, dialoglayout, getActivity().getSupportFragmentManager(), getActivity(), adapter.submission.isSelfPost() ? adapter.submission.getSelftext() : null, new String[] { adapter.submission.getAuthor() });
                builder.setCancelable(false).setView(dialoglayout);
                final Dialog d = builder.create();
                d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                d.show();
                dialoglayout.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        d.dismiss();
                    }
                });
                dialoglayout.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        adapter.dataSet.refreshLayout.setRefreshing(true);
                        new ReplyTaskComment(adapter.submission).execute(e.getText().toString());
                        d.dismiss();
                    }
                });
            }
        });
    }
    if (fab != null)
        fab.show();
    resetScroll(false);
    fastScroll = v.findViewById(R.id.commentnav);
    if (!SettingValues.fastscroll) {
        fastScroll.setVisibility(View.GONE);
    } else {
        v.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.keys != null && adapter.keys.size() > 0) {
                    goDown();
                }
            }
        });
        v.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.keys != null && adapter.keys.size() > 0)
                    goUp();
            }
        });
        v.findViewById(R.id.nav).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (adapter != null && adapter.currentComments != null) {
                    int parentCount, opCount, linkCount, gildCount;
                    parentCount = 0;
                    opCount = 0;
                    linkCount = 0;
                    gildCount = 0;
                    String op = adapter.submission.getAuthor();
                    for (CommentObject o : adapter.currentComments) {
                        if (o.comment != null && !(o instanceof MoreChildItem)) {
                            if (o.comment.isTopLevel())
                                parentCount++;
                            if (o.comment.getComment().getTimesGilded() > 0)
                                gildCount++;
                            if (o.comment.getComment().getAuthor() != null && o.comment.getComment().getAuthor().equals(op)) {
                                opCount++;
                            }
                            if (o.comment.getComment().getDataNode().has("body_html") && o.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a")) {
                                linkCount++;
                            }
                        }
                    }
                    new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.set_nav_mode).setSingleChoiceItems(Reddit.stringToArray("Parent comment (" + parentCount + ")" + "," + "Children comment (highlight child comment & navigate)" + "," + "OP (" + opCount + ")" + "," + "Time" + "," + "Link (" + linkCount + ")" + "," + ((Authentication.isLoggedIn) ? "You" + "," : "") + "Gilded (" + gildCount + ")").toArray(new String[Authentication.isLoggedIn ? 6 : 5]), getCurrentSort(), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch(which) {
                                case 0:
                                    currentSort = CommentNavType.PARENTS;
                                    break;
                                case 1:
                                    currentSort = CommentNavType.CHILDREN;
                                    break;
                                case 2:
                                    currentSort = CommentNavType.OP;
                                    break;
                                case 3:
                                    currentSort = CommentNavType.TIME;
                                    LayoutInflater inflater = getActivity().getLayoutInflater();
                                    final View dialoglayout = inflater.inflate(R.layout.commenttime, null);
                                    final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                                    final Slider landscape = (Slider) dialoglayout.findViewById(R.id.landscape);
                                    final TextView since = (TextView) dialoglayout.findViewById(R.id.time_string);
                                    landscape.setValueRange(60, 18000, false);
                                    landscape.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {

                                        @Override
                                        public void onPositionChanged(Slider slider, boolean b, float v, float v1, int i, int i1) {
                                            Calendar c = Calendar.getInstance();
                                            sortTime = c.getTimeInMillis() - i1 * 1000;
                                            int commentcount = 0;
                                            for (CommentObject o : adapter.currentComments) {
                                                if (o.comment != null && o.comment.getComment().getDataNode().has("created") && o.comment.getComment().getCreated().getTime() > sortTime) {
                                                    commentcount += 1;
                                                }
                                            }
                                            since.setText(TimeUtils.getTimeAgo(sortTime, getActivity()) + " (" + commentcount + " comments)");
                                        }
                                    });
                                    landscape.setValue(600, false);
                                    builder.setView(dialoglayout);
                                    builder.setPositiveButton(R.string.btn_set, null).show();
                                    break;
                                case 5:
                                    currentSort = CommentNavType.YOU;
                                    break;
                                case 4:
                                    currentSort = CommentNavType.LINK;
                                    break;
                                case 6:
                                    currentSort = CommentNavType.GILDED;
                                    break;
                            }
                        }
                    }).show();
                }
            }
        });
    }
    v.findViewById(R.id.up).setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // Scroll to top
            rv.getLayoutManager().scrollToPosition(1);
            return true;
        }
    });
    if (SettingValues.voteGestures) {
        v.findViewById(R.id.up).setOnTouchListener(new OnFlingGestureListener() {

            @Override
            public void onRightToLeft() {
            }

            @Override
            public void onLeftToRight() {
            }

            @Override
            public void onBottomToTop() {
                adapter.submissionViewHolder.upvote.performClick();
                Context context = getContext();
                int duration = Toast.LENGTH_SHORT;
                CharSequence text;
                if (!upvoted) {
                    text = getString(R.string.profile_upvoted);
                    downvoted = false;
                } else {
                    text = getString(R.string.vote_removed);
                }
                upvoted = !upvoted;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }

            @Override
            public void onTopToBottom() {
            }
        });
    }
    if (SettingValues.voteGestures) {
        v.findViewById(R.id.down).setOnTouchListener(new OnFlingGestureListener() {

            @Override
            public void onRightToLeft() {
            }

            @Override
            public void onLeftToRight() {
            }

            @Override
            public void onBottomToTop() {
                adapter.submissionViewHolder.downvote.performClick();
                Context context = getContext();
                int duration = Toast.LENGTH_SHORT;
                CharSequence text;
                if (!downvoted) {
                    text = getString(R.string.profile_downvoted);
                    upvoted = false;
                } else {
                    text = getString(R.string.vote_removed);
                }
                downvoted = !downvoted;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }

            @Override
            public void onTopToBottom() {
            }
        });
    }
    toolbar.setBackgroundColor(Palette.getColor(subreddit));
    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, getActivity()));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (comments != null) {
                comments.loadMore(adapter, subreddit, true);
            } else {
                mSwipeRefreshLayout.setRefreshing(false);
            }
        // TODO catch errors
        }
    });
    toolbar.setTitle(subreddit);
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    toolbar.inflateMenu(R.menu.menu_comment_items);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.search:
                    {
                        if (comments.comments != null && comments.submission != null) {
                            DataShare.sharedComments = comments.comments;
                            DataShare.subAuthor = comments.submission.getAuthor();
                            Intent i = new Intent(getActivity(), CommentSearch.class);
                            if (getActivity() instanceof MainActivity) {
                                getActivity().startActivityForResult(i, 423);
                            } else {
                                startActivityForResult(i, 423);
                            }
                        }
                    }
                    return true;
                case R.id.sidebar:
                    doSidebarOpen();
                    return true;
                case R.id.related:
                    if (adapter.submission.isSelfPost()) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle("Selftext posts have no related submissions").setPositiveButton(R.string.btn_ok, null).show();
                    } else {
                        Intent i = new Intent(getActivity(), Related.class);
                        i.putExtra(Related.EXTRA_URL, adapter.submission.getUrl());
                        startActivity(i);
                    }
                    return true;
                case R.id.shadowbox:
                    if (SettingValues.tabletUI) {
                        if (comments.comments != null && comments.submission != null) {
                            ShadowboxComments.comments = new ArrayList<>();
                            for (CommentObject c : comments.comments) {
                                if (c instanceof CommentItem) {
                                    if (c.comment.getComment().getDataNode().get("body_html").asText().contains("&lt;/a")) {
                                        String body = c.comment.getComment().getDataNode().get("body_html").asText();
                                        String url;
                                        String[] split = body.split("&lt;a href=\"");
                                        if (split.length > 1) {
                                            for (String chunk : split) {
                                                url = chunk.substring(0, chunk.indexOf("\"", 1));
                                                ContentType.Type t = ContentType.getContentType(url);
                                                if (ContentType.mediaType(t)) {
                                                    ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                                }
                                            }
                                        } else {
                                            int start = body.indexOf("&lt;a href=\"");
                                            url = body.substring(start, body.indexOf("\"", start + 1));
                                            ContentType.Type t = ContentType.getContentType(url);
                                            if (ContentType.mediaType(t)) {
                                                ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
                                            }
                                        }
                                    }
                                }
                            }
                            if (!ShadowboxComments.comments.isEmpty()) {
                                Intent i = new Intent(getActivity(), ShadowboxComments.class);
                                startActivity(i);
                            } else {
                                Snackbar.make(mSwipeRefreshLayout, R.string.shadowbox_comments_nolinks, Snackbar.LENGTH_SHORT).show();
                            }
                        }
                    } else {
                        AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(getContext()).setTitle(R.string.general_shadowbox_comments_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();
                            }
                        });
                        b.show();
                    }
                    return true;
                case R.id.sort:
                    {
                        openPopup(toolbar);
                        return true;
                    }
                case R.id.content:
                    {
                        if (adapter != null && adapter.submission != null) {
                            if (!PostMatch.openExternal(adapter.submission.getUrl())) {
                                ContentType.Type type = ContentType.getContentType(adapter.submission);
                                switch(type) {
                                    case VID_ME:
                                    case STREAMABLE:
                                        if (SettingValues.video) {
                                            Intent myIntent = new Intent(getActivity(), MediaView.class);
                                            myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
                                            myIntent.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                            getActivity().startActivity(myIntent);
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case IMGUR:
                                    case XKCD:
                                        Intent i2 = new Intent(getActivity(), MediaView.class);
                                        i2.putExtra(MediaView.SUBREDDIT, subreddit);
                                        if (adapter.submission.getDataNode().has("preview") && adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && type != ContentType.Type.XKCD) {
                                            // Load the preview image which has probably already been cached in memory instead of the direct link
                                            String previewUrl = adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
                                            i2.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
                                        }
                                        i2.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
                                        getActivity().startActivity(i2);
                                        break;
                                    case EMBEDDED:
                                        if (SettingValues.video) {
                                            String data = adapter.submission.getDataNode().get("media_embed").get("content").asText();
                                            {
                                                Intent i = new Intent(getActivity(), FullscreenVideo.class);
                                                i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                                getActivity().startActivity(i);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case REDDIT:
                                        PopulateSubmissionViewHolder.openRedditContent(adapter.submission.getUrl(), getActivity());
                                        break;
                                    case LINK:
                                        LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getColor(adapter.submission.getSubredditName()), getActivity());
                                        break;
                                    case NONE:
                                    case SELF:
                                        if (adapter.submission.getSelftext().isEmpty()) {
                                            Snackbar s = Snackbar.make(rv, R.string.submission_nocontent, 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 {
                                            LayoutInflater inflater = getActivity().getLayoutInflater();
                                            final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
                                            final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity());
                                            adapter.setViews(adapter.submission.getDataNode().get("selftext_html").asText(), adapter.submission.getSubredditName(), (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
                                            builder.setView(dialoglayout);
                                            builder.show();
                                        }
                                        break;
                                    case ALBUM:
                                        if (SettingValues.album) {
                                            if (SettingValues.albumSwipe) {
                                                Intent i = new Intent(getActivity(), AlbumPager.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(AlbumPager.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            } else {
                                                Intent i = new Intent(getActivity(), Album.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(Album.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case TUMBLR:
                                        if (SettingValues.image) {
                                            if (SettingValues.albumSwipe) {
                                                Intent i = new Intent(getActivity(), TumblrPager.class);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                i.putExtra(TumblrPager.SUBREDDIT, subreddit);
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            } else {
                                                Intent i = new Intent(getActivity(), Tumblr.class);
                                                i.putExtra(Tumblr.SUBREDDIT, subreddit);
                                                i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
                                                getActivity().startActivity(i);
                                                getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                        break;
                                    case IMAGE:
                                        PopulateSubmissionViewHolder.openImage(type, getActivity(), adapter.submission, null, -1);
                                        break;
                                    case VREDDIT_REDIRECT:
                                    case VREDDIT_DIRECT:
                                    case GIF:
                                        PopulateSubmissionViewHolder.openGif(getActivity(), adapter.submission, -1);
                                        break;
                                    case VIDEO:
                                        if (Reddit.videoPlugin) {
                                            try {
                                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
                                                sharingIntent.putExtra("url", adapter.submission.getUrl());
                                                getActivity().startActivity(sharingIntent);
                                            } catch (Exception e) {
                                                LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                            }
                                        } else {
                                            LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                                        }
                                }
                            } else {
                                LinkUtil.openExternally(adapter.submission.getUrl(), getActivity());
                            }
                        }
                    }
                    return true;
                case R.id.reload:
                    if (comments != null) {
                        mSwipeRefreshLayout.setRefreshing(true);
                        comments.loadMore(adapter, subreddit);
                    }
                    return true;
                case R.id.collapse:
                    {
                        if (adapter != null) {
                            adapter.collapseAll();
                        }
                    }
                    return true;
                case android.R.id.home:
                    getActivity().onBackPressed();
                    return true;
            }
            return false;
        }
    });
    toolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((LinearLayoutManager) rv.getLayoutManager()).scrollToPositionWithOffset(1, headerHeight);
            resetScroll(false);
        }
    });
    addClickFunctionSubName(toolbar);
    doTopBar();
    if (Authentication.didOnline && !NetworkUtil.isConnectedNoOverride(getActivity())) {
        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.err_title).setMessage(R.string.err_connection_failed_msg).setNegativeButton(R.string.btn_close, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!(getActivity() instanceof MainActivity)) {
                    getActivity().finish();
                }
            }
        }).setPositiveButton(R.string.btn_offline, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(getActivity());
            }
        }).show();
    }
    if (!(getActivity() instanceof CommentsScreen) || ((CommentsScreen) getActivity()).currentPage == page) {
        doAdapter(true);
    } else {
        doAdapter(false);
    }
    return v;
}
Also used : ContentType(me.ccrama.redditslide.ContentType) ArrayList(java.util.ArrayList) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) FullscreenVideo(me.ccrama.redditslide.Activities.FullscreenVideo) EditText(android.widget.EditText) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) Related(me.ccrama.redditslide.Activities.Related) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) ActivityNotFoundException(android.content.ActivityNotFoundException) LayoutInflater(android.view.LayoutInflater) CommentUrlObject(me.ccrama.redditslide.Adapters.CommentUrlObject) Snackbar(android.support.design.widget.Snackbar) Slider(com.rey.material.widget.Slider) DialogInterface(android.content.DialogInterface) MainActivity(me.ccrama.redditslide.Activities.MainActivity) Toast(android.widget.Toast) MoreChildItem(me.ccrama.redditslide.Adapters.MoreChildItem) Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Calendar(java.util.Calendar) MenuItem(android.view.MenuItem) Intent(android.content.Intent) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) IOException(java.io.IOException) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) ContentType(me.ccrama.redditslide.ContentType) CommentNavType(me.ccrama.redditslide.Adapters.CommentNavType) ShadowboxComments(me.ccrama.redditslide.Activities.ShadowboxComments) FrameLayout(android.widget.FrameLayout)

Example 5 with CommentObject

use of me.ccrama.redditslide.Adapters.CommentObject in project Slide by ccrama.

the class CommentSearch method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideRedditSwipeAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme();
    setContentView(R.layout.activity_filtercomments);
    final EditText search = (EditText) findViewById(R.id.search);
    RecyclerView rv = (RecyclerView) findViewById(R.id.vertical_content);
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(this);
    rv.setLayoutManager(mLayoutManager);
    ArrayList<CommentNode> comments = new ArrayList<>();
    List<CommentObject> commentsOld = DataShare.sharedComments;
    if (commentsOld != null && !commentsOld.isEmpty())
        for (CommentObject o : commentsOld) {
            if (o instanceof CommentItem)
                comments.add(o.comment);
        }
    else
        finish();
    final CommentAdapterSearch adapter = new CommentAdapterSearch(this, comments);
    rv.setAdapter(adapter);
    search.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String result = search.getText().toString();
            adapter.setResult(result);
            adapter.getFilter().filter(result);
        }
    });
}
Also used : EditText(android.widget.EditText) ArrayList(java.util.ArrayList) CommentNode(net.dean.jraw.models.CommentNode) CommentAdapterSearch(me.ccrama.redditslide.Adapters.CommentAdapterSearch) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) CommentObject(me.ccrama.redditslide.Adapters.CommentObject) CommentItem(me.ccrama.redditslide.Adapters.CommentItem) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

CommentItem (me.ccrama.redditslide.Adapters.CommentItem)5 CommentObject (me.ccrama.redditslide.Adapters.CommentObject)5 ActivityNotFoundException (android.content.ActivityNotFoundException)3 IOException (java.io.IOException)3 ApiException (net.dean.jraw.ApiException)3 NetworkException (net.dean.jraw.http.NetworkException)3 RecyclerView (android.support.v7.widget.RecyclerView)2 EditText (android.widget.EditText)2 ArrayList (java.util.ArrayList)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Snackbar (android.support.design.widget.Snackbar)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 Toolbar (android.support.v7.widget.Toolbar)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1