CheckmarkWidget now shows numerical values for numerical habits

pull/499/head
Thomas Saedt 6 years ago
parent ef22fd8dce
commit abd9eb51a4

@ -39,12 +39,20 @@ class CheckmarkWidget(
setPercentage(habit.scores.todayValue.toFloat())
setActiveColor(PaletteUtils.getColor(context, habit.color))
setName(habit.name)
setCheckmarkValue(habit.checkmarks.todayValue)
refresh()
}
v.setCheckmarkValue(habit.checkmarks.todayValue)
v.refresh()
}
override fun buildView() = CheckmarkWidgetView(context)
override fun buildView(): CheckmarkWidgetView{
return if (habit.isNumerical) {
NumericalCheckmarkWidgetView(context)
}else{
CheckmarkWidgetView(context)
}
}
override fun getDefaultHeight() = 125
override fun getDefaultWidth() = 125
}

@ -34,18 +34,18 @@ import static org.isoron.androidbase.utils.InterfaceUtils.getDimension;
public class CheckmarkWidgetView extends HabitWidgetView
{
private int activeColor;
protected int activeColor;
private float percentage;
protected float percentage;
@Nullable
private String name;
protected String name;
private RingView ring;
protected RingView ring;
private TextView label;
protected TextView label;
private int checkmarkValue;
protected int checkmarkValue;
public CheckmarkWidgetView(Context context)
{

@ -0,0 +1,51 @@
package org.isoron.uhabits.widgets.views
import android.content.Context
import android.util.AttributeSet
import org.isoron.androidbase.utils.StyledResources
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.habits.list.views.toShortString
import org.isoron.uhabits.core.models.Checkmark
class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
override fun refresh() {
if (backgroundPaint == null || frame == null || ring == null) return
//right now most of this code is copied over from the regular CheckmarkWidget. This is for testing purposes, just to get something working.
val res = StyledResources(context)
val text: String
val bgColor: Int
val fgColor: Int
val numberValue : Double = checkmarkValue / 1000.0
text = numberValue.toShortString()
bgColor = activeColor
fgColor = res.getColor(R.attr.highContrastReverseTextColor)
setShadowAlpha(0x4f)
rebuildBackground()
backgroundPaint!!.color = bgColor
frame.setBackgroundDrawable(background)
ring.percentage = percentage
ring.color = fgColor
ring.setBackgroundColor(bgColor)
ring.setText(text)
label.text = name
label.setTextColor(fgColor)
requestLayout()
postInvalidate()
}
}
Loading…
Cancel
Save