Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrefsUtility.AppearanceCommentHeaderItem> mCommentHeaderItems;

public final float rrCommentFontScale;
Expand All @@ -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);
Expand All @@ -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();

Expand Down
43 changes: 22 additions & 21 deletions src/main/java/org/quantumbadger/redreader/views/IndentView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -63,7 +65,6 @@ public IndentView(
mHalfALine = mPixelsPerLine / 2;

final int rrIndentBackgroundCol;
final int rrIndentLineCol;

{
final TypedArray attr = context.obtainStyledAttributes(new int[] {
Expand All @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -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();
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<attr name="rrIndentBackgroundCol" format="color" />
<attr name="rrIndentLineCol" format="color" />

<attr name="rrLoadingRingForegroundCol" />
<attr name="rrLoadingRingBackgroundCol" />
<attr name="rrLoadingRingForegroundCol" format="color" />
<attr name="rrLoadingRingBackgroundCol" format="color" />

<attr name="rrListItemBackgroundCol" format="color" />
<attr name="rrListItemBackgroundHighlightCol" format="color" />
Expand Down Expand Up @@ -116,4 +116,11 @@
<attr name="rrIconMagnify" format="reference" />
<attr name="rrIconAccountSearch" format="reference" />

<!-- Comment indentation line colors -->
<attr name="rrIndentLineCol1" format="color"/>
<attr name="rrIndentLineCol2" format="color"/>
<attr name="rrIndentLineCol3" format="color"/>
<attr name="rrIndentLineCol4" format="color"/>
<attr name="rrIndentLineCol5" format="color"/>

</resources>
2 changes: 1 addition & 1 deletion src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@

<!-- 2013-08-04 -->

<string name="pref_appearance_indentlines_title">Show indent lines</string>
<string name="pref_appearance_indentlines_title">Show colorful comment indent bars</string>
<string name="pref_appearance_indentlines_key" translatable="false">pref_appearance_indentlines</string>

<!-- 2014-03-14 -->
Expand Down
Loading