Fix wrong colors in CommentIndentationView.

This commit is contained in:
Alex Ning 2021-04-10 16:55:52 +08:00
parent bc27f077d6
commit ad78aebf67
2 changed files with 8 additions and 18 deletions

View File

@ -1896,11 +1896,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor);
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(0, verticalBlockColors);
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setLevelAndColors(0, verticalBlockColors);
} else if (holder instanceof LoadMoreChildCommentsViewHolder) {
((LoadMoreChildCommentsViewHolder) holder).commentIndentationView.setLevelAndColors(0, verticalBlockColors);
} else if (holder instanceof PostDetailBaseViewHolder) {
((PostDetailBaseViewHolder) holder).mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((PostDetailBaseViewHolder) holder).mScoreTextView.setTextColor(mPostIconAndInfoColor);

View File

@ -2,9 +2,7 @@ package ml.docilealligator.infinityforreddit.customviews;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.LinearLayout;
@ -19,7 +17,7 @@ public class CommentIndentationView extends LinearLayout {
private final Paint paint;
private int level;
private int[] colors;
private ArrayList<Path> paths;
private ArrayList<Integer> startXs;
private final int spacing;
private final int pathWidth;
@ -30,9 +28,8 @@ public class CommentIndentationView extends LinearLayout {
pathWidth = (int) Utils.convertDpToPixel(2, context);
spacing = pathWidth * 6;
paint.setStrokeWidth(pathWidth);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setPathEffect(new DashPathEffect(new float[] { pathWidth * 2, pathWidth * 2 }, 0));
paths = new ArrayList<>();
paint.setStyle(Paint.Style.STROKE);
startXs = new ArrayList<>();
}
@Override
@ -40,11 +37,7 @@ public class CommentIndentationView extends LinearLayout {
super.onLayout(changed, left, top, right, bottom);
for (int i = 0; i < level; i++) {
float startX = spacing * (i + 1) + pathWidth;
Path path = new Path();
path.moveTo(startX, 0);
path.lineTo(startX, getHeight());
paths.add(path);
startXs.add(spacing * (i + 1) + pathWidth);
}
}
@ -52,17 +45,17 @@ public class CommentIndentationView extends LinearLayout {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0; i < paths.size(); i++) {
for (int i = 0; i < startXs.size(); i++) {
paint.setColor(colors[i % 7]);
canvas.drawPath(paths.get(i), paint);
canvas.drawLine(startXs.get(i), 0, startXs.get(i), getHeight(), paint);
}
startXs.clear();
}
public void setLevelAndColors(int level, int[] colors) {
paths.clear();
this.colors = colors;
this.level = level;
int indentationSpacing = (int) (level * spacing + pathWidth);
int indentationSpacing = (level * spacing + pathWidth);
setPaddingRelative(indentationSpacing, 0, pathWidth, 0);
}
}