Skip to content

Commit

Permalink
Revert "Sliding window targets"
Browse files Browse the repository at this point in the history
This reverts commit 6027932.
  • Loading branch information
ofalvai committed Feb 23, 2023
1 parent 6027932 commit df6177f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ sealed class ActionHistory {

object Clean : ActionHistory()

data class SlidingWindow(val windowSize: Int, val actionCount: Int)
data class Streak(val days: Int) : ActionHistory()

data class Streak(val days: Int, val slidingWindow: SlidingWindow) : ActionHistory()

data class MissedDays(val days: Int, val slidingWindow: SlidingWindow) : ActionHistory()
data class MissedDays(val days: Int) : ActionHistory()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import java.time.ZoneId
import com.ofalvai.habittracker.core.database.entity.Action as ActionEntity

private const val RECENT_ACTIONS_PER_HABIT = 30 // Max number of days of any dashboard configs
private const val SLIDING_WINDOW_SIZE = 7

fun actionsToRecentDays(actions: List<ActionEntity>): ImmutableList<Action> {
val lastDay = LocalDate.now()
Expand Down Expand Up @@ -77,7 +76,7 @@ fun actionsToHistory(actions: List<ActionEntity>): ActionHistory {
break
}
}
return ActionHistory.Streak(days, actionsToMovingWindow(sortedActions))
return ActionHistory.Streak(days)
} else if (firstActionDate.isBefore(LocalDate.now())) {
// It's a missed day streak
var days = 0
Expand All @@ -88,20 +87,9 @@ fun actionsToHistory(actions: List<ActionEntity>): ActionHistory {
previousDate = previousDate.minusDays(1)
}

return ActionHistory.MissedDays(days, actionsToMovingWindow(sortedActions))
return ActionHistory.MissedDays(days)
} else {
// firstActionDate is in the future. This should never happen
return ActionHistory.Clean
}
}

private fun actionsToMovingWindow(sortedActions: List<ActionEntity>): ActionHistory.SlidingWindow {
val windowStartInclusive = LocalDate.now().minusDays(SLIDING_WINDOW_SIZE.toLong())
return ActionHistory.SlidingWindow(
SLIDING_WINDOW_SIZE,
sortedActions.count {
val instant = windowStartInclusive.atStartOfDay(ZoneId.systemDefault()).toInstant()
it.timestamp.isAfter(instant)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ fun ActionHistoryLabel(totalActionCount: Int, actionHistory: ActionHistory) {
val actionHistoryLabel = when (actionHistory) {
ActionHistory.Clean -> stringResource(R.string.common_action_count_clean)
is ActionHistory.MissedDays -> resources.getQuantityString(
R.plurals.common_action_count_moving_window, actionHistory.slidingWindow.actionCount, actionHistory.slidingWindow.actionCount, actionHistory.slidingWindow.windowSize
R.plurals.common_action_count_missed_days, actionHistory.days, actionHistory.days
)
is ActionHistory.Streak -> resources.getQuantityString(
R.plurals.common_action_count_moving_window, actionHistory.slidingWindow.actionCount, actionHistory.slidingWindow.actionCount, actionHistory.slidingWindow.windowSize
R.plurals.common_action_count_streak, actionHistory.days, actionHistory.days
)
}
val mergedLabel = stringResource(coreR.string.common_interpunct, totalLabel, actionHistoryLabel)
Expand Down Expand Up @@ -269,25 +269,9 @@ fun PreviewHabitCard() {

PreviewTheme {
Column(Modifier.padding(16.dp)) {
HabitCard(
habit = habit1,
actions = actions1.toImmutableList(),
totalActionCount = 14,
actionHistory = ActionHistory.Clean,
onActionToggle = { _, _, _ -> },
onDetailClick = {},
dragOffset = 0f
)
HabitCard(habit1, actions1.toImmutableList(), 14, ActionHistory.Clean, { _, _, _ -> }, {}, 0f)
Spacer(modifier = Modifier.height(16.dp))
HabitCard(
habit = habit2,
actions = actions2.toImmutableList(),
totalActionCount = 3,
actionHistory = ActionHistory.Streak(3, ActionHistory.SlidingWindow(7, 5)),
onActionToggle = { _, _, _ -> },
onDetailClick = {},
dragOffset = 0f
)
HabitCard(habit2, actions2.toImmutableList(), 3, ActionHistory.Streak(3), { _, _, _ -> }, {}, 0f)
}
}
}
5 changes: 2 additions & 3 deletions feature-dashboard/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@

<string name="common_action_count_clean">Start today</string>
<plurals name="common_action_count_total">
<item quantity="one">%d total</item>
<item quantity="other">%d total</item>
</plurals>
<plurals name="common_action_count_streak">
<item quantity="one">%d day streak</item>
<item quantity="other">%d day streak</item>
</plurals>
<plurals name="common_action_count_missed_days">
<item quantity="one">%d missed day</item>
<item quantity="other">%d missed days</item>
</plurals>
<plurals name="common_action_count_moving_window">
<item quantity="other">%1$d in last %2$d days</item>
</plurals>

<string name="habitdetails_singlestat_total">times total</string>
<string name="habitdetails_singlestat_weekly">times this week</string>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }

[libraries]
gradle-android-desugar = "com.android.tools:desugar_jdk_libs:2.0.2"
gradle-android-plugin = "com.android.tools.build:gradle:8.1.0-alpha06"
gradle-android-plugin = "com.android.tools.build:gradle:8.1.0-alpha05"

kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
Expand Down

0 comments on commit df6177f

Please sign in to comment.