Simplify ScoreList

This commit is contained in:
2020-12-29 09:38:29 -06:00
parent 1c696e2561
commit 11863cd7b0
20 changed files with 161 additions and 393 deletions

View File

@@ -52,8 +52,12 @@ public class ScoreChartTest extends BaseViewTest
fixtures.purgeHabits(habitList);
habit = fixtures.createLongHabit();
Timestamp today = DateUtils.getTodayWithOffset();
List<Entry> known = habit.getComputedEntries().getKnown();
Timestamp oldest = known.get(known.size() - 1).getTimestamp();
view = new ScoreChart(targetContext);
view.setScores(habit.getScores().toList());
view.setScores(habit.getScores().getByInterval(oldest, today));
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
view.setBucketSize(7);
measureView(view, dpToPixels(300), dpToPixels(200));

View File

@@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.*
import androidx.test.filters.*
import org.isoron.uhabits.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.utils.*
import org.junit.*
import org.junit.runner.*
@@ -41,10 +42,12 @@ class HabitCardViewTest : BaseViewTest() {
habit1 = fixtures.createLongHabit()
habit2 = fixtures.createLongNumericalHabit()
val today = DateUtils.getTodayWithOffset()
view = component.getHabitCardViewFactory().create().apply {
habit = habit1
values = habit1.computedEntries.getAllValues()
score = habit1.scores.todayValue
score = habit1.scores.get(today).value
isSelected = false
buttonCount = 5
}

View File

@@ -47,11 +47,12 @@ public class CheckmarkWidgetViewTest extends BaseViewTest
setTheme(R.style.WidgetTheme);
Habit habit = fixtures.createShortHabit();
Timestamp today = DateUtils.getTodayWithOffset();
view = new CheckmarkWidgetView(targetContext);
double score = habit.getScores().getTodayValue();
double score = habit.getScores().get(today).getValue();
float percentage = (float) score;
Timestamp today = DateUtils.getTodayWithOffset();
view.setActiveColor(PaletteUtils.getAndroidTestColor(0));
view.setEntryState(habit.getComputedEntries().get(today).getValue());
view.setEntryValue(habit.getComputedEntries().get(today).getValue());

View File

@@ -72,9 +72,9 @@ class OverviewCardPresenter(val habit: Habit) {
val lastMonth = today.minus(30)
val lastYear = today.minus(365)
val scores = habit.scores
val scoreToday = scores.todayValue.toFloat()
val scoreLastMonth = scores.getValue(lastMonth).toFloat()
val scoreLastYear = scores.getValue(lastYear).toFloat()
val scoreToday = scores.get(today).value.toFloat()
val scoreLastMonth = scores.get(lastMonth).value.toFloat()
val scoreLastYear = scores.get(lastYear).value.toFloat()
val totalCount = habit.originalEntries.getKnown()
.filter { it.value == YES_MANUAL }
.count()

View File

@@ -79,7 +79,10 @@ class ScoreCardPresenter(
fun present(spinnerPosition: Int): ScoreCardViewModel {
val bucketSize = BUCKET_SIZES[spinnerPosition]
val scoreList = habit.scores
val scores = if (bucketSize == 1) scoreList.toList()
val today = DateUtils.getTodayWithOffset()
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
val scores = if (bucketSize == 1) scoreList.getByInterval(oldest, today)
else scoreList.groupBy(getTruncateField(bucketSize), firstWeekday)
return ScoreCardViewModel(
color = habit.color,

View File

@@ -54,7 +54,7 @@ open class CheckmarkWidget(
} else {
setEntryState(habit.computedEntries.get(today).value)
}
setPercentage(habit.scores.todayValue.toFloat())
setPercentage(habit.scores.get(today).value.toFloat())
refresh()
}
}

View File

@@ -24,6 +24,7 @@ import android.view.*
import org.isoron.uhabits.activities.common.views.*
import org.isoron.uhabits.activities.habits.show.views.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.utils.*
import org.isoron.uhabits.utils.*
import org.isoron.uhabits.widgets.views.*
@@ -38,8 +39,11 @@ class ScoreWidget(
override fun refreshData(view: View) {
val size = ScoreCardPresenter.BUCKET_SIZES[prefs.scoreCardSpinnerPosition]
val today = DateUtils.getTodayWithOffset()
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
val scores = when(size) {
1 -> habit.scores.toList()
1 -> habit.scores.getByInterval(oldest, today)
else -> habit.scores.groupBy(ScoreCardPresenter.getTruncateField(size), prefs.firstWeekday)
}