@ -21,6 +21,7 @@ package org.isoron.uhabits.core.ui.screens.habits.show.views
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.core.models.countSkippedDays
import org.isoron.uhabits.core.models.groupedSum
import org.isoron.uhabits.core.models.groupedSum
import org.isoron.uhabits.core.ui.views.Theme
import org.isoron.uhabits.core.ui.views.Theme
import org.isoron.uhabits.core.utils.DateUtils
import org.isoron.uhabits.core.utils.DateUtils
@ -51,37 +52,59 @@ class TargetCardPresenter {
isNumerical = habit . isNumerical
isNumerical = habit . isNumerical
) . firstOrNull ( ) ?. value ?: 0
) . firstOrNull ( ) ?. value ?: 0
val skippedDayToday = entries . countSkippedDays (
truncateField = DateUtils . TruncateField . DAY
) . firstOrNull ( ) ?. value ?: 0
val valueThisWeek = entries . groupedSum (
val valueThisWeek = entries . groupedSum (
truncateField = DateUtils . TruncateField . WEEK _NUMBER ,
truncateField = DateUtils . TruncateField . WEEK _NUMBER ,
firstWeekday = firstWeekday ,
firstWeekday = firstWeekday ,
isNumerical = habit . isNumerical
isNumerical = habit . isNumerical
) . firstOrNull ( ) ?. value ?: 0
) . firstOrNull ( ) ?. value ?: 0
val skippedDaysThisWeek = entries . countSkippedDays (
truncateField = DateUtils . TruncateField . WEEK _NUMBER ,
firstWeekday = firstWeekday
) . firstOrNull ( ) ?. value ?: 0
val valueThisMonth = entries . groupedSum (
val valueThisMonth = entries . groupedSum (
truncateField = DateUtils . TruncateField . MONTH ,
truncateField = DateUtils . TruncateField . MONTH ,
isNumerical = habit . isNumerical
isNumerical = habit . isNumerical
) . firstOrNull ( ) ?. value ?: 0
) . firstOrNull ( ) ?. value ?: 0
val skippedDaysThisMonth = entries . countSkippedDays (
truncateField = DateUtils . TruncateField . MONTH ,
) . firstOrNull ( ) ?. value ?: 0
val valueThisQuarter = entries . groupedSum (
val valueThisQuarter = entries . groupedSum (
truncateField = DateUtils . TruncateField . QUARTER ,
truncateField = DateUtils . TruncateField . QUARTER ,
isNumerical = habit . isNumerical
isNumerical = habit . isNumerical
) . firstOrNull ( ) ?. value ?: 0
) . firstOrNull ( ) ?. value ?: 0
val skippedDaysThisQuarter = entries . countSkippedDays (
truncateField = DateUtils . TruncateField . QUARTER
) . firstOrNull ( ) ?. value ?: 0
val valueThisYear = entries . groupedSum (
val valueThisYear = entries . groupedSum (
truncateField = DateUtils . TruncateField . YEAR ,
truncateField = DateUtils . TruncateField . YEAR ,
isNumerical = habit . isNumerical
isNumerical = habit . isNumerical
) . firstOrNull ( ) ?. value ?: 0
) . firstOrNull ( ) ?. value ?: 0
val skippedDaysThisYear = entries . countSkippedDays (
truncateField = DateUtils . TruncateField . YEAR
) . firstOrNull ( ) ?. value ?: 0
val cal = DateUtils . getStartOfTodayCalendarWithOffset ( )
val cal = DateUtils . getStartOfTodayCalendarWithOffset ( )
val daysInMonth = cal . getActualMaximum ( Calendar . DAY _OF _MONTH )
val daysInMonth = cal . getActualMaximum ( Calendar . DAY _OF _MONTH )
val daysInQuarter = 91
val daysInQuarter = 91
val daysInYear = cal . getActualMaximum ( Calendar . DAY _OF _YEAR )
val daysInYear = cal . getActualMaximum ( Calendar . DAY _OF _YEAR )
val targetToday = habit . targetValue / habit . frequency . denominator
val dailyTarget = habit . targetValue / habit . frequency . denominator
val targetThisWeek = targetToday * 7
val targetToday = dailyTarget * ( 1 - skippedDayToday )
val targetThisMonth = targetToday * daysInMonth
val targetThisWeek = dailyTarget * ( 7 - skippedDaysThisWeek )
val targetThisQuarter = targetToday * daysInQuarter
val targetThisMonth = dailyTarget * ( daysInMonth - skippedDaysThisMonth )
val targetThisYear = targetToday * daysInYear
val targetThisQuarter = dailyTarget * ( daysInQuarter - skippedDaysThisQuarter )
val targetThisYear = dailyTarget * ( daysInYear - skippedDaysThisYear )
val values = ArrayList < Double > ( )
val values = ArrayList < Double > ( )
if ( habit . frequency . denominator <= 1 ) values . add ( valueToday / 1 e3 )
if ( habit . frequency . denominator <= 1 ) values . add ( valueToday / 1 e3 )