mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Simplify ScoreList
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user