aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-06-22 05:16:17 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-06-22 05:16:17 +0000
commit11ec08c12fbbf20a52dae50359fa520c29d66367 (patch)
treeb36b825ab851191dbb7e8d0a6ca79ae76f223d22 /app/src/main/java/ml
parente222fbc5b1e9592f66abc24fa3a3b43ced4db52f (diff)
downloadinfinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar.gz
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar.bz2
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar.lz
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar.xz
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.tar.zst
infinity-for-reddit-11ec08c12fbbf20a52dae50359fa520c29d66367.zip
Implement two pane layout in ViewPostDetailFragment to separate post detail and comments. Fix bugs related to separating CommentAndPostRecyclerViewAdapter.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java93
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java331
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java136
3 files changed, 155 insertions, 405 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
index 4f42b519..965c9844 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
@@ -393,9 +393,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
Comment comment = getCurrentComment(position);
if (comment != null) {
if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) {
- ((CommentViewHolder) holder).itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
+ holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
} else if (comment.getAwards() != null && !comment.getAwards().equals("")) {
- ((CommentViewHolder) holder).itemView.setBackgroundColor(mAwardedCommentBackgroundColor);
+ holder.itemView.setBackgroundColor(mAwardedCommentBackgroundColor);
}
String authorPrefixed = "u/" + comment.getAuthor();
@@ -591,9 +591,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.addAll(placeholderPosition, expandedComments);
if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
- } else {
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
+ } else {
+ notifyItemRangeInserted(placeholderPosition, expandedComments.size());
}
} else {
mVisibleComments.get(parentPosition).getChildren()
@@ -612,16 +612,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.remove(placeholderPosition);
if (mIsSingleCommentThreadMode) {
- notifyItemRemoved(placeholderPosition + 2);
- } else {
notifyItemRemoved(placeholderPosition + 1);
+ } else {
+ notifyItemRemoved(placeholderPosition);
}
mVisibleComments.addAll(placeholderPosition, expandedComments);
if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
- } else {
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
+ } else {
+ notifyItemRangeInserted(placeholderPosition, expandedComments.size());
}
}
} else {
@@ -654,9 +654,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.addAll(placeholderPosition, expandedComments);
if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
- } else {
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
+ } else {
+ notifyItemRangeInserted(placeholderPosition, expandedComments.size());
}
}
@@ -785,14 +785,14 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (mIsSingleCommentThreadMode) {
if (mFullyCollapseComment) {
- notifyItemChanged(position + 2);
+ notifyItemChanged(position + 1);
}
- notifyItemRangeRemoved(position + 3, allChildrenSize);
+ notifyItemRangeRemoved(position + 2, allChildrenSize);
} else {
if (mFullyCollapseComment) {
- notifyItemChanged(position + 1);
+ notifyItemChanged(position);
}
- notifyItemRangeRemoved(position + 2, allChildrenSize);
+ notifyItemRangeRemoved(position + 1, allChildrenSize);
}
}
@@ -801,32 +801,32 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
isInitiallyLoading = false;
isInitiallyLoadingFailed = false;
if (comments.size() == 0) {
- notifyItemChanged(1);
+ notifyItemChanged(0);
} else {
- notifyItemRemoved(1);
+ notifyItemRemoved(0);
}
}
int sizeBefore = mVisibleComments.size();
mVisibleComments.addAll(comments);
if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(sizeBefore + 2, comments.size());
- } else {
notifyItemRangeInserted(sizeBefore + 1, comments.size());
+ } else {
+ notifyItemRangeInserted(sizeBefore, comments.size());
}
if (mHasMoreComments != hasMoreComments) {
if (hasMoreComments) {
if (mIsSingleCommentThreadMode) {
- notifyItemInserted(mVisibleComments.size() + 2);
- } else {
notifyItemInserted(mVisibleComments.size() + 1);
+ } else {
+ notifyItemInserted(mVisibleComments.size());
}
} else {
if (mIsSingleCommentThreadMode) {
- notifyItemRemoved(mVisibleComments.size() + 2);
- } else {
notifyItemRemoved(mVisibleComments.size() + 1);
+ } else {
+ notifyItemRemoved(mVisibleComments.size());
}
}
}
@@ -865,18 +865,18 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.get(parentPosition).setExpanded(true);
mVisibleComments.addAll(parentPosition + 1, newList);
if (mIsSingleCommentThreadMode) {
- notifyItemChanged(parentPosition + 2);
- notifyItemRangeInserted(parentPosition + 3, newList.size());
- } else {
notifyItemChanged(parentPosition + 1);
notifyItemRangeInserted(parentPosition + 2, newList.size());
+ } else {
+ notifyItemChanged(parentPosition);
+ notifyItemRangeInserted(parentPosition + 1, newList.size());
}
} else {
mVisibleComments.add(parentPosition + 1, comment);
if (mIsSingleCommentThreadMode) {
- notifyItemInserted(parentPosition + 3);
- } else {
notifyItemInserted(parentPosition + 2);
+ } else {
+ notifyItemInserted(parentPosition + 1);
}
}
}
@@ -895,35 +895,35 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int previousSize = mVisibleComments.size();
mVisibleComments.clear();
if (mIsSingleCommentThreadMode) {
- notifyItemRangeRemoved(1, previousSize + 1);
+ notifyItemRangeRemoved(0, previousSize + 1);
} else {
- notifyItemRangeRemoved(1, previousSize);
+ notifyItemRangeRemoved(0, previousSize);
}
}
- if (isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
+ if (isInitiallyLoading || isInitiallyLoadingFailed) {
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
- notifyItemChanged(1);
+ notifyItemChanged(0);
} else {
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
- notifyItemInserted(1);
+ notifyItemInserted(0);
}
}
public void initiallyLoadCommentsFailed() {
isInitiallyLoading = false;
isInitiallyLoadingFailed = true;
- notifyItemChanged(1);
+ notifyItemChanged(0);
}
public void loadMoreCommentsFailed() {
loadMoreCommentsFailed = true;
if (mIsSingleCommentThreadMode) {
- notifyItemChanged(mVisibleComments.size() + 2);
- } else {
notifyItemChanged(mVisibleComments.size() + 1);
+ } else {
+ notifyItemChanged(mVisibleComments.size());
}
}
@@ -933,9 +933,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.get(position).setCommentMarkdown(commentContentMarkdown);
if (mIsSingleCommentThreadMode) {
- notifyItemChanged(position + 2);
- } else {
notifyItemChanged(position + 1);
+ } else {
+ notifyItemChanged(position);
}
}
@@ -945,16 +945,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.get(position).setAuthor("[deleted]");
mVisibleComments.get(position).setCommentMarkdown("[deleted]");
if (mIsSingleCommentThreadMode) {
- notifyItemChanged(position + 2);
- } else {
notifyItemChanged(position + 1);
+ } else {
+ notifyItemChanged(position);
}
} else {
mVisibleComments.remove(position);
if (mIsSingleCommentThreadMode) {
- notifyItemRemoved(position + 2);
- } else {
notifyItemRemoved(position + 1);
+ } else {
+ notifyItemRemoved(position);
}
}
}
@@ -1160,6 +1160,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
authorFlairTextView.setOnClickListener(view -> authorTextView.performClick());
moreButton.setOnClickListener(view -> {
+ getItemCount();
Comment comment = getCurrentComment(this);
if (comment != null) {
Bundle bundle = new Bundle();
@@ -1447,9 +1448,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.addAll(commentPosition + 1, newList);
if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(commentPosition + 3, newList.size());
- } else {
notifyItemRangeInserted(commentPosition + 2, newList.size());
+ } else {
+ notifyItemRangeInserted(commentPosition + 1, newList.size());
}
expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp);
}
@@ -1578,11 +1579,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.addAll(commentPosition + 1, newList);
if (mIsSingleCommentThreadMode) {
- notifyItemChanged(commentPosition + 2);
- notifyItemRangeInserted(commentPosition + 3, newList.size());
- } else {
notifyItemChanged(commentPosition + 1);
notifyItemRangeInserted(commentPosition + 2, newList.size());
+ } else {
+ notifyItemChanged(commentPosition);
+ notifyItemRangeInserted(commentPosition + 1, newList.size());
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index fce988da..4334c42a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -127,15 +127,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6;
private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7;
private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8;
- private static final int VIEW_TYPE_FIRST_LOADING = 9;
- private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 10;
- private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 11;
- private static final int VIEW_TYPE_COMMENT = 12;
- private static final int VIEW_TYPE_COMMENT_FULLY_COLLAPSED = 13;
- private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 14;
- private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 15;
- private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 16;
- private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 17;
private AppCompatActivity mActivity;
private ViewPostDetailFragment mFragment;
@@ -446,91 +437,35 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
@Override
public int getItemViewType(int position) {
- if (position == 0) {
- switch (mPost.getPostType()) {
- case Post.VIDEO_TYPE:
- if (mAutoplay) {
- if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
- return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
- }
- return VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY;
- } else {
- return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
- }
- case Post.GIF_TYPE:
- if (mAutoplay) {
- if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
- return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
- }
- return VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY;
- } else {
+ switch (mPost.getPostType()) {
+ case Post.VIDEO_TYPE:
+ if (mAutoplay) {
+ if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
}
- case Post.IMAGE_TYPE:
- return VIEW_TYPE_POST_DETAIL_IMAGE;
- case Post.LINK_TYPE:
- return VIEW_TYPE_POST_DETAIL_LINK;
- case Post.NO_PREVIEW_LINK_TYPE:
- return VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK;
- case Post.GALLERY_TYPE:
- return VIEW_TYPE_POST_DETAIL_GALLERY;
- default:
- return VIEW_TYPE_POST_DETAIL_TEXT_TYPE;
- }
- }
-
- if (mVisibleComments.size() == 0) {
- if (position == 1) {
- if (isInitiallyLoading) {
- return VIEW_TYPE_FIRST_LOADING;
- } else if (isInitiallyLoadingFailed) {
- return VIEW_TYPE_FIRST_LOADING_FAILED;
+ return VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY;
} else {
- return VIEW_TYPE_NO_COMMENT_PLACEHOLDER;
+ return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
}
- }
- }
-
- if (mIsSingleCommentThreadMode) {
- if (position == 1) {
- return VIEW_TYPE_VIEW_ALL_COMMENTS;
- }
-
- if (position == mVisibleComments.size() + 2) {
- if (mHasMoreComments) {
- return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
- } else {
- return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
- }
- }
-
- Comment comment = mVisibleComments.get(position - 2);
- if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
- if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
- return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
- }
- return VIEW_TYPE_COMMENT;
- } else {
- return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
- }
- } else {
- if (position == mVisibleComments.size() + 1) {
- if (mHasMoreComments) {
- return VIEW_TYPE_IS_LOADING_MORE_COMMENTS;
+ case Post.GIF_TYPE:
+ if (mAutoplay) {
+ if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
+ return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
+ }
+ return VIEW_TYPE_POST_DETAIL_GIF_AUTOPLAY;
} else {
- return VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED;
- }
- }
-
- Comment comment = mVisibleComments.get(position - 1);
- if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
- if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
- return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
+ return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
}
- return VIEW_TYPE_COMMENT;
- } else {
- return VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS;
- }
+ case Post.IMAGE_TYPE:
+ return VIEW_TYPE_POST_DETAIL_IMAGE;
+ case Post.LINK_TYPE:
+ return VIEW_TYPE_POST_DETAIL_LINK;
+ case Post.NO_PREVIEW_LINK_TYPE:
+ return VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK;
+ case Post.GALLERY_TYPE:
+ return VIEW_TYPE_POST_DETAIL_GALLERY;
+ default:
+ return VIEW_TYPE_POST_DETAIL_TEXT_TYPE;
}
}
@@ -1065,224 +1000,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
notifyItemChanged(0);
}
- private int getParentPosition(int position) {
- if (position >= 0 && position < mVisibleComments.size()) {
- int childDepth = mVisibleComments.get(position).getDepth();
- for (int i = position; i >= 0; i--) {
- if (mVisibleComments.get(i).getDepth() < childDepth) {
- return i;
- }
- }
- }
- return -1;
- }
-
- private void expandChildren(ArrayList<Comment> comments, ArrayList<Comment> newList, int position) {
- if (comments != null && comments.size() > 0) {
- newList.addAll(position, comments);
- for (int i = 0; i < comments.size(); i++) {
- position++;
- if (comments.get(i).getChildren() != null && comments.get(i).getChildren().size() > 0) {
- expandChildren(comments.get(i).getChildren(), newList, position);
- position = position + comments.get(i).getChildren().size();
- }
- comments.get(i).setExpanded(true);
- }
- }
- }
-
- private void collapseChildren(int position) {
- mVisibleComments.get(position).setExpanded(false);
- int depth = mVisibleComments.get(position).getDepth();
- int allChildrenSize = 0;
- for (int i = position + 1; i < mVisibleComments.size(); i++) {
- if (mVisibleComments.get(i).getDepth() > depth) {
- allChildrenSize++;
- } else {
- break;
- }
- }
-
- if (allChildrenSize > 0) {
- mVisibleComments.subList(position + 1, position + 1 + allChildrenSize).clear();
- }
- if (mIsSingleCommentThreadMode) {
- if (mFullyCollapseComment) {
- notifyItemChanged(position + 2);
- }
- notifyItemRangeRemoved(position + 3, allChildrenSize);
- } else {
- if (mFullyCollapseComment) {
- notifyItemChanged(position + 1);
- }
- notifyItemRangeRemoved(position + 2, allChildrenSize);
- }
- }
-
- public void addComments(@NonNull ArrayList<Comment> comments, boolean hasMoreComments) {
- if (mVisibleComments.size() == 0) {
- isInitiallyLoading = false;
- isInitiallyLoadingFailed = false;
- if (comments.size() == 0) {
- notifyItemChanged(1);
- } else {
- notifyItemRemoved(1);
- }
- }
-
- int sizeBefore = mVisibleComments.size();
- mVisibleComments.addAll(comments);
- if (mIsSingleCommentThreadMode) {
- notifyItemRangeInserted(sizeBefore + 2, comments.size());
- } else {
- notifyItemRangeInserted(sizeBefore + 1, comments.size());
- }
-
- if (mHasMoreComments != hasMoreComments) {
- if (hasMoreComments) {
- if (mIsSingleCommentThreadMode) {
- notifyItemInserted(mVisibleComments.size() + 2);
- } else {
- notifyItemInserted(mVisibleComments.size() + 1);
- }
- } else {
- if (mIsSingleCommentThreadMode) {
- notifyItemRemoved(mVisibleComments.size() + 2);
- } else {
- notifyItemRemoved(mVisibleComments.size() + 1);
- }
- }
- }
- mHasMoreComments = hasMoreComments;
- }
-
- public void addComment(Comment comment) {
- if (mVisibleComments.size() == 0 || isInitiallyLoadingFailed) {
- notifyItemRemoved(1);
- }
-
- mVisibleComments.add(0, comment);
-
- if (isInitiallyLoading) {
- notifyItemInserted(2);
- } else {
- notifyItemInserted(1);
- }
- }
-
- public void addChildComment(Comment comment, String parentFullname, int parentPosition) {
- if (!parentFullname.equals(mVisibleComments.get(parentPosition).getFullName())) {
- for (int i = 0; i < mVisibleComments.size(); i++) {
- if (parentFullname.equals(mVisibleComments.get(i).getFullName())) {
- parentPosition = i;
- break;
- }
- }
- }
-
- mVisibleComments.get(parentPosition).addChild(comment);
- mVisibleComments.get(parentPosition).setHasReply(true);
- if (!mVisibleComments.get(parentPosition).isExpanded()) {
- ArrayList<Comment> newList = new ArrayList<>();
- expandChildren(mVisibleComments.get(parentPosition).getChildren(), newList, 0);
- mVisibleComments.get(parentPosition).setExpanded(true);
- mVisibleComments.addAll(parentPosition + 1, newList);
- if (mIsSingleCommentThreadMode) {
- notifyItemChanged(parentPosition + 2);
- notifyItemRangeInserted(parentPosition + 3, newList.size());
- } else {
- notifyItemChanged(parentPosition + 1);
- notifyItemRangeInserted(parentPosition + 2, newList.size());
- }
- } else {
- mVisibleComments.add(parentPosition + 1, comment);
- if (mIsSingleCommentThreadMode) {
- notifyItemInserted(parentPosition + 3);
- } else {
- notifyItemInserted(parentPosition + 2);
- }
- }
- }
-
- public void setSingleComment(String singleCommentId, boolean isSingleCommentThreadMode) {
- mSingleCommentId = singleCommentId;
- mIsSingleCommentThreadMode = isSingleCommentThreadMode;
- }
-
- public ArrayList<Comment> getVisibleComments() {
- return mVisibleComments;
- }
-
- public void initiallyLoading() {
- if (mVisibleComments.size() != 0) {
- int previousSize = mVisibleComments.size();
- mVisibleComments.clear();
- if (mIsSingleCommentThreadMode) {
- notifyItemRangeRemoved(1, previousSize + 1);
- } else {
- notifyItemRangeRemoved(1, previousSize);
- }
- }
-
- if (isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) {
- isInitiallyLoading = true;
- isInitiallyLoadingFailed = false;
- notifyItemChanged(1);
- } else {
- isInitiallyLoading = true;
- isInitiallyLoadingFailed = false;
- notifyItemInserted(1);
- }
- }
-
- public void initiallyLoadCommentsFailed() {
- isInitiallyLoading = false;
- isInitiallyLoadingFailed = true;
- notifyItemChanged(1);
- }
-
- public void loadMoreCommentsFailed() {
- loadMoreCommentsFailed = true;
- if (mIsSingleCommentThreadMode) {
- notifyItemChanged(mVisibleComments.size() + 2);
- } else {
- notifyItemChanged(mVisibleComments.size() + 1);
- }
- }
-
- public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
- if (commentAuthor != null)
- mVisibleComments.get(position).setAuthor(commentAuthor);
-
- mVisibleComments.get(position).setCommentMarkdown(commentContentMarkdown);
- if (mIsSingleCommentThreadMode) {
- notifyItemChanged(position + 2);
- } else {
- notifyItemChanged(position + 1);
- }
- }
-
- public void deleteComment(int position) {
- if (mVisibleComments != null && position >= 0 && position < mVisibleComments.size()) {
- if (mVisibleComments.get(position).hasReply()) {
- mVisibleComments.get(position).setAuthor("[deleted]");
- mVisibleComments.get(position).setCommentMarkdown("[deleted]");
- if (mIsSingleCommentThreadMode) {
- notifyItemChanged(position + 2);
- } else {
- notifyItemChanged(position + 1);
- }
- } else {
- mVisibleComments.remove(position);
- if (mIsSingleCommentThreadMode) {
- notifyItemRemoved(position + 2);
- } else {
- notifyItemRemoved(position + 1);
- }
- }
- }
- }
-
public void setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(boolean needBlurNsfw, boolean doNotBlurNsfwInNsfwSubreddits) {
mNeedBlurNsfw = needBlurNsfw;
mDoNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits;
@@ -2044,7 +1761,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
@Override
public int getPlayerOrder() {
- return getBindingAdapterPosition();
+ return 0;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 750f5367..992b6880 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@@ -126,8 +127,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@BindView(R.id.swipe_refresh_layout_view_post_detail_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
- @BindView(R.id.recycler_view_view_post_detail_fragment)
+ @BindView(R.id.post_detail_recycler_view_view_post_detail_fragment)
CustomToroContainer mRecyclerView;
+ RecyclerView mCommentsRecyclerView;
@BindView(R.id.fetch_post_info_linear_layout_view_post_detail_fragment)
LinearLayout mFetchPostInfoLinearLayout;
@BindView(R.id.fetch_post_info_image_view_view_post_detail_fragment)
@@ -216,7 +218,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private LinearLayoutManager mLinearLayoutManager;
private ConcatAdapter mConcatAdapter;
private PostDetailRecyclerViewAdapter mPostAdapter;
- private CommentsRecyclerViewAdapter mCommentAdapter;
+ private CommentsRecyclerViewAdapter mCommentsAdapter;
private RecyclerView.SmoothScroller mSmoothScroller;
private Drawable mSavedIcon;
private Drawable mUnsavedIcon;
@@ -277,8 +279,15 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
- mLinearLayoutManager = new LinearLayoutManager(activity);
- mRecyclerView.setLayoutManager(mLinearLayoutManager);
+ if (getResources().getBoolean(R.bool.isTablet) || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ mLinearLayoutManager = new LinearLayoutManager(activity);
+ mCommentsRecyclerView = rootView.findViewById(R.id.comments_recycler_view_view_post_detail_fragment);
+ mCommentsRecyclerView.setLayoutManager(mLinearLayoutManager);
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
+ } else {
+ mLinearLayoutManager = new LinearLayoutManager(activity);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
+ }
if (children != null && children.size() > 0) {
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -391,8 +400,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (touchHelper != null) {
touchHelper.attachToRecyclerView(null);
touchHelper.attachToRecyclerView(mRecyclerView);
- if (mCommentAdapter != null) {
- mCommentAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction);
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction);
}
}
}
@@ -531,7 +540,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
});
- mCommentAdapter = new CommentsRecyclerViewAdapter(activity,
+ mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mSharedPreferences,
@@ -549,8 +558,14 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
fetchMoreComments();
}
});
- mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentAdapter);
- mRecyclerView.setAdapter(mConcatAdapter);
+ if (mCommentsRecyclerView != null) {
+ mRecyclerView.setAdapter(mPostAdapter);
+ mCommentsRecyclerView.setAdapter(mCommentsAdapter);
+ } else {
+ mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentsAdapter);
+ mRecyclerView.setAdapter(mConcatAdapter);
+ }
+
if (comments == null) {
fetchCommentsRespectRecommendedSort(false);
@@ -561,7 +576,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} else if (isFetchingComments) {
fetchCommentsRespectRecommendedSort(false);
} else {
- mCommentAdapter.addComments(comments, hasMoreChildren);
+ mCommentsAdapter.addComments(comments, hasMoreChildren);
if (isLoadingMoreChildren) {
isLoadingMoreChildren = false;
fetchMoreComments();
@@ -670,28 +685,28 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
public void addComment(Comment comment) {
- if (mCommentAdapter != null) {
- mCommentAdapter.addComment(comment);
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.addComment(comment);
}
}
public void addChildComment(Comment comment, String parentFullname, int parentPosition) {
- if (mCommentAdapter != null) {
- mCommentAdapter.addChildComment(comment, parentFullname, parentPosition);
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.addChildComment(comment, parentFullname, parentPosition);
}
}
public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
- if (mCommentAdapter != null) {
- mCommentAdapter.editComment(commentAuthor,
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.editComment(commentAuthor,
commentContentMarkdown,
position);
}
}
public void awardGiven(String awardsHTML, int awardCount, int position) {
- if (mCommentAdapter != null) {
- mCommentAdapter.giveAward(awardsHTML, awardCount, position);
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.giveAward(awardsHTML, awardCount, position);
}
}
@@ -743,8 +758,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
public void saveComment(int position, boolean isSaved) {
- if (mCommentAdapter != null) {
- mCommentAdapter.setSaveComment(position, isSaved);
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.setSaveComment(position, isSaved);
}
}
@@ -1009,7 +1024,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onResume() {
super.onResume();
- if (mCommentAdapter != null && mRecyclerView != null) {
+ if (mRecyclerView != null) {
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
}
}
@@ -1017,7 +1032,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onPause() {
super.onPause();
- if (mCommentAdapter != null && mRecyclerView != null) {
+ if (mRecyclerView != null) {
mRecyclerView.onWindowVisibilityChanged(View.GONE);
}
}
@@ -1025,7 +1040,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
- comments = mCommentAdapter == null ? null : mCommentAdapter.getVisibleComments();
+ comments = mCommentsAdapter == null ? null : mCommentsAdapter.getVisibleComments();
Bridge.saveInstanceState(this, outState);
}
@@ -1107,7 +1122,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
});
- mCommentAdapter = new CommentsRecyclerViewAdapter(activity,
+ mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit,
mAccessToken, mAccountName, mPost, mLocale,
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
@@ -1125,8 +1140,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
fetchMoreComments();
}
});
- mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentAdapter);
- mRecyclerView.setAdapter(mConcatAdapter);
+ if (mCommentsRecyclerView != null) {
+ mRecyclerView.setAdapter(mPostAdapter);
+ mCommentsRecyclerView.setAdapter(mCommentsAdapter);
+ } else {
+ mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentsAdapter);
+ mRecyclerView.setAdapter(mConcatAdapter);
+ }
if (mRespectSubredditRecommendedSortType) {
fetchCommentsRespectRecommendedSort(false);
@@ -1138,7 +1158,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
ViewPostDetailFragment.this.children = moreChildrenFullnames;
hasMoreChildren = children.size() != 0;
- mCommentAdapter.addComments(expandedComments, hasMoreChildren);
+ mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
if (children.size() > 0) {
mRecyclerView.clearOnScrollListeners();
@@ -1189,7 +1209,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onParseCommentFailed() {
- mCommentAdapter.initiallyLoadCommentsFailed();
+ mCommentsAdapter.initiallyLoadCommentsFailed();
}
});
}
@@ -1251,8 +1271,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private void fetchComments(boolean changeRefreshState, boolean checkSortState, String sortType) {
isFetchingComments = true;
- mCommentAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
- mCommentAdapter.initiallyLoading();
+ mCommentsAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
+ mCommentsAdapter.initiallyLoading();
String commentId = null;
if (isSingleCommentThreadMode) {
commentId = mSingleCommentId;
@@ -1276,7 +1296,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
comments = expandedComments;
hasMoreChildren = children.size() != 0;
- mCommentAdapter.addComments(expandedComments, hasMoreChildren);
+ mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
if (children.size() > 0) {
mRecyclerView.clearOnScrollListeners();
@@ -1341,7 +1361,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
return;
}
- mCommentAdapter.initiallyLoadCommentsFailed();
+ mCommentsAdapter.initiallyLoadCommentsFailed();
if (changeRefreshState) {
isRefreshing = false;
}
@@ -1366,7 +1386,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onFetchMoreCommentSuccess(ArrayList<Comment> expandedComments, int childrenStartingIndex) {
hasMoreChildren = childrenStartingIndex < children.size();
- mCommentAdapter.addComments(expandedComments, hasMoreChildren);
+ mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
mChildrenStartingIndex = childrenStartingIndex;
isLoadingMoreChildren = false;
loadMoreChildrenSuccess = true;
@@ -1376,7 +1396,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public void onFetchMoreCommentFailed() {
isLoadingMoreChildren = false;
loadMoreChildrenSuccess = false;
- mCommentAdapter.loadMoreCommentsFailed();
+ mCommentsAdapter.loadMoreCommentsFailed();
}
});
}
@@ -1599,7 +1619,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void deleteSuccess() {
Toast.makeText(activity, R.string.delete_post_success, Toast.LENGTH_SHORT).show();
- mCommentAdapter.deleteComment(position);
+ mCommentsAdapter.deleteComment(position);
}
@Override
@@ -1619,7 +1639,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
new FetchRemovedComment.FetchRemovedCommentListener() {
@Override
public void fetchSuccess(Comment comment) {
- mCommentAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
+ mCommentsAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
}
@Override
@@ -1639,8 +1659,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public void scrollToNextParentComment() {
if (mLinearLayoutManager != null) {
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
- if (mCommentAdapter != null) {
- int nextParentPosition = mCommentAdapter.getNextParentCommentPosition(currentPosition);
+ if (mCommentsAdapter != null) {
+ int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(currentPosition);
if (nextParentPosition < 0) {
return;
}
@@ -1656,8 +1676,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public void scrollToPreviousParentComment() {
if (mLinearLayoutManager != null) {
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
- if (mCommentAdapter != null) {
- int nextParentPosition = mCommentAdapter.getPreviousParentCommentPosition(currentPosition);
+ if (mCommentsAdapter != null) {
+ int nextParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(currentPosition);
if (nextParentPosition < 0) {
return;
}
@@ -1725,7 +1745,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mPostAdapter != null) {
mPostAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits);
}
- refreshAdapter();
+ if (mCommentsRecyclerView != null) {
+ refreshAdapter(mRecyclerView, mConcatAdapter);
+ } else {
+ refreshAdapter(mRecyclerView, mPostAdapter);
+ }
}
@Subscribe
@@ -1733,23 +1757,27 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (mPostAdapter != null) {
mPostAdapter.setBlurSpoiler(event.needBlurSpoiler);
}
- refreshAdapter();
+ if (mCommentsRecyclerView != null) {
+ refreshAdapter(mRecyclerView, mConcatAdapter);
+ } else {
+ refreshAdapter(mRecyclerView, mPostAdapter);
+ }
}
- private void refreshAdapter() {
+ private void refreshAdapter(RecyclerView recyclerView, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
int previousPosition = -1;
- if (mLinearLayoutManager != null) {
- previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ if (recyclerView.getLayoutManager() != null) {
+ previousPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
}
- RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
- mRecyclerView.setAdapter(null);
- mRecyclerView.setLayoutManager(null);
- mRecyclerView.setAdapter(mConcatAdapter);
- mRecyclerView.setLayoutManager(layoutManager);
+ RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
+ recyclerView.setAdapter(null);
+ recyclerView.setLayoutManager(null);
+ recyclerView.setAdapter(adapter);
+ recyclerView.setLayoutManager(layoutManager);
if (previousPosition > 0) {
- mRecyclerView.scrollToPosition(previousPosition);
+ recyclerView.scrollToPosition(previousPosition);
}
}
@@ -1769,7 +1797,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
if (stateChanged) {
- refreshAdapter();
+ if (mCommentsRecyclerView != null) {
+ refreshAdapter(mRecyclerView, mConcatAdapter);
+ } else {
+ refreshAdapter(mRecyclerView, mPostAdapter);
+ }
}
}
}