mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
Continuing comment thread is now available. It can now show all the comments with depth >= 10.
This commit is contained in:
parent
03d5a02480
commit
8d4e2fb149
@ -70,6 +70,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
public static final String EXTRA_POST_ID = "EPI";
|
public static final String EXTRA_POST_ID = "EPI";
|
||||||
public static final String EXTRA_POST_LIST_POSITION = "EPLP";
|
public static final String EXTRA_POST_LIST_POSITION = "EPLP";
|
||||||
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
||||||
|
public static final String EXTRA_CONTEXT_NUMBER = "ECN";
|
||||||
public static final String EXTRA_MESSAGE_FULLNAME = "ENI";
|
public static final String EXTRA_MESSAGE_FULLNAME = "ENI";
|
||||||
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
||||||
public static final String EXTRA_POST_FRAGMENT_ID = "EPFI";
|
public static final String EXTRA_POST_FRAGMENT_ID = "EPFI";
|
||||||
@ -510,6 +511,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
||||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
|
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
|
||||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||||
|
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||||
} else {
|
} else {
|
||||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, posts.get(position));
|
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, posts.get(position));
|
||||||
@ -523,6 +525,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
|
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
|
||||||
}
|
}
|
||||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||||
|
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||||
}
|
}
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
|
@ -637,7 +637,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
}
|
}
|
||||||
|
|
||||||
Comment comment = mVisibleComments.get(position - 2);
|
Comment comment = mVisibleComments.get(position - 2);
|
||||||
if (!comment.isPlaceHolder()) {
|
if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
|
||||||
if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
|
if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
|
||||||
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
|
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
|
||||||
}
|
}
|
||||||
@ -655,7 +655,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
}
|
}
|
||||||
|
|
||||||
Comment comment = mVisibleComments.get(position - 1);
|
Comment comment = mVisibleComments.get(position - 1);
|
||||||
if (!comment.isPlaceHolder()) {
|
if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) {
|
||||||
if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
|
if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) {
|
||||||
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
|
return VIEW_TYPE_COMMENT_FULLY_COLLAPSED;
|
||||||
}
|
}
|
||||||
@ -1035,148 +1035,140 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (holder instanceof CommentViewHolder) {
|
} else if (holder instanceof CommentViewHolder) {
|
||||||
Comment comment;
|
Comment comment = getCurrentComment(position);
|
||||||
if (mIsSingleCommentThreadMode) {
|
if (comment != null) {
|
||||||
comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 2);
|
if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) {
|
||||||
} else {
|
((CommentViewHolder) holder).itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
|
||||||
comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 1);
|
} else if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
||||||
}
|
((CommentViewHolder) holder).itemView.setBackgroundColor(mAwardedCommentBackgroundColor);
|
||||||
|
|
||||||
if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) {
|
|
||||||
((CommentViewHolder) holder).itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
|
|
||||||
} else if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
|
||||||
((CommentViewHolder) holder).itemView.setBackgroundColor(mAwardedCommentBackgroundColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
String authorPrefixed = "u/" + comment.getAuthor();
|
|
||||||
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
|
||||||
|
|
||||||
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
|
|
||||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
|
||||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
|
|
||||||
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
|
|
||||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
|
||||||
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.isSubmitter()) {
|
|
||||||
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
|
|
||||||
Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor);
|
|
||||||
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
submitterDrawable, null, null, null);
|
|
||||||
} else if (comment.isModerator()) {
|
|
||||||
((CommentViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
|
|
||||||
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
|
|
||||||
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
moderatorDrawable, null, null, null);
|
|
||||||
} else if (comment.getAuthor().equals(mAccountName)) {
|
|
||||||
((CommentViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
|
|
||||||
Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor);
|
|
||||||
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
currentUserDrawable, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mShowElapsedTime) {
|
|
||||||
((CommentViewHolder) holder).commentTimeTextView.setText(
|
|
||||||
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
|
|
||||||
} else {
|
|
||||||
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mCommentToolbarHidden) {
|
|
||||||
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
|
|
||||||
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
|
||||||
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
|
||||||
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
|
||||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
|
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
|
||||||
comment.getScore() + comment.getVoteType()));
|
|
||||||
((CommentViewHolder) holder).topScoreTextView.setText(mActivity.getString(R.string.top_score,
|
|
||||||
Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
|
||||||
comment.getScore() + comment.getVoteType())));
|
|
||||||
|
|
||||||
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
|
|
||||||
if (comment.getDepth() > depthThreshold) {
|
|
||||||
((CommentViewHolder) holder).saveButton.setVisibility(View.GONE);
|
|
||||||
((CommentViewHolder) holder).replyButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
((CommentViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
|
|
||||||
((CommentViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.hasReply()) {
|
|
||||||
if (comment.isExpanded()) {
|
|
||||||
((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp);
|
|
||||||
} else {
|
|
||||||
((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp);
|
|
||||||
}
|
}
|
||||||
((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (comment.getVoteType()) {
|
String authorPrefixed = "u/" + comment.getAuthor();
|
||||||
case Comment.VOTE_TYPE_UPVOTE:
|
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
|
||||||
|
|
||||||
|
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
|
||||||
|
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||||
|
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
|
||||||
|
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
|
||||||
|
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||||
|
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.isSubmitter()) {
|
||||||
|
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
|
||||||
|
Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor);
|
||||||
|
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
|
submitterDrawable, null, null, null);
|
||||||
|
} else if (comment.isModerator()) {
|
||||||
|
((CommentViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
|
||||||
|
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
|
||||||
|
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
|
moderatorDrawable, null, null, null);
|
||||||
|
} else if (comment.getAuthor().equals(mAccountName)) {
|
||||||
|
((CommentViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
|
||||||
|
Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor);
|
||||||
|
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
|
currentUserDrawable, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mShowElapsedTime) {
|
||||||
|
((CommentViewHolder) holder).commentTimeTextView.setText(
|
||||||
|
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
|
||||||
|
} else {
|
||||||
|
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mCommentToolbarHidden) {
|
||||||
|
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
|
||||||
|
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
||||||
|
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
||||||
|
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
|
||||||
|
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
|
comment.getScore() + comment.getVoteType()));
|
||||||
|
((CommentViewHolder) holder).topScoreTextView.setText(mActivity.getString(R.string.top_score,
|
||||||
|
Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
|
comment.getScore() + comment.getVoteType())));
|
||||||
|
|
||||||
|
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
|
||||||
|
if (comment.getDepth() > depthThreshold) {
|
||||||
|
((CommentViewHolder) holder).saveButton.setVisibility(View.GONE);
|
||||||
|
((CommentViewHolder) holder).replyButton.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
((CommentViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
|
||||||
|
((CommentViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.hasReply()) {
|
||||||
|
if (comment.isExpanded()) {
|
||||||
|
((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp);
|
||||||
|
} else {
|
||||||
|
((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp);
|
||||||
|
}
|
||||||
|
((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (comment.getVoteType()) {
|
||||||
|
case Comment.VOTE_TYPE_UPVOTE:
|
||||||
|
((CommentViewHolder) holder).upvoteButton
|
||||||
|
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
|
||||||
|
((CommentViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
|
||||||
|
break;
|
||||||
|
case Comment.VOTE_TYPE_DOWNVOTE:
|
||||||
|
((CommentViewHolder) holder).downvoteButton
|
||||||
|
.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
|
||||||
|
((CommentViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPost.isArchived()) {
|
||||||
|
((CommentViewHolder) holder).replyButton
|
||||||
|
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
||||||
|
android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((CommentViewHolder) holder).upvoteButton
|
((CommentViewHolder) holder).upvoteButton
|
||||||
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
||||||
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
|
android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((CommentViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
|
|
||||||
break;
|
|
||||||
case Comment.VOTE_TYPE_DOWNVOTE:
|
|
||||||
((CommentViewHolder) holder).downvoteButton
|
((CommentViewHolder) holder).downvoteButton
|
||||||
.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
||||||
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
|
android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((CommentViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPost.isArchived()) {
|
if (mPost.isLocked()) {
|
||||||
((CommentViewHolder) holder).replyButton
|
((CommentViewHolder) holder).replyButton
|
||||||
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
||||||
android.graphics.PorterDuff.Mode.SRC_IN);
|
android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((CommentViewHolder) holder).upvoteButton
|
}
|
||||||
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
|
||||||
android.graphics.PorterDuff.Mode.SRC_IN);
|
|
||||||
((CommentViewHolder) holder).downvoteButton
|
|
||||||
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
|
||||||
android.graphics.PorterDuff.Mode.SRC_IN);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPost.isLocked()) {
|
if (comment.isSaved()) {
|
||||||
((CommentViewHolder) holder).replyButton
|
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||||
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
|
} else {
|
||||||
android.graphics.PorterDuff.Mode.SRC_IN);
|
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comment.isSaved()) {
|
|
||||||
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
|
||||||
} else {
|
|
||||||
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
|
||||||
}
|
}
|
||||||
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
|
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
|
||||||
Comment comment;
|
Comment comment = getCurrentComment(position);
|
||||||
if (mIsSingleCommentThreadMode) {
|
if (comment != null) {
|
||||||
comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 2);
|
String authorWithPrefix = "u/" + comment.getAuthor();
|
||||||
} else {
|
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
|
||||||
comment = mVisibleComments.get(holder.getBindingAdapterPosition() - 1);
|
if (mShowElapsedTime) {
|
||||||
|
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
|
||||||
|
} else {
|
||||||
|
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
|
||||||
|
}
|
||||||
|
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.top_score,
|
||||||
|
Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType())));
|
||||||
|
((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
String authorWithPrefix = "u/" + comment.getAuthor();
|
|
||||||
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
|
|
||||||
if (mShowElapsedTime) {
|
|
||||||
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
|
|
||||||
} else {
|
|
||||||
((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
|
|
||||||
}
|
|
||||||
((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.top_score,
|
|
||||||
Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType())));
|
|
||||||
((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
|
|
||||||
} else if (holder instanceof LoadMoreChildCommentsViewHolder) {
|
} else if (holder instanceof LoadMoreChildCommentsViewHolder) {
|
||||||
Comment placeholder;
|
Comment placeholder;
|
||||||
placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getBindingAdapterPosition() - 2)
|
placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getBindingAdapterPosition() - 2)
|
||||||
@ -1184,111 +1176,53 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
|
|
||||||
((LoadMoreChildCommentsViewHolder) holder).commentIndentationView.setLevelAndColors(placeholder.getDepth(), verticalBlockColors);
|
((LoadMoreChildCommentsViewHolder) holder).commentIndentationView.setLevelAndColors(placeholder.getDepth(), verticalBlockColors);
|
||||||
|
|
||||||
if (placeholder.isLoadingMoreChildren()) {
|
if (placeholder.getPlaceholderType() == Comment.PLACEHOLDER_LOAD_MORE_COMMENTS) {
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
|
if (placeholder.isLoadingMoreChildren()) {
|
||||||
} else if (placeholder.isLoadMoreChildrenFailed()) {
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
} else if (placeholder.isLoadMoreChildrenFailed()) {
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
||||||
|
} else {
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments);
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_continue_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setOnClickListener(view -> {
|
if (placeholder.getPlaceholderType() == Comment.PLACEHOLDER_LOAD_MORE_COMMENTS) {
|
||||||
int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1;
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setOnClickListener(view -> {
|
||||||
int parentPosition = getParentPosition(commentPosition);
|
int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1;
|
||||||
if (parentPosition >= 0) {
|
int parentPosition = getParentPosition(commentPosition);
|
||||||
Comment parentComment = mVisibleComments.get(parentPosition);
|
if (parentPosition >= 0) {
|
||||||
|
Comment parentComment = mVisibleComments.get(parentPosition);
|
||||||
|
|
||||||
mVisibleComments.get(commentPosition).setLoadingMoreChildren(true);
|
mVisibleComments.get(commentPosition).setLoadingMoreChildren(true);
|
||||||
mVisibleComments.get(commentPosition).setLoadMoreChildrenFailed(false);
|
mVisibleComments.get(commentPosition).setLoadMoreChildrenFailed(false);
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
|
||||||
|
|
||||||
Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
|
Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
|
||||||
FetchComment.fetchMoreComment(retrofit, mAccessToken, parentComment.getMoreChildrenFullnames(),
|
FetchComment.fetchMoreComment(retrofit, mAccessToken, parentComment.getMoreChildrenFullnames(),
|
||||||
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1,
|
parentComment.getMoreChildrenStartingIndex(), parentComment.getDepth() + 1,
|
||||||
mExpandChildren, mLocale,
|
mExpandChildren, mLocale,
|
||||||
new FetchComment.FetchMoreCommentListener() {
|
new FetchComment.FetchMoreCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchMoreCommentSuccess(ArrayList<Comment> expandedComments,
|
public void onFetchMoreCommentSuccess(ArrayList<Comment> expandedComments,
|
||||||
int childrenStartingIndex) {
|
int childrenStartingIndex) {
|
||||||
if (mVisibleComments.size() > parentPosition
|
if (mVisibleComments.size() > parentPosition
|
||||||
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
|
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
|
||||||
if (mVisibleComments.get(parentPosition).isExpanded()) {
|
if (mVisibleComments.get(parentPosition).isExpanded()) {
|
||||||
if (mVisibleComments.get(parentPosition).getChildren().size() > childrenStartingIndex) {
|
if (mVisibleComments.get(parentPosition).getChildren().size() > childrenStartingIndex) {
|
||||||
mVisibleComments.get(parentPosition).setMoreChildrenStartingIndex(childrenStartingIndex);
|
mVisibleComments.get(parentPosition).setMoreChildrenStartingIndex(childrenStartingIndex);
|
||||||
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
||||||
.setLoadingMoreChildren(false);
|
.setLoadingMoreChildren(false);
|
||||||
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
||||||
.setLoadMoreChildrenFailed(false);
|
.setLoadMoreChildrenFailed(false);
|
||||||
|
|
||||||
int placeholderPosition = commentPosition;
|
int placeholderPosition = commentPosition;
|
||||||
if (mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
if (mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
||||||
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
||||||
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
||||||
placeholderPosition = i;
|
placeholderPosition = i;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
|
||||||
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(false);
|
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments);
|
|
||||||
|
|
||||||
mVisibleComments.addAll(placeholderPosition, expandedComments);
|
|
||||||
if (mIsSingleCommentThreadMode) {
|
|
||||||
notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
|
|
||||||
} else {
|
|
||||||
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mVisibleComments.get(parentPosition).getChildren()
|
|
||||||
.remove(mVisibleComments.get(parentPosition).getChildren().size() - 1);
|
|
||||||
mVisibleComments.get(parentPosition).removeMoreChildrenFullnames();
|
|
||||||
|
|
||||||
int placeholderPosition = commentPosition;
|
|
||||||
if (mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
|
||||||
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
placeholderPosition = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.remove(placeholderPosition);
|
|
||||||
if (mIsSingleCommentThreadMode) {
|
|
||||||
notifyItemRemoved(placeholderPosition + 2);
|
|
||||||
} else {
|
|
||||||
notifyItemRemoved(placeholderPosition + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.addAll(placeholderPosition, expandedComments);
|
|
||||||
if (mIsSingleCommentThreadMode) {
|
|
||||||
notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
|
|
||||||
} else {
|
|
||||||
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mVisibleComments.get(parentPosition).hasReply() && mVisibleComments.get(parentPosition).getChildren().size() <= childrenStartingIndex) {
|
|
||||||
mVisibleComments.get(parentPosition).getChildren()
|
|
||||||
.remove(mVisibleComments.get(parentPosition).getChildren().size() - 1);
|
|
||||||
mVisibleComments.get(parentPosition).removeMoreChildrenFullnames();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.get(parentPosition).addChildren(expandedComments);
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < mVisibleComments.size(); i++) {
|
|
||||||
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
if (mVisibleComments.get(i).isExpanded()) {
|
|
||||||
int placeholderPosition = i + mVisibleComments.get(i).getChildren().size();
|
|
||||||
|
|
||||||
if (!mVisibleComments.get(i).getFullName()
|
|
||||||
.equals(mVisibleComments.get(placeholderPosition).getFullName())) {
|
|
||||||
for (int j = i + 1; j < mVisibleComments.size(); j++) {
|
|
||||||
if (mVisibleComments.get(j).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
|
||||||
placeholderPosition = j;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1303,75 +1237,150 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
} else {
|
} else {
|
||||||
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
mVisibleComments.get(parentPosition).getChildren()
|
||||||
|
.remove(mVisibleComments.get(parentPosition).getChildren().size() - 1);
|
||||||
|
mVisibleComments.get(parentPosition).removeMoreChildrenFullnames();
|
||||||
|
|
||||||
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1)
|
int placeholderPosition = commentPosition;
|
||||||
.setLoadingMoreChildren(false);
|
if (mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
||||||
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1)
|
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
||||||
.setLoadMoreChildrenFailed(false);
|
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
||||||
mVisibleComments.get(i).addChildren(expandedComments);
|
placeholderPosition = i;
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFetchMoreCommentFailed() {
|
|
||||||
if (parentPosition < mVisibleComments.size()
|
|
||||||
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
|
|
||||||
if (mVisibleComments.get(parentPosition).isExpanded()) {
|
|
||||||
int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1;
|
|
||||||
int placeholderPosition = commentPosition;
|
|
||||||
if (commentPosition >= mVisibleComments.size() || commentPosition < 0 || !mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
|
||||||
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
placeholderPosition = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
|
||||||
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
|
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
|
||||||
.setLoadingMoreChildren(false);
|
|
||||||
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
|
||||||
.setLoadMoreChildrenFailed(true);
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < mVisibleComments.size(); i++) {
|
|
||||||
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
|
||||||
if (mVisibleComments.get(i).isExpanded()) {
|
|
||||||
int placeholderPosition = i + mVisibleComments.get(i).getChildren().size();
|
|
||||||
if (!mVisibleComments.get(placeholderPosition).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
|
||||||
for (int j = i + 1; j < mVisibleComments.size(); j++) {
|
|
||||||
if (mVisibleComments.get(j).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
|
||||||
placeholderPosition = j;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
mVisibleComments.remove(placeholderPosition);
|
||||||
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
|
if (mIsSingleCommentThreadMode) {
|
||||||
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
notifyItemRemoved(placeholderPosition + 2);
|
||||||
|
} else {
|
||||||
|
notifyItemRemoved(placeholderPosition + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.addAll(placeholderPosition, expandedComments);
|
||||||
|
if (mIsSingleCommentThreadMode) {
|
||||||
|
notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
|
||||||
|
} else {
|
||||||
|
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (mVisibleComments.get(parentPosition).hasReply() && mVisibleComments.get(parentPosition).getChildren().size() <= childrenStartingIndex) {
|
||||||
|
mVisibleComments.get(parentPosition).getChildren()
|
||||||
|
.remove(mVisibleComments.get(parentPosition).getChildren().size() - 1);
|
||||||
|
mVisibleComments.get(parentPosition).removeMoreChildrenFullnames();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1).setLoadingMoreChildren(false);
|
mVisibleComments.get(parentPosition).addChildren(expandedComments);
|
||||||
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1).setLoadMoreChildrenFailed(true);
|
} else {
|
||||||
|
for (int i = 0; i < mVisibleComments.size(); i++) {
|
||||||
|
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
||||||
|
if (mVisibleComments.get(i).isExpanded()) {
|
||||||
|
int placeholderPosition = i + mVisibleComments.get(i).getChildren().size();
|
||||||
|
|
||||||
break;
|
if (!mVisibleComments.get(i).getFullName()
|
||||||
|
.equals(mVisibleComments.get(placeholderPosition).getFullName())) {
|
||||||
|
for (int j = i + 1; j < mVisibleComments.size(); j++) {
|
||||||
|
if (mVisibleComments.get(j).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
||||||
|
placeholderPosition = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(false);
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments);
|
||||||
|
|
||||||
|
mVisibleComments.addAll(placeholderPosition, expandedComments);
|
||||||
|
if (mIsSingleCommentThreadMode) {
|
||||||
|
notifyItemRangeInserted(placeholderPosition + 2, expandedComments.size());
|
||||||
|
} else {
|
||||||
|
notifyItemRangeInserted(placeholderPosition + 1, expandedComments.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1)
|
||||||
|
.setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1)
|
||||||
|
.setLoadMoreChildrenFailed(false);
|
||||||
|
mVisibleComments.get(i).addChildren(expandedComments);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
@Override
|
||||||
}
|
public void onFetchMoreCommentFailed() {
|
||||||
});
|
if (parentPosition < mVisibleComments.size()
|
||||||
|
&& parentComment.getFullName().equals(mVisibleComments.get(parentPosition).getFullName())) {
|
||||||
|
if (mVisibleComments.get(parentPosition).isExpanded()) {
|
||||||
|
int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 2 : holder.getBindingAdapterPosition() - 1;
|
||||||
|
int placeholderPosition = commentPosition;
|
||||||
|
if (commentPosition >= mVisibleComments.size() || commentPosition < 0 || !mVisibleComments.get(commentPosition).getFullName().equals(parentComment.getFullName())) {
|
||||||
|
for (int i = parentPosition + 1; i < mVisibleComments.size(); i++) {
|
||||||
|
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
||||||
|
placeholderPosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
||||||
|
.setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(parentPosition).getChildren().get(mVisibleComments.get(parentPosition).getChildren().size() - 1)
|
||||||
|
.setLoadMoreChildrenFailed(true);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < mVisibleComments.size(); i++) {
|
||||||
|
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
|
||||||
|
if (mVisibleComments.get(i).isExpanded()) {
|
||||||
|
int placeholderPosition = i + mVisibleComments.get(i).getChildren().size();
|
||||||
|
if (!mVisibleComments.get(placeholderPosition).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
||||||
|
for (int j = i + 1; j < mVisibleComments.size(); j++) {
|
||||||
|
if (mVisibleComments.get(j).getFullName().equals(mVisibleComments.get(i).getFullName())) {
|
||||||
|
placeholderPosition = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1).setLoadingMoreChildren(false);
|
||||||
|
mVisibleComments.get(i).getChildren().get(mVisibleComments.get(i).getChildren().size() - 1).setLoadMoreChildrenFailed(true);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setOnClickListener(view -> {
|
||||||
|
Comment comment = getCurrentComment(position);
|
||||||
|
if (comment != null) {
|
||||||
|
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||||
|
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, mPost);
|
||||||
|
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getParentId());
|
||||||
|
intent.putExtra(ViewPostDetailActivity.EXTRA_CONTEXT_NUMBER, "0");
|
||||||
|
mActivity.startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
if (holder instanceof CommentViewHolder) {
|
if (holder instanceof CommentViewHolder) {
|
||||||
Comment comment = getItem(holder.getAdapterPosition());
|
Comment comment = getItem(holder.getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
|
if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
|
||||||
String name = "u/" + comment.getLinkAuthor();
|
String name = "u/" + comment.getLinkAuthor();
|
||||||
@ -477,11 +477,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
commentDivider.setBackgroundColor(mDividerColor);
|
commentDivider.setBackgroundColor(mDividerColor);
|
||||||
|
|
||||||
authorTextView.setOnClickListener(view -> {
|
authorTextView.setOnClickListener(view -> {
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Comment comment = getItem(getAdapterPosition());
|
Comment comment = getItem(getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
|
if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
|
||||||
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
|
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
|
||||||
@ -496,11 +496,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
});
|
});
|
||||||
|
|
||||||
moreButton.setOnClickListener(view -> {
|
moreButton.setOnClickListener(view -> {
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Comment comment = getItem(getAdapterPosition());
|
Comment comment = getItem(getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
if (comment.getAuthor().equals(mAccountName)) {
|
if (comment.getAuthor().equals(mAccountName)) {
|
||||||
@ -508,7 +508,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
}
|
}
|
||||||
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment);
|
bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment);
|
||||||
bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition());
|
bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getBindingAdapterPosition());
|
||||||
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_COMMENT_MARKDOWN, comment.getCommentMarkdown());
|
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_COMMENT_MARKDOWN, comment.getCommentMarkdown());
|
||||||
CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment();
|
CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment();
|
||||||
commentMoreBottomSheetFragment.setArguments(bundle);
|
commentMoreBottomSheetFragment.setArguments(bundle);
|
||||||
@ -517,11 +517,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
});
|
});
|
||||||
|
|
||||||
itemView.setOnClickListener(view -> {
|
itemView.setOnClickListener(view -> {
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Comment comment = getItem(getAdapterPosition());
|
Comment comment = getItem(getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId());
|
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId());
|
||||||
@ -542,11 +542,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Comment comment = getItem(getAdapterPosition());
|
Comment comment = getItem(getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
int previousVoteType = comment.getVoteType();
|
int previousVoteType = comment.getVoteType();
|
||||||
String newVoteType;
|
String newVoteType;
|
||||||
@ -574,7 +574,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
int currentPosition = getAdapterPosition();
|
int currentPosition = getBindingAdapterPosition();
|
||||||
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
|
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
|
||||||
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
|
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
|
||||||
if (currentPosition == position) {
|
if (currentPosition == position) {
|
||||||
@ -599,7 +599,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position) {
|
public void onVoteThingFail(int position) {
|
||||||
}
|
}
|
||||||
}, comment.getFullName(), newVoteType, getAdapterPosition());
|
}, comment.getFullName(), newVoteType, getBindingAdapterPosition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -609,11 +609,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Comment comment = getItem(getAdapterPosition());
|
Comment comment = getItem(getBindingAdapterPosition());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
int previousVoteType = comment.getVoteType();
|
int previousVoteType = comment.getVoteType();
|
||||||
String newVoteType;
|
String newVoteType;
|
||||||
@ -640,7 +640,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
int currentPosition = getAdapterPosition();
|
int currentPosition = getBindingAdapterPosition();
|
||||||
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
|
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
|
||||||
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
|
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
|
||||||
if (currentPosition == position) {
|
if (currentPosition == position) {
|
||||||
@ -665,12 +665,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position1) {
|
public void onVoteThingFail(int position1) {
|
||||||
}
|
}
|
||||||
}, comment.getFullName(), newVoteType, getAdapterPosition());
|
}, comment.getFullName(), newVoteType, getBindingAdapterPosition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
saveButton.setOnClickListener(view -> {
|
saveButton.setOnClickListener(view -> {
|
||||||
int position = getAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position < 0) {
|
if (position < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -682,7 +682,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
comment.setSaved(false);
|
comment.setSaved(false);
|
||||||
if (getAdapterPosition() == position) {
|
if (getBindingAdapterPosition() == position) {
|
||||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||||
}
|
}
|
||||||
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
|
||||||
@ -691,7 +691,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
comment.setSaved(true);
|
comment.setSaved(true);
|
||||||
if (getAdapterPosition() == position) {
|
if (getBindingAdapterPosition() == position) {
|
||||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||||
}
|
}
|
||||||
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
|
||||||
@ -703,7 +703,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
comment.setSaved(true);
|
comment.setSaved(true);
|
||||||
if (getAdapterPosition() == position) {
|
if (getBindingAdapterPosition() == position) {
|
||||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||||
}
|
}
|
||||||
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
|
||||||
@ -712,7 +712,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
comment.setSaved(false);
|
comment.setSaved(false);
|
||||||
if (getAdapterPosition() == position) {
|
if (getBindingAdapterPosition() == position) {
|
||||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||||
}
|
}
|
||||||
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -197,18 +197,18 @@ public interface RedditAPI {
|
|||||||
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
|
@GET("/r/{subredditName}/about/rules.json?raw_json=1")
|
||||||
Call<String> getRules(@Path("subredditName") String subredditName);
|
Call<String> getRules(@Path("subredditName") String subredditName);
|
||||||
|
|
||||||
@GET("/comments/{id}/placeholder/{singleCommentId}.json?context=8&raw_json=1")
|
@GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
|
Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
|
||||||
@Query("sort") String sortType,
|
@Query("sort") String sortType, @Query("context") String contextNumber,
|
||||||
@HeaderMap Map<String, String> headers);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("/comments/{id}.json?raw_json=1")
|
@GET("/comments/{id}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") String sortType,
|
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") String sortType,
|
||||||
@HeaderMap Map<String, String> headers);
|
@HeaderMap Map<String, String> headers);
|
||||||
|
|
||||||
@GET("/comments/{id}/placeholder/{singleCommentId}.json?context=8&raw_json=1")
|
@GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
|
Call<String> getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
|
||||||
@Query("sort") String sortType);
|
@Query("sort") String sortType, @Query("context") String contextNumber);
|
||||||
|
|
||||||
@GET("/comments/{id}.json?raw_json=1")
|
@GET("/comments/{id}.json?raw_json=1")
|
||||||
Call<String> getPostAndCommentsById(@Path("id") String id, @Query("sort") String sortType);
|
Call<String> getPostAndCommentsById(@Path("id") String id, @Query("sort") String sortType);
|
||||||
|
@ -11,6 +11,9 @@ public class Comment implements Parcelable {
|
|||||||
public static final int VOTE_TYPE_NO_VOTE = 0;
|
public static final int VOTE_TYPE_NO_VOTE = 0;
|
||||||
public static final int VOTE_TYPE_UPVOTE = 1;
|
public static final int VOTE_TYPE_UPVOTE = 1;
|
||||||
public static final int VOTE_TYPE_DOWNVOTE = -1;
|
public static final int VOTE_TYPE_DOWNVOTE = -1;
|
||||||
|
public static final int NOT_PLACEHOLDER = 0;
|
||||||
|
public static final int PLACEHOLDER_LOAD_MORE_COMMENTS = 1;
|
||||||
|
public static final int PLACEHOLDER_CONTINUE_THREAD = 2;
|
||||||
public static final Creator<Comment> CREATOR = new Creator<Comment>() {
|
public static final Creator<Comment> CREATOR = new Creator<Comment>() {
|
||||||
@Override
|
@Override
|
||||||
public Comment createFromParcel(Parcel in) {
|
public Comment createFromParcel(Parcel in) {
|
||||||
@ -50,7 +53,7 @@ public class Comment implements Parcelable {
|
|||||||
private ArrayList<Comment> children;
|
private ArrayList<Comment> children;
|
||||||
private ArrayList<String> moreChildrenFullnames;
|
private ArrayList<String> moreChildrenFullnames;
|
||||||
private int moreChildrenStartingIndex;
|
private int moreChildrenStartingIndex;
|
||||||
private boolean isPlaceHolder;
|
private int placeholderType;
|
||||||
private boolean isLoadingMoreChildren;
|
private boolean isLoadingMoreChildren;
|
||||||
private boolean loadMoreChildrenFailed;
|
private boolean loadMoreChildrenFailed;
|
||||||
|
|
||||||
@ -87,17 +90,25 @@ public class Comment implements Parcelable {
|
|||||||
this.isExpanded = false;
|
this.isExpanded = false;
|
||||||
this.hasExpandedBefore = false;
|
this.hasExpandedBefore = false;
|
||||||
moreChildrenStartingIndex = 0;
|
moreChildrenStartingIndex = 0;
|
||||||
isPlaceHolder = false;
|
placeholderType = NOT_PLACEHOLDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Comment(String parentFullName, int depth) {
|
public Comment(String parentFullName, int depth, int placeholderType) {
|
||||||
this.fullName = parentFullName;
|
if (placeholderType == PLACEHOLDER_LOAD_MORE_COMMENTS) {
|
||||||
|
this.fullName = parentFullName;
|
||||||
|
} else {
|
||||||
|
this.parentId = parentFullName.substring(3);
|
||||||
|
}
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
isPlaceHolder = true;
|
this.placeholderType = placeholderType;
|
||||||
isLoadingMoreChildren = false;
|
isLoadingMoreChildren = false;
|
||||||
loadMoreChildrenFailed = false;
|
loadMoreChildrenFailed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Comment(String parentFullName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected Comment(Parcel in) {
|
protected Comment(Parcel in) {
|
||||||
id = in.readString();
|
id = in.readString();
|
||||||
fullName = in.readString();
|
fullName = in.readString();
|
||||||
@ -126,7 +137,7 @@ public class Comment implements Parcelable {
|
|||||||
children = in.readArrayList(Comment.class.getClassLoader());
|
children = in.readArrayList(Comment.class.getClassLoader());
|
||||||
moreChildrenFullnames = in.readArrayList(Comment.class.getClassLoader());
|
moreChildrenFullnames = in.readArrayList(Comment.class.getClassLoader());
|
||||||
moreChildrenStartingIndex = in.readInt();
|
moreChildrenStartingIndex = in.readInt();
|
||||||
isPlaceHolder = in.readByte() != 0;
|
placeholderType = in.readInt();
|
||||||
isLoadingMoreChildren = in.readByte() != 0;
|
isLoadingMoreChildren = in.readByte() != 0;
|
||||||
loadMoreChildrenFailed = in.readByte() != 0;
|
loadMoreChildrenFailed = in.readByte() != 0;
|
||||||
}
|
}
|
||||||
@ -286,7 +297,7 @@ public class Comment implements Parcelable {
|
|||||||
if (children == null || children.size() == 0) {
|
if (children == null || children.size() == 0) {
|
||||||
setChildren(moreChildren);
|
setChildren(moreChildren);
|
||||||
} else {
|
} else {
|
||||||
if (children.size() > 1 && children.get(children.size() - 1).isPlaceHolder) {
|
if (children.size() > 1 && children.get(children.size() - 1).placeholderType == PLACEHOLDER_LOAD_MORE_COMMENTS) {
|
||||||
children.addAll(children.size() - 2, moreChildren);
|
children.addAll(children.size() - 2, moreChildren);
|
||||||
} else {
|
} else {
|
||||||
children.addAll(moreChildren);
|
children.addAll(moreChildren);
|
||||||
@ -329,8 +340,8 @@ public class Comment implements Parcelable {
|
|||||||
this.moreChildrenStartingIndex = moreChildrenStartingIndex;
|
this.moreChildrenStartingIndex = moreChildrenStartingIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaceHolder() {
|
public int getPlaceholderType() {
|
||||||
return isPlaceHolder;
|
return placeholderType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoadingMoreChildren() {
|
public boolean isLoadingMoreChildren() {
|
||||||
@ -383,7 +394,7 @@ public class Comment implements Parcelable {
|
|||||||
parcel.writeList(children);
|
parcel.writeList(children);
|
||||||
parcel.writeList(moreChildrenFullnames);
|
parcel.writeList(moreChildrenFullnames);
|
||||||
parcel.writeInt(moreChildrenStartingIndex);
|
parcel.writeInt(moreChildrenStartingIndex);
|
||||||
parcel.writeByte((byte) (isPlaceHolder ? 1 : 0));
|
parcel.writeInt(placeholderType);
|
||||||
parcel.writeByte((byte) (isLoadingMoreChildren ? 1 : 0));
|
parcel.writeByte((byte) (isLoadingMoreChildren ? 1 : 0));
|
||||||
parcel.writeByte((byte) (loadMoreChildrenFailed ? 1 : 0));
|
parcel.writeByte((byte) (loadMoreChildrenFailed ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
|||||||
for (int i = 0; i < commentsJSONArray.length(); i++) {
|
for (int i = 0; i < commentsJSONArray.length(); i++) {
|
||||||
try {
|
try {
|
||||||
JSONObject commentJSON = commentsJSONArray.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
JSONObject commentJSON = commentsJSONArray.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||||
comments.add(ParseComment.parseSingleComment(commentJSON, 0, locale));
|
comments.add(ParseComment.parseSingleComment(commentJSON, 0));
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
public class FetchComment {
|
public class FetchComment {
|
||||||
public static void fetchComments(Retrofit retrofit, @Nullable String accessToken, String article,
|
public static void fetchComments(Retrofit retrofit, @Nullable String accessToken, String article,
|
||||||
String commentId, String sortType, boolean expandChildren,
|
String commentId, String sortType, String contextNumber, boolean expandChildren,
|
||||||
Locale locale, FetchCommentListener fetchCommentListener) {
|
Locale locale, FetchCommentListener fetchCommentListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> comments;
|
Call<String> comments;
|
||||||
@ -23,13 +23,13 @@ public class FetchComment {
|
|||||||
if (commentId == null) {
|
if (commentId == null) {
|
||||||
comments = api.getPostAndCommentsById(article, sortType);
|
comments = api.getPostAndCommentsById(article, sortType);
|
||||||
} else {
|
} else {
|
||||||
comments = api.getPostAndCommentsSingleThreadById(article, commentId, sortType);
|
comments = api.getPostAndCommentsSingleThreadById(article, commentId, sortType, contextNumber);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (commentId == null) {
|
if (commentId == null) {
|
||||||
comments = api.getPostAndCommentsByIdOauth(article, sortType, APIUtils.getOAuthHeader(accessToken));
|
comments = api.getPostAndCommentsByIdOauth(article, sortType, APIUtils.getOAuthHeader(accessToken));
|
||||||
} else {
|
} else {
|
||||||
comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, sortType,
|
comments = api.getPostAndCommentsSingleThreadByIdOauth(article, commentId, sortType, contextNumber,
|
||||||
APIUtils.getOAuthHeader(accessToken));
|
APIUtils.getOAuthHeader(accessToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,13 +70,18 @@ public class ParseComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actualCommentLength = comments.length() - 1;
|
actualCommentLength = comments.length() - 1;
|
||||||
|
|
||||||
|
if (moreChildrenFullnames.isEmpty() && comments.getJSONObject(comments.length() - 1).getString(JSONUtils.KIND_KEY).equals(JSONUtils.KIND_VALUE_MORE)) {
|
||||||
|
newCommentData.add(new Comment(more.getString(JSONUtils.PARENT_ID_KEY), more.getInt(JSONUtils.DEPTH_KEY), Comment.PLACEHOLDER_CONTINUE_THREAD));
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
actualCommentLength = comments.length();
|
actualCommentLength = comments.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < actualCommentLength; i++) {
|
for (int i = 0; i < actualCommentLength; i++) {
|
||||||
JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||||
Comment singleComment = parseSingleComment(data, depth, locale);
|
Comment singleComment = parseSingleComment(data, depth);
|
||||||
|
|
||||||
if (data.get(JSONUtils.REPLIES_KEY) instanceof JSONObject) {
|
if (data.get(JSONUtils.REPLIES_KEY) instanceof JSONObject) {
|
||||||
JSONArray childrenArray = data.getJSONObject(JSONUtils.REPLIES_KEY)
|
JSONArray childrenArray = data.getJSONObject(JSONUtils.REPLIES_KEY)
|
||||||
@ -107,14 +112,14 @@ public class ParseComment {
|
|||||||
}
|
}
|
||||||
if (c.hasMoreChildrenFullnames() && c.getMoreChildrenFullnames().size() > c.getMoreChildrenStartingIndex()) {
|
if (c.hasMoreChildrenFullnames() && c.getMoreChildrenFullnames().size() > c.getMoreChildrenStartingIndex()) {
|
||||||
//Add a load more placeholder
|
//Add a load more placeholder
|
||||||
Comment placeholder = new Comment(c.getFullName(), c.getDepth() + 1);
|
Comment placeholder = new Comment(c.getFullName(), c.getDepth() + 1, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS);
|
||||||
visibleComments.add(placeholder);
|
visibleComments.add(placeholder);
|
||||||
c.addChild(placeholder, c.getChildren().size());
|
c.addChild(placeholder, c.getChildren().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Comment parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
|
static Comment parseSingleComment(JSONObject singleCommentData, int depth) throws JSONException {
|
||||||
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
||||||
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
||||||
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
|
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
|
||||||
@ -262,6 +267,7 @@ public class ParseComment {
|
|||||||
expandChildren(newComments, expandedNewComments, expandChildren);
|
expandChildren(newComments, expandedNewComments, expandChildren);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
parseFailed = true;
|
parseFailed = true;
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -302,7 +308,7 @@ public class ParseComment {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
JSONObject sentCommentData = new JSONObject(response);
|
JSONObject sentCommentData = new JSONObject(response);
|
||||||
comment = parseSingleComment(sentCommentData, depth, locale);
|
comment = parseSingleComment(sentCommentData, depth);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
errorMessage = parseSentCommentErrorMessage(response);
|
errorMessage = parseSentCommentErrorMessage(response);
|
||||||
|
@ -117,6 +117,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
public static final String EXTRA_POST_DATA = "EPD";
|
public static final String EXTRA_POST_DATA = "EPD";
|
||||||
public static final String EXTRA_POST_ID = "EPI";
|
public static final String EXTRA_POST_ID = "EPI";
|
||||||
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
||||||
|
public static final String EXTRA_CONTEXT_NUMBER = "ECN";
|
||||||
public static final String EXTRA_MESSAGE_FULLNAME = "EMF";
|
public static final String EXTRA_MESSAGE_FULLNAME = "EMF";
|
||||||
public static final String EXTRA_POST_LIST_POSITION = "EPLP";
|
public static final String EXTRA_POST_LIST_POSITION = "EPLP";
|
||||||
private static final int EDIT_POST_REQUEST_CODE = 2;
|
private static final int EDIT_POST_REQUEST_CODE = 2;
|
||||||
@ -202,6 +203,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private int postListPosition = -1;
|
private int postListPosition = -1;
|
||||||
private String mSingleCommentId;
|
private String mSingleCommentId;
|
||||||
|
private String mContextNumber;
|
||||||
private boolean showToast = false;
|
private boolean showToast = false;
|
||||||
private boolean isSortingComments = false;
|
private boolean isSortingComments = false;
|
||||||
private boolean mIsSmoothScrolling = false;
|
private boolean mIsSmoothScrolling = false;
|
||||||
@ -461,6 +463,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
};
|
};
|
||||||
|
|
||||||
mSingleCommentId = getArguments().getString(EXTRA_SINGLE_COMMENT_ID);
|
mSingleCommentId = getArguments().getString(EXTRA_SINGLE_COMMENT_ID);
|
||||||
|
mContextNumber = getArguments().getString(EXTRA_CONTEXT_NUMBER, "8");
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
if (mSingleCommentId != null) {
|
if (mSingleCommentId != null) {
|
||||||
isSingleCommentThreadMode = true;
|
isSingleCommentThreadMode = true;
|
||||||
@ -1055,7 +1059,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
if (isSingleCommentThreadMode && mSingleCommentId != null) {
|
if (isSingleCommentThreadMode && mSingleCommentId != null) {
|
||||||
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadById(
|
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadById(
|
||||||
subredditId, mSingleCommentId, sortType);
|
subredditId, mSingleCommentId, sortType, mContextNumber);
|
||||||
} else {
|
} else {
|
||||||
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId,
|
postAndComments = mRetrofit.create(RedditAPI.class).getPostAndCommentsById(subredditId,
|
||||||
sortType);
|
sortType);
|
||||||
@ -1063,7 +1067,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
} else {
|
} else {
|
||||||
if (isSingleCommentThreadMode && mSingleCommentId != null) {
|
if (isSingleCommentThreadMode && mSingleCommentId != null) {
|
||||||
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId,
|
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsSingleThreadByIdOauth(subredditId,
|
||||||
mSingleCommentId, sortType, APIUtils.getOAuthHeader(mAccessToken));
|
mSingleCommentId, sortType, mContextNumber, APIUtils.getOAuthHeader(mAccessToken));
|
||||||
} else {
|
} else {
|
||||||
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId,
|
postAndComments = mOauthRetrofit.create(RedditAPI.class).getPostAndCommentsByIdOauth(subredditId,
|
||||||
sortType, APIUtils.getOAuthHeader(mAccessToken));
|
sortType, APIUtils.getOAuthHeader(mAccessToken));
|
||||||
@ -1240,8 +1244,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
}
|
}
|
||||||
|
|
||||||
Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
|
Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
|
||||||
FetchComment.fetchComments(retrofit, mAccessToken, mPost.getId(), commentId, sortType, mExpandChildren,
|
FetchComment.fetchComments(retrofit, mAccessToken, mPost.getId(), commentId, sortType,
|
||||||
mLocale, new FetchComment.FetchCommentListener() {
|
mContextNumber, mExpandChildren, mLocale, new FetchComment.FetchCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
|
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
|
||||||
String parentId, ArrayList<String> children) {
|
String parentId, ArrayList<String> children) {
|
||||||
|
@ -6,6 +6,7 @@ package ml.docilealligator.infinityforreddit.utils;
|
|||||||
|
|
||||||
public class JSONUtils {
|
public class JSONUtils {
|
||||||
public static final String KIND_KEY = "kind";
|
public static final String KIND_KEY = "kind";
|
||||||
|
public static final String KIND_VALUE_MORE = "more";
|
||||||
public static final String DATA_KEY = "data";
|
public static final String DATA_KEY = "data";
|
||||||
public static final String AFTER_KEY = "after";
|
public static final String AFTER_KEY = "after";
|
||||||
public static final String CHILDREN_KEY = "children";
|
public static final String CHILDREN_KEY = "children";
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:text="@string/comment_load_more_comments"
|
|
||||||
android:textColor="?attr/primaryTextColor"
|
android:textColor="?attr/primaryTextColor"
|
||||||
android:textSize="?attr/font_default"
|
android:textSize="?attr/font_default"
|
||||||
android:fontFamily="?attr/font_family" />
|
android:fontFamily="?attr/font_family" />
|
||||||
|
@ -193,6 +193,7 @@
|
|||||||
|
|
||||||
<string name="comment_load_more_comments">Load more comments</string>
|
<string name="comment_load_more_comments">Load more comments</string>
|
||||||
<string name="comment_load_more_comments_failed">Load failed. Tap to retry.</string>
|
<string name="comment_load_more_comments_failed">Load failed. Tap to retry.</string>
|
||||||
|
<string name="comment_continue_thread">Continue thread</string>
|
||||||
|
|
||||||
<string name="loading">Loading</string>
|
<string name="loading">Loading</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user