Search in sources :

Example 1 with SubmissionComments

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

the class CommentPage method doTopBar.

public void doTopBar() {
    final View loadallV = v.findViewById(R.id.loadall);
    final View npV = v.findViewById(R.id.np);
    final View archivedV = v.findViewById(R.id.archived);
    final View lockedV = v.findViewById(R.id.locked);
    final View headerV = v.findViewById(R.id.toolbar);
    final View contestV = v.findViewById(R.id.contest);
    shownHeaders = 0;
    headerV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    loadallV.setVisibility(View.VISIBLE);
    npV.setVisibility(View.VISIBLE);
    archivedV.setVisibility(View.VISIBLE);
    lockedV.setVisibility(View.VISIBLE);
    contestV.setVisibility(View.VISIBLE);
    if (!loadMore) {
        loadallV.setVisibility(View.GONE);
    } else {
        loadallV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        shownHeaders += loadallV.getMeasuredHeight();
        loadallV.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                doRefresh(true);
                shownHeaders -= loadallV.getMeasuredHeight();
                headerHeight = headerV.getMeasuredHeight() + shownHeaders;
                loadallV.setVisibility(View.GONE);
                if (adapter != null) {
                    adapter.notifyItemChanged(0);
                }
                // avoid crashes when load more is clicked before loading is finished
                if (comments.mLoadData != null) {
                    comments.mLoadData.cancel(true);
                }
                comments = new SubmissionComments(fullname, CommentPage.this, mSwipeRefreshLayout);
                comments.setSorting(CommentSort.CONFIDENCE);
                loadMore = false;
                mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + (Constants.PTR_OFFSET_BOTTOM + shownHeaders));
            }
        });
    }
    if (!np && !archived) {
        npV.setVisibility(View.GONE);
        archivedV.setVisibility(View.GONE);
    } else if (archived) {
        archivedV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        shownHeaders += archivedV.getMeasuredHeight();
        npV.setVisibility(View.GONE);
        archivedV.setBackgroundColor(Palette.getColor(subreddit));
    } else {
        npV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        shownHeaders += npV.getMeasuredHeight();
        archivedV.setVisibility(View.GONE);
        npV.setBackgroundColor(Palette.getColor(subreddit));
    }
    if (locked) {
        lockedV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        shownHeaders += lockedV.getMeasuredHeight();
    } else {
        lockedV.setVisibility(View.GONE);
    }
    if (contest) {
        contestV.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        shownHeaders += contestV.getMeasuredHeight();
    } else {
        contestV.setVisibility(View.GONE);
    }
    headerHeight = headerV.getMeasuredHeight() + shownHeaders;
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp. Account for show headers.
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + (Constants.PTR_OFFSET_BOTTOM + shownHeaders));
}
Also used : SubmissionComments(me.ccrama.redditslide.Adapters.SubmissionComments) 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)

Example 2 with SubmissionComments

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

the class CommentPage method doAdapter.

public void doAdapter(boolean load) {
    commentSorting = SettingValues.getCommentSorting(subreddit);
    if (load)
        doRefresh(true);
    if (load)
        loaded = true;
    if (!single && getActivity() instanceof CommentsScreen && ((CommentsScreen) getActivity()).subredditPosts != null && Authentication.didOnline && ((CommentsScreen) getActivity()).currentPosts != null && ((CommentsScreen) getActivity()).currentPosts.size() > page) {
        try {
            comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout);
        } catch (IndexOutOfBoundsException e) {
            return;
        }
        Submission s = ((CommentsScreen) getActivity()).currentPosts.get(page);
        if (s != null && s.getDataNode().has("suggested_sort") && !s.getDataNode().get("suggested_sort").asText().equalsIgnoreCase("null")) {
            String sorting = s.getDataNode().get("suggested_sort").asText().toUpperCase();
            sorting = sorting.replace("İ", "I");
            commentSorting = CommentSort.valueOf(sorting);
        } else if (s != null) {
            commentSorting = SettingValues.getCommentSorting(s.getSubredditName());
        }
        if (load)
            comments.setSorting(commentSorting);
        if (adapter == null) {
            adapter = new CommentAdapter(this, comments, rv, s, getFragmentManager());
            rv.setAdapter(adapter);
        }
    } else if (getActivity() instanceof MainActivity) {
        if (Authentication.didOnline) {
            comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout);
            Submission s = ((MainActivity) getActivity()).openingComments;
            if (s != null && s.getDataNode().has("suggested_sort") && !s.getDataNode().get("suggested_sort").asText().equalsIgnoreCase("null")) {
                String sorting = s.getDataNode().get("suggested_sort").asText().toUpperCase();
                sorting = sorting.replace("İ", "I");
                commentSorting = CommentSort.valueOf(sorting);
            } else if (s != null) {
                commentSorting = SettingValues.getCommentSorting(s.getSubredditName());
            }
            if (load)
                comments.setSorting(commentSorting);
            if (adapter == null) {
                adapter = new CommentAdapter(this, comments, rv, s, getFragmentManager());
                rv.setAdapter(adapter);
            }
        } else {
            Submission s = ((MainActivity) getActivity()).openingComments;
            doRefresh(false);
            comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout, s);
            if (adapter == null) {
                adapter = new CommentAdapter(this, comments, rv, s, getFragmentManager());
                rv.setAdapter(adapter);
            }
        }
    } else {
        Submission s = null;
        try {
            s = OfflineSubreddit.getSubmissionFromStorage(fullname.contains("_") ? fullname : "t3_" + fullname, getContext(), !NetworkUtil.isConnected(getActivity()), new ObjectMapper().reader());
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (s != null && s.getComments() != null) {
            doRefresh(false);
            comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout, s);
            if (adapter == null) {
                adapter = new CommentAdapter(this, comments, rv, s, getFragmentManager());
                rv.setAdapter(adapter);
            }
        } else if (context.isEmpty()) {
            comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout);
            comments.setSorting(commentSorting);
            if (adapter == null) {
                if (s != null) {
                    adapter = new CommentAdapter(this, comments, rv, s, getFragmentManager());
                }
                rv.setAdapter(adapter);
            }
        } else {
            if (context.equals(Reddit.EMPTY_STRING)) {
                comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout);
                if (load)
                    comments.setSorting(commentSorting);
            } else {
                comments = new SubmissionComments(fullname, this, mSwipeRefreshLayout, context, contextNumber);
                if (load)
                    comments.setSorting(commentSorting);
            }
        }
    }
}
Also used : CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) SubmissionComments(me.ccrama.redditslide.Adapters.SubmissionComments) Submission(net.dean.jraw.models.Submission) MainActivity(me.ccrama.redditslide.Activities.MainActivity) IOException(java.io.IOException) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SubmissionComments (me.ccrama.redditslide.Adapters.SubmissionComments)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 CommentsScreen (me.ccrama.redditslide.Activities.CommentsScreen)1 MainActivity (me.ccrama.redditslide.Activities.MainActivity)1 MediaView (me.ccrama.redditslide.Activities.MediaView)1 SubredditView (me.ccrama.redditslide.Activities.SubredditView)1 CommentAdapter (me.ccrama.redditslide.Adapters.CommentAdapter)1 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)1 Submission (net.dean.jraw.models.Submission)1