mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Color days on HistoryChart according to target
This commit is contained in:
@@ -38,6 +38,8 @@ public class HistoryChart extends ScrollableChart
|
||||
{
|
||||
private int[] checkmarks;
|
||||
|
||||
private int target;
|
||||
|
||||
private Paint pSquareBg, pSquareFg, pTextHeader;
|
||||
|
||||
private float squareSpacing;
|
||||
@@ -85,6 +87,8 @@ public class HistoryChart extends ScrollableChart
|
||||
|
||||
private float headerOverflow = 0;
|
||||
|
||||
private boolean isNumerical = false;
|
||||
|
||||
@NonNull
|
||||
private Controller controller;
|
||||
|
||||
@@ -168,6 +172,11 @@ public class HistoryChart extends ScrollableChart
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void setNumerical(boolean numerical)
|
||||
{
|
||||
isNumerical = numerical;
|
||||
}
|
||||
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
{
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
@@ -179,6 +188,12 @@ public class HistoryChart extends ScrollableChart
|
||||
this.isEditable = isEditable;
|
||||
}
|
||||
|
||||
public void setTarget(int target)
|
||||
{
|
||||
this.target = target;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
protected void initPaints()
|
||||
{
|
||||
pTextHeader = new Paint();
|
||||
@@ -326,7 +341,12 @@ public class HistoryChart extends ScrollableChart
|
||||
else
|
||||
{
|
||||
int checkmark = checkmarks[checkmarkOffset];
|
||||
pSquareBg.setColor(colors[Math.min(2, checkmark)]);
|
||||
if(checkmark == 0) pSquareBg.setColor(colors[0]);
|
||||
else if(checkmark < target)
|
||||
{
|
||||
pSquareBg.setColor(isNumerical ? textColor : colors[1]);
|
||||
}
|
||||
else pSquareBg.setColor(colors[2]);
|
||||
}
|
||||
|
||||
pSquareFg.setColor(reverseTextColor);
|
||||
@@ -351,6 +371,7 @@ public class HistoryChart extends ScrollableChart
|
||||
isEditable = false;
|
||||
checkmarks = new int[0];
|
||||
controller = new Controller() {};
|
||||
target = 2;
|
||||
|
||||
initColors();
|
||||
initPaints();
|
||||
|
||||
@@ -126,6 +126,11 @@ public class HistoryCard extends HabitCard
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
if(habit.isNumerical())
|
||||
{
|
||||
chart.setTarget((int) (habit.getTargetValue() * 1000));
|
||||
chart.setNumerical(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user