mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28: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[] checkmarks;
|
||||||
|
|
||||||
|
private int target;
|
||||||
|
|
||||||
private Paint pSquareBg, pSquareFg, pTextHeader;
|
private Paint pSquareBg, pSquareFg, pTextHeader;
|
||||||
|
|
||||||
private float squareSpacing;
|
private float squareSpacing;
|
||||||
@@ -85,6 +87,8 @@ public class HistoryChart extends ScrollableChart
|
|||||||
|
|
||||||
private float headerOverflow = 0;
|
private float headerOverflow = 0;
|
||||||
|
|
||||||
|
private boolean isNumerical = false;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Controller controller;
|
private Controller controller;
|
||||||
|
|
||||||
@@ -168,6 +172,11 @@ public class HistoryChart extends ScrollableChart
|
|||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNumerical(boolean numerical)
|
||||||
|
{
|
||||||
|
isNumerical = numerical;
|
||||||
|
}
|
||||||
|
|
||||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||||
{
|
{
|
||||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||||
@@ -179,6 +188,12 @@ public class HistoryChart extends ScrollableChart
|
|||||||
this.isEditable = isEditable;
|
this.isEditable = isEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTarget(int target)
|
||||||
|
{
|
||||||
|
this.target = target;
|
||||||
|
postInvalidate();
|
||||||
|
}
|
||||||
|
|
||||||
protected void initPaints()
|
protected void initPaints()
|
||||||
{
|
{
|
||||||
pTextHeader = new Paint();
|
pTextHeader = new Paint();
|
||||||
@@ -326,7 +341,12 @@ public class HistoryChart extends ScrollableChart
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int checkmark = checkmarks[checkmarkOffset];
|
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);
|
pSquareFg.setColor(reverseTextColor);
|
||||||
@@ -351,6 +371,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
isEditable = false;
|
isEditable = false;
|
||||||
checkmarks = new int[0];
|
checkmarks = new int[0];
|
||||||
controller = new Controller() {};
|
controller = new Controller() {};
|
||||||
|
target = 2;
|
||||||
|
|
||||||
initColors();
|
initColors();
|
||||||
initPaints();
|
initPaints();
|
||||||
|
|||||||
@@ -126,6 +126,11 @@ public class HistoryCard extends HabitCard
|
|||||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
title.setTextColor(color);
|
title.setTextColor(color);
|
||||||
chart.setColor(color);
|
chart.setColor(color);
|
||||||
|
if(habit.isNumerical())
|
||||||
|
{
|
||||||
|
chart.setTarget((int) (habit.getTargetValue() * 1000));
|
||||||
|
chart.setNumerical(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user