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

@@ -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)
}