Search in sources :

Example 1 with CommentAdapter

use of me.ccrama.redditslide.Adapters.CommentAdapter 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)

Example 2 with CommentAdapter

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

the class CommentPage method doData.

public void doData(Boolean b) {
    if (adapter == null || single) {
        adapter = new CommentAdapter(this, comments, rv, comments.submission, getFragmentManager());
        rv.setAdapter(adapter);
        adapter.currentSelectedItem = context;
        if (context.isEmpty()) {
            if (SettingValues.collapseCommentsDefault) {
                adapter.collapseAll();
            }
        }
        adapter.reset(getContext(), comments, rv, comments.submission, b);
    } else if (!b) {
        try {
            adapter.reset(getContext(), comments, rv, (getActivity() instanceof MainActivity) ? ((MainActivity) getActivity()).openingComments : comments.submission, b);
            if (SettingValues.collapseCommentsDefault) {
                adapter.collapseAll();
            }
        } catch (Exception ignored) {
        }
    } else {
        adapter.reset(getContext(), comments, rv, comments.submission, b);
        if (SettingValues.collapseCommentsDefault) {
            adapter.collapseAll();
        }
        adapter.notifyItemChanged(1);
    }
}
Also used : MainActivity(me.ccrama.redditslide.Activities.MainActivity) CommentAdapter(me.ccrama.redditslide.Adapters.CommentAdapter) IOException(java.io.IOException) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException)

Aggregations

IOException (java.io.IOException)2 MainActivity (me.ccrama.redditslide.Activities.MainActivity)2 CommentAdapter (me.ccrama.redditslide.Adapters.CommentAdapter)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CommentsScreen (me.ccrama.redditslide.Activities.CommentsScreen)1 SubmissionComments (me.ccrama.redditslide.Adapters.SubmissionComments)1 ApiException (net.dean.jraw.ApiException)1 NetworkException (net.dean.jraw.http.NetworkException)1 Submission (net.dean.jraw.models.Submission)1