From 5d25b236f7959e131ff1be4c3fcbb57d5db46a48 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Tue, 22 Mar 2022 17:05:06 +0100 Subject: [PATCH] Resolving comments --- .../habits/list/views/NumberButtonView.kt | 10 +++++----- .../org/isoron/uhabits/core/models/EntryList.kt | 7 +++---- .../core/ui/screens/habits/show/views/TargetCard.kt | 13 ++++--------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt index e7eccfcce..ed00049ee 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt @@ -183,16 +183,16 @@ class NumberButtonView( val textSize: Float when { - value >= 0 -> { - label = value.toShortString() - typeface = BOLD_TYPEFACE - textSize = dim(R.dimen.smallTextSize) - } value == Entry.SKIP.toDouble() / 1000 -> { label = resources.getString(R.string.fa_skipped) textSize = dim(R.dimen.smallTextSize) typeface = getFontAwesome() } + value >= 0 -> { + label = value.toShortString() + typeface = BOLD_TYPEFACE + textSize = dim(R.dimen.smallTextSize) + } preferences.areQuestionMarksEnabled -> { label = resources.getString(R.string.fa_question) typeface = getFontAwesome() diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/EntryList.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/EntryList.kt index 3c6a1ed58..2d9662b21 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/EntryList.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/EntryList.kt @@ -276,7 +276,7 @@ open class EntryList { * For numerical habits, non-positive entry values are converted to zero. For boolean habits, each * YES_MANUAL value is converted to 1000 and all other values are converted to zero. * - * SKIP values are treated converted to zero (if they weren't, each SKIP day would count as 0.003). + * SKIP values are converted to zero (if they weren't, each SKIP day would count as 0.003). * * The returned list is sorted by timestamp, with the newest entry coming first and the oldest entry * coming last. If the original list has gaps in it (for example, weeks or months without any @@ -311,12 +311,11 @@ fun List.groupedSum( } /** - * Counts the number of days with vaLue SKIP in the given perio + * Counts the number of days with vaLue SKIP in the given period. */ fun List.countSkippedDays( truncateField: DateUtils.TruncateField, - firstWeekday: Int = Calendar.SATURDAY, - isNumerical: Boolean, + firstWeekday: Int = Calendar.SATURDAY ): List { return this.map { (timestamp, value) -> if (value == SKIP) { diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/TargetCard.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/TargetCard.kt index 0c53a290d..9b8add0dc 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/TargetCard.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/TargetCard.kt @@ -53,8 +53,7 @@ class TargetCardPresenter { ).firstOrNull()?.value ?: 0 val skippedDayToday = entries.countSkippedDays( - truncateField = DateUtils.TruncateField.DAY, - isNumerical = habit.isNumerical + truncateField = DateUtils.TruncateField.DAY ).firstOrNull()?.value ?: 0 val valueThisWeek = entries.groupedSum( @@ -65,8 +64,7 @@ class TargetCardPresenter { val skippedDaysThisWeek = entries.countSkippedDays( truncateField = DateUtils.TruncateField.WEEK_NUMBER, - firstWeekday = firstWeekday, - isNumerical = habit.isNumerical + firstWeekday = firstWeekday ).firstOrNull()?.value ?: 0 val valueThisMonth = entries.groupedSum( @@ -76,7 +74,6 @@ class TargetCardPresenter { val skippedDaysThisMonth = entries.countSkippedDays( truncateField = DateUtils.TruncateField.MONTH, - isNumerical = habit.isNumerical ).firstOrNull()?.value ?: 0 val valueThisQuarter = entries.groupedSum( @@ -85,8 +82,7 @@ class TargetCardPresenter { ).firstOrNull()?.value ?: 0 val skippedDaysThisQuarter = entries.countSkippedDays( - truncateField = DateUtils.TruncateField.QUARTER, - isNumerical = habit.isNumerical + truncateField = DateUtils.TruncateField.QUARTER ).firstOrNull()?.value ?: 0 val valueThisYear = entries.groupedSum( @@ -95,8 +91,7 @@ class TargetCardPresenter { ).firstOrNull()?.value ?: 0 val skippedDaysThisYear = entries.countSkippedDays( - truncateField = DateUtils.TruncateField.YEAR, - isNumerical = habit.isNumerical + truncateField = DateUtils.TruncateField.YEAR ).firstOrNull()?.value ?: 0 val cal = DateUtils.getStartOfTodayCalendarWithOffset()