-
-
Notifications
You must be signed in to change notification settings - Fork 42
🔧 added toggle buttons for time period #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: shub39 <[email protected]>
|
Caution Review failedThe pull request is closed. WalkthroughBumps app version to 5.0.0, adds WeeklyTimePeriod and a time-range selector for weekly analytics, updates AnalyticsCard API to accept an icon and adjusts overlay sizing, applies iconized headers across callers, extends chart data window, tweaks task UI/interaction, and adds a "weeks" string resource. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as WeeklyGraph UI
participant Selector as Time Selector (LazyRow)
participant Enum as WeeklyTimePeriod
participant Chart as LineChart
User->>UI: Open Weekly analytics
UI->>Selector: render period buttons (entries)
User->>Selector: select period
Selector-->>UI: onToggle(period)
UI->>Enum: period.toWeeks()
UI->>Chart: takeLast(N weeks) and render filtered data
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. ⛔ Files ignored due to path filters (5)
📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (16)
app/src/main/java/com/shub39/grit/tasks/presentation/ui/component/TaskCard.kt (2)
65-65: Smooth size transitions are welcome; consider a gentler spring to reduce list jank.Default animateContentSize() can feel a bit snappy inside LazyColumn. A softer spring improves perceived smoothness during expand/collapse.
Apply:
- modifier = modifier.animateContentSize(), + modifier = modifier.animateContentSize( + animationSpec = androidx.compose.animation.core.spring( + stiffness = androidx.compose.animation.core.Spring.StiffnessMediumLow + ) + ),
107-109: 11.sp is below common accessibility guidance; bump to 12.sp.Small text tends to become hard to read. 12.sp keeps it compact but friendlier.
- style = MaterialTheme.typography.labelSmall.copy( - fontSize = 11.sp - ) + style = MaterialTheme.typography.labelSmall.copy(fontSize = 12.sp)app/src/main/java/com/shub39/grit/tasks/presentation/ui/section/TaskList.kt (1)
277-279: UX check: long‑press no longer edits completed tasks. Intentional?New guard (!editState && !task.status) blocks editing finished items via long‑press. If that’s desired—cool. If not, consider allowing edit regardless of status, or provide an alternate entry point for completed tasks.
If you want to keep long‑press editing for all:
- if (!editState && !task.status) { + if (!editState) { editTask = task - } + }app/src/main/res/values/strings.xml (1)
123-125: Pluralization for “week(s)”.If you ever introduce a 1‑week option, switch this to plurals to localize correctly.
Example to add alongside (no breaking change now):
<plurals name="weeks_quantity"> <item quantity="one">%d Week</item> <item quantity="other">%d Weeks</item> </plurals>app/src/main/java/com/shub39/grit/habits/presentation/util.kt (1)
21-21: Remove “15 means 16 weeks” off‑by‑one confusion; make the window explicit.Using 15 to emit 16 data points is easy to misread. Make the lookback size explicit and iterate 0 until lookbackWeeks.
- val totalWeeks = 15 + // Generate 16 data points (last 16 full weeks including current week) + val lookbackWeeks = 16 @@ - val startDateOfPeriod = today.minusWeeks(totalWeeks.toLong()).with(weekFields.dayOfWeek(), 1) + val startDateOfPeriod = today + .minusWeeks((lookbackWeeks - 1).toLong()) + .with(weekFields.dayOfWeek(), 1) @@ - val values = (0..totalWeeks).map { i -> - val currentWeekStart = today.minusWeeks(totalWeeks - i.toLong()).with(weekFields.dayOfWeek(), 1) + val values = (0 until lookbackWeeks).map { i -> + val currentWeekStart = today + .minusWeeks((lookbackWeeks - 1 - i).toLong()) + .with(weekFields.dayOfWeek(), 1)Optional follow‑up: accept lookbackWeeks as a parameter (default 16) so UI periods can drive data length directly.
Also applies to: 23-23, 33-35
app/src/main/java/com/shub39/grit/habits/domain/WeeklyTimePeriod.kt (1)
5-7: Optional: order smallest→largest for nicer UXToggle sequences commonly progress 4, 8, 16. If you prefer that:
- WEEKS_16(16), - WEEKS_8(8), - WEEKS_4(4); + WEEKS_4(4), + WEEKS_8(8), + WEEKS_16(16);app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt (1)
40-60: Accessibility: mark header as a semantic headingImproves screen-reader navigation.
- Row( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), + Row( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + .semantics { heading() },Add imports:
import androidx.compose.ui.semantics.heading import androidx.compose.ui.semantics.semanticsapp/src/main/java/com/shub39/grit/habits/presentation/ui/component/HabitHeatMap.kt (1)
64-70: Improve week header text contrast on secondaryContainerFor consistent accessibility, prefer
onSecondaryContaineroversecondaryon asecondaryContainerbackground.Apply this diff:
- .background( - color = MaterialTheme.colorScheme.secondaryContainer, - shape = CircleShape - ) + .background( + color = MaterialTheme.colorScheme.secondaryContainer, + shape = CircleShape + ) @@ - color = MaterialTheme.colorScheme.secondary, + color = MaterialTheme.colorScheme.onSecondaryContainer,Also applies to: 73-73
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyBooleanHeatmap.kt (1)
73-79: Match text color to container for better contrastSame contrast note as HabitHeatMap: use
onSecondaryContaineratopsecondaryContainer.Apply this diff:
- .background( - color = MaterialTheme.colorScheme.secondaryContainer, - shape = CircleShape - ) + .background( + color = MaterialTheme.colorScheme.secondaryContainer, + shape = CircleShape + ) @@ - color = MaterialTheme.colorScheme.secondary, + color = MaterialTheme.colorScheme.onSecondaryContainer,Also applies to: 82-82
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyGraph.kt (3)
49-50: Make rememberSaveable robust for enumsEnums may not be saved/restored across process death without a saver. Provide a
SaverforWeeklyTimePeriod.Apply this diff:
@@ -import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.saveable.Saver @@ - var selectedTimePeriod by rememberSaveable { mutableStateOf(WeeklyTimePeriod.WEEKS_8) } + val periodSaver = Saver<WeeklyTimePeriod, String>( + save = { it.name }, + restore = { WeeklyTimePeriod.valueOf(it) } + ) + var selectedTimePeriod by rememberSaveable(stateSaver = periodSaver) { + mutableStateOf(WeeklyTimePeriod.WEEKS_8) + }
66-73: Consider a segmented single-choice control for better a11y semanticsThe ToggleButtons emulate single selection but don’t convey group semantics. If available in your Material3 version, consider
SingleChoiceSegmentedButtonRow+SegmentedButton.
70-71: Use plurals for localization (“N weeks”)Hardcoding “weeks” can be incorrect in some locales. Prefer
pluralStringResource.Apply this diff (requires adding
R.plurals.weeks):+import androidx.compose.ui.res.pluralStringResource @@ - Text(text = "${period.toWeeks()} ${stringResource(R.string.weeks)}") + val weeks = period.toWeeks() + Text(text = pluralStringResource(R.plurals.weeks, weeks, weeks))app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyActivity.kt (4)
66-69: Respect isChecked in ToggleButton to avoid forcing selectionThis ensures proper single-select behavior and prevents re-selecting on deselect taps.
- ToggleButton( - checked = period == selectedTimePeriod, - onCheckedChange = { selectedTimePeriod = period } - ) { + ToggleButton( + checked = period == selectedTimePeriod, + onCheckedChange = { isChecked -> + if (isChecked) selectedTimePeriod = period + } + ) {
65-66: Add stable keys to LazyRow itemsKeys reduce unnecessary recompositions and preserve state if the list changes.
- items(WeeklyTimePeriod.entries) { period -> + items(items = WeeklyTimePeriod.entries, key = { it.name }) { period ->
70-71: Use plurals for proper i18n (“1 week” vs “2 weeks”)Switch to pluralStringResource and add a plurals entry.
- Text(text = "${period.toWeeks()} ${stringResource(R.string.weeks)}") + Text(text = pluralStringResource(R.plurals.weeks, period.toWeeks(), period.toWeeks()))Add import outside this hunk:
import androidx.compose.ui.res.pluralStringResourceAdd to strings.xml:
<plurals name="weeks"> <item quantity="one">%d week</item> <item quantity="other">%d weeks</item> </plurals>
93-95: Scale X-axis grid lines with selected periodImproves readability when switching between shorter and longer ranges.
- lineCount = 10, + lineCount = selectedTimePeriod.toWeeks().coerceAtMost(10),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (13)
app/build.gradle.kts(1 hunks)app/src/main/java/com/shub39/grit/habits/domain/WeeklyTimePeriod.kt(1 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt(3 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/CalendarMap.kt(2 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/HabitHeatMap.kt(3 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeekDayBreakdown.kt(2 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyActivity.kt(4 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyBooleanHeatmap.kt(3 hunks)app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyGraph.kt(4 hunks)app/src/main/java/com/shub39/grit/habits/presentation/util.kt(2 hunks)app/src/main/java/com/shub39/grit/tasks/presentation/ui/component/TaskCard.kt(4 hunks)app/src/main/java/com/shub39/grit/tasks/presentation/ui/section/TaskList.kt(1 hunks)app/src/main/res/values/strings.xml(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyActivity.kt (1)
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt (1)
AnalyticsCard(27-88)
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyGraph.kt (1)
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt (1)
AnalyticsCard(27-88)
🔇 Additional comments (10)
app/build.gradle.kts (1)
14-15: Version bump looks good.VersionCode 5000 and VersionName 5.0.0 align with the major feature addition.
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt (2)
47-51: LGTM: icon renderingIcon tint and placement align with the new header style.
30-30: Public API change accepted – all call sites updatedVerified that every
AnalyticsCard(…)invocation (6 occurrences across WeeklyGraph, WeeklyActivity, HabitHeatMap, WeeklyBooleanHeatmap, CalendarMap, and WeekDayBreakdown) now supplies theiconargument, so the source-breaking change is fully covered.app/src/main/java/com/shub39/grit/habits/presentation/ui/component/CalendarMap.kt (2)
49-50: LGTM: passes calendar icon to AnalyticsCardCall-site matches the updated API.
11-12: No action needed:material-icons-extendedis declared in the version catalog (gradle/libs.versions.toml:33).app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeekDayBreakdown.kt (1)
5-6: Adoption of AnalyticsCard icon looks goodHeader icon wiring is correct and consistent with the new AnalyticsCard API.
Also applies to: 42-42
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/HabitHeatMap.kt (1)
40-40: Icon integration LGTMUsing
Icons.Rounded.Mapaligns with the new card header pattern.app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyBooleanHeatmap.kt (1)
49-49: Icon integration LGTM
Icons.Rounded.ViewWeekis a good semantic choice for this card.app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyGraph.kt (1)
96-100: Safe slicing of series values — LGTM
takeLast(selectedTimePeriod.toWeeks())safely handles shorter series and keeps color/label viacopy.app/src/main/java/com/shub39/grit/habits/presentation/ui/component/WeeklyActivity.kt (1)
75-81: Verify empty-data handling for LineChartPreview passes an empty list; some chart libs crash on empty series. If it doesn’t handle empty lists, gate the chart and show a placeholder.
Example guard:
val chartValues = lineChartData.takeLast(selectedTimePeriod.toWeeks()) if (chartValues.isEmpty()) { Text(text = stringResource(R.string.no_data)) } else { LineChart( // ... data = listOf( Line( // ... - values = lineChartData.takeLast(selectedTimePeriod.toWeeks()), + values = chartValues, // ... ) ), // ... ) }Add string if needed:
<string name="no_data">No data yet</string>Also applies to: 101-106
| companion object { | ||
| fun WeeklyTimePeriod.toWeeks(): Int { | ||
| return when (this) { | ||
| WEEKS_16 -> 16 | ||
| WEEKS_8 -> 8 | ||
| WEEKS_4 -> 4 | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix: member extension is out of scope; calls like period.toWeeks() won’t resolve
An extension declared inside a companion object is a member extension and isn’t visible at call sites like your UI composables. Convert to an enum ctor property (simplest) and drop the companion.
-enum class WeeklyTimePeriod {
- WEEKS_16,
- WEEKS_8,
- WEEKS_4;
-
- companion object {
- fun WeeklyTimePeriod.toWeeks(): Int {
- return when (this) {
- WEEKS_16 -> 16
- WEEKS_8 -> 8
- WEEKS_4 -> 4
- }
- }
- }
-}
+enum class WeeklyTimePeriod(val weeks: Int) {
+ WEEKS_16(16),
+ WEEKS_8(8),
+ WEEKS_4(4);
+}Follow-up: replace selectedTimePeriod.toWeeks() with selectedTimePeriod.weeks.
🤖 Prompt for AI Agents
In app/src/main/java/com/shub39/grit/habits/domain/WeeklyTimePeriod.kt around
lines 9 to 17, the member extension declared inside the companion object is out
of scope for call sites (e.g., UI composables) so change the enum to carry the
week value as an enum constructor property: add a constructor parameter (val
weeks: Int) to WeeklyTimePeriod, set each enum constant with its week value
(e.g., WEEKS_16(16), etc.), remove the companion object and the extension
function, and then update all call sites to use selectedTimePeriod.weeks instead
of selectedTimePeriod.toWeeks().
| contentAlignment = Alignment.Center, | ||
| modifier = Modifier | ||
| .heightIn(max = 300.dp) | ||
| .heightIn(300.dp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Set fixed overlay height (min-only currently allows growth)
.heightIn(300.dp) sets min height, not max. Use an exact 300.dp to prevent oversized overlays.
- .heightIn(300.dp)
+ .heightIn(min = 300.dp, max = 300.dp)🤖 Prompt for AI Agents
In
app/src/main/java/com/shub39/grit/habits/presentation/ui/component/AnalyticsCard.kt
around line 66, the modifier uses .heightIn(300.dp) which only sets a minimum
height and allows the overlay to grow; replace it with an exact height modifier
(e.g., .height(300.dp)) so the overlay is fixed at 300.dp and cannot oversized.
Signed-off-by: shub39 <[email protected]>
Summary by CodeRabbit
New Features
UI/UX
Bug Fixes
Chores