diff --git a/src/main/java/org/quantumbadger/redreader/common/RRThemeAttributes.java b/src/main/java/org/quantumbadger/redreader/common/RRThemeAttributes.java index f0901fc75..07ddfa3fe 100644 --- a/src/main/java/org/quantumbadger/redreader/common/RRThemeAttributes.java +++ b/src/main/java/org/quantumbadger/redreader/common/RRThemeAttributes.java @@ -41,6 +41,12 @@ public class RRThemeAttributes { public final int rrCrosspostBackCol; public final int rrCrosspostTextCol; + public final int rrIndentLineCol1; + public final int rrIndentLineCol2; + public final int rrIndentLineCol3; + public final int rrIndentLineCol4; + public final int rrIndentLineCol5; + private final EnumSet mCommentHeaderItems; public final float rrCommentFontScale; @@ -62,7 +68,12 @@ public RRThemeAttributes(final Context context) { R.attr.rrMainTextCol, com.google.android.material.R.attr.colorAccent, R.attr.rrCrosspostBackCol, - R.attr.rrCrosspostTextCol + R.attr.rrCrosspostTextCol, + R.attr.rrIndentLineCol1, + R.attr.rrIndentLineCol2, + R.attr.rrIndentLineCol3, + R.attr.rrIndentLineCol4, + R.attr.rrIndentLineCol5 }); rrCommentHeaderBoldCol = appearance.getColor(0, 255); @@ -79,6 +90,11 @@ public RRThemeAttributes(final Context context) { colorAccent = appearance.getColor(11, 255); rrCrosspostBackCol = appearance.getColor(12, 255); rrCrosspostTextCol = appearance.getColor(13, 255); + rrIndentLineCol1 = appearance.getColor(14, 0xFF6B8AC7); // Blue fallback + rrIndentLineCol2 = appearance.getColor(15, 0xFF5FA05F); // Green fallback + rrIndentLineCol3 = appearance.getColor(16, 0xFFCD8500); // Orange fallback + rrIndentLineCol4 = appearance.getColor(17, 0xFFB8374A); // Red fallback + rrIndentLineCol5 = appearance.getColor(18, 0xFF8E6FB8); // Purple fallback appearance.recycle(); diff --git a/src/main/java/org/quantumbadger/redreader/views/IndentView.java b/src/main/java/org/quantumbadger/redreader/views/IndentView.java index 1fc02873b..22040b158 100644 --- a/src/main/java/org/quantumbadger/redreader/views/IndentView.java +++ b/src/main/java/org/quantumbadger/redreader/views/IndentView.java @@ -27,6 +27,7 @@ import org.quantumbadger.redreader.R; import org.quantumbadger.redreader.common.General; import org.quantumbadger.redreader.common.PrefsUtility; +import org.quantumbadger.redreader.common.RRThemeAttributes; /** * Draws the left margin for comments based on the RedditPreparedComment#indentation number @@ -41,7 +42,8 @@ class IndentView extends View { private final boolean mPrefDrawLines; - private float[] mLineBuffer; + private final int[] mIndentColors; // Array to hold indentation colors + private final int mOriginalIndentLineCol; // Original single line color public IndentView(final Context context) { this(context, null); @@ -63,7 +65,6 @@ public IndentView( mHalfALine = mPixelsPerLine / 2; final int rrIndentBackgroundCol; - final int rrIndentLineCol; { final TypedArray attr = context.obtainStyledAttributes(new int[] { @@ -72,13 +73,20 @@ public IndentView( }); rrIndentBackgroundCol = attr.getColor(0, General.COLOR_INVALID); - rrIndentLineCol = attr.getColor(1, General.COLOR_INVALID); - + mOriginalIndentLineCol = attr.getColor(1, General.COLOR_INVALID); attr.recycle(); } + // Load indentation colors from RRThemeAttributes + final RRThemeAttributes themeAttributes = new RRThemeAttributes(context); + mIndentColors = new int[5]; + mIndentColors[0] = themeAttributes.rrIndentLineCol1; + mIndentColors[1] = themeAttributes.rrIndentLineCol2; + mIndentColors[2] = themeAttributes.rrIndentLineCol3; + mIndentColors[3] = themeAttributes.rrIndentLineCol4; + mIndentColors[4] = themeAttributes.rrIndentLineCol5; + this.setBackgroundColor(rrIndentBackgroundCol); - mPaint.setColor(rrIndentLineCol); mPaint.setStrokeWidth(mPixelsPerLine); mPrefDrawLines = PrefsUtility.pref_appearance_indentlines(); @@ -92,22 +100,19 @@ protected void onDraw(final Canvas canvas) { final int height = getMeasuredHeight(); if(mPrefDrawLines) { - // i keeps track of indentation, and - // l is to populate the float[] with line co-ordinates - int l = 0; - int i = 0; - while(i < mIndent) { - final float x = (mPixelsPerIndent * ++i) - mHalfALine; - mLineBuffer[l++] = x; // start-x - mLineBuffer[l++] = 0; // start-y - mLineBuffer[l++] = x; // stop-x - mLineBuffer[l++] = height; // stop-y + // Draw only the rightmost line with the appropriate color for this indentation level + if(mIndent > 0) { + final float rightLine = getWidth() - mHalfALine; + // Use color based on the current indentation level + mPaint.setColor(mIndentColors[(mIndent - 1) % mIndentColors.length]); + canvas.drawLine(rightLine, 0, rightLine, height, mPaint); } - canvas.drawLines(mLineBuffer, mPaint); } else { + // Use the original theme color when colorful bars are disabled + mPaint.setColor(mOriginalIndentLineCol); final float rightLine = getWidth() - mHalfALine; - canvas.drawLine(rightLine, 0, rightLine, getHeight(), mPaint); + canvas.drawLine(rightLine, 0, rightLine, height, mPaint); } } @@ -120,10 +125,6 @@ public void setIndentation(final int indent) { getLayoutParams().width = (mPixelsPerIndent * indent); mIndent = indent; - if(mPrefDrawLines) { - mLineBuffer = new float[mIndent * 4]; - } - invalidate(); requestLayout(); } diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index cf27036dd..16d31a2d5 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -32,8 +32,8 @@ - - + + @@ -116,4 +116,11 @@ + + + + + + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index eba05baca..25358735d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -506,7 +506,7 @@ - Show indent lines + Show colorful comment indent bars pref_appearance_indentlines