From ad78aebf679af89f54ae537186f89907851ff963 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 10 Apr 2021 16:55:52 +0800 Subject: Fix wrong colors in CommentIndentationView. --- .../CommentAndPostRecyclerViewAdapter.java | 3 --- .../customviews/CommentIndentationView.java | 23 ++++++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 06e0ee52..306b607a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -1896,11 +1896,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter paths; + private ArrayList 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); } } -- cgit v1.2.3