Skip to content

SAAS-18493 Tighten DateTimeWidget to a compact calendar-only layout#3728

Draft
avazirna wants to merge 3 commits into
masterfrom
SAAS-18493-update-datetime-widget-formatting
Draft

SAAS-18493 Tighten DateTimeWidget to a compact calendar-only layout#3728
avazirna wants to merge 3 commits into
masterfrom
SAAS-18493-update-datetime-widget-formatting

Conversation

@avazirna

@avazirna avazirna commented May 20, 2026

Copy link
Copy Markdown
Contributor

Product Description

Cleans up the layout of the date+time form widget. Previously the DatePicker rendered both its month/day/year spinner header and the full CalendarView, and the calendar stretched to fill the form's width, producing a tall picker with cramped day cells. After this PR:

  • The spinner header is hidden — only the CalendarView is shown.
  • The CalendarView wraps to content width, so it no longer stretches across the form and the day cells render at their natural size.

The TimePicker portion of the widget is unchanged.

Screenshots: before/after of a form containing a DateTime question on a typical handset to be attached.

Technical Summary

Ticket: https://dimagi.atlassian.net/browse/SAAS-18493 — "Request to update date & time widget formatting" (Bug).

The change is purely visual; no answer/serialization behavior is touched. Both setSpinnersShown and setCalendarViewShown have been stable Android DatePicker APIs since API 11.

Safety Assurance

Safety story

  • Manually verified the new layout on a form containing a DateTime question (debug build, commcare flavor).
  • Confirmed the widget still produces a DateTimeData answer with the selected date and time, and that read-only forms still disable the pickers (setFocusable/setEnabled paths unchanged).
  • Risk is bounded to the rendering of this widget; no storage, sync, or form-engine paths are touched, so no migration or data considerations.

Automated test coverage

No new automated coverage — the change is a layout/visual tweak that existing unit tests don't cover and that's difficult to assert on without a screenshot test harness. Existing form-rendering smoke tests will catch any inflation/crash regressions.

Labels and Review

  • Do we need to enhance the manual QA test coverage ? Add a check that the DateTime widget renders as calendar-only and wraps to content width on a representative device.
  • Does the PR introduce any major changes worth communicating ? No RELEASES.md update needed.
  • Risk label: low (UI-only, single widget).
  • Reviewers: forms / mobile UI owners.

@avazirna avazirna marked this pull request as draft May 20, 2026 08:35
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR makes three targeted updates to DateTimeWidget. It removes an unused android.os.Build import, hides the date picker's spinners by calling setSpinnersShown(false) during widget construction, and extends an existing layout workaround to set the calendar view width to LayoutParams.WRAP_CONTENT alongside its height adjustment.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: tightening the DateTimeWidget to a compact calendar-only layout, which directly matches the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description follows the template with complete sections: Product Description explaining user-facing changes, Technical Summary with ticket link and rationale, Safety Assurance with safety story and test coverage, and Labels and Review addressing all required checkboxes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SAAS-18493-update-datetime-widget-formatting

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/org/commcare/views/widgets/DateTimeWidget.java (1)

96-102: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Rename method to reflect that it now sets both dimensions.

The method updateCalendarViewHeight() now sets both width and height to WRAP_CONTENT, but the name only mentions height. This is misleading for future maintainers.

♻️ Suggested refactor to rename the method
-    private void updateCalendarViewHeight() {
+    private void updateCalendarViewDimensions() {
         CalendarView calendarView = mDatePicker.getCalendarView();
         LayoutParams params = (LayoutParams) calendarView.getLayoutParams();
         params.height = LayoutParams.WRAP_CONTENT;
         params.width = LayoutParams.WRAP_CONTENT;
         calendarView.setLayoutParams(params);
     }

Also update the call site on line 42:

         mDatePicker.setSpinnersShown(false);
-        updateCalendarViewHeight();
+        updateCalendarViewDimensions();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/org/commcare/views/widgets/DateTimeWidget.java` around lines 96 -
102, Rename the misleading method updateCalendarViewHeight() to a name
reflecting both dimensions (e.g., updateCalendarViewSize or
setCalendarViewWrapContent) and update all call sites to the new method name;
inside the renamed method keep the existing body that gets the CalendarView via
mDatePicker.getCalendarView(), casts LayoutParams, sets params.height and
params.width to LayoutParams.WRAP_CONTENT, and reapplies them with
calendarView.setLayoutParams(params).
🧹 Nitpick comments (1)
app/src/org/commcare/views/widgets/DateTimeWidget.java (1)

92-94: ⚡ Quick win

Update comment to reflect that width is also being set.

The comment describes the workaround as updating "the calendarview height to wrap content", but now the method also sets the width. The comment should be updated for accuracy.

📝 Suggested comment update
     /**
-     * CalendarView bottom line gets cut off in appcompat theme because it's height is fixed here:
+     * CalendarView bottom line gets cut off and stretches to match parent in appcompat theme
+     * because its dimensions are fixed here:
      * https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/res/layout/date_picker_legacy.xml#L78
-     * This workaround updates the calendarview height to wrap content.
+     * This workaround updates the calendarview dimensions to wrap content.
      */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/org/commcare/views/widgets/DateTimeWidget.java` around lines 92 - 94,
The existing comment above the workaround in DateTimeWidget.java currently
states it "updates the calendarview height to wrap content" but the code also
adjusts the width; update that comment to accurately describe both dimensions
being changed (height and width) and mention that the workaround sets
calendarView layout params to wrap_content for height and width so readers of
the DateTimeWidget class understand the full effect.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@app/src/org/commcare/views/widgets/DateTimeWidget.java`:
- Around line 96-102: Rename the misleading method updateCalendarViewHeight() to
a name reflecting both dimensions (e.g., updateCalendarViewSize or
setCalendarViewWrapContent) and update all call sites to the new method name;
inside the renamed method keep the existing body that gets the CalendarView via
mDatePicker.getCalendarView(), casts LayoutParams, sets params.height and
params.width to LayoutParams.WRAP_CONTENT, and reapplies them with
calendarView.setLayoutParams(params).

---

Nitpick comments:
In `@app/src/org/commcare/views/widgets/DateTimeWidget.java`:
- Around line 92-94: The existing comment above the workaround in
DateTimeWidget.java currently states it "updates the calendarview height to wrap
content" but the code also adjusts the width; update that comment to accurately
describe both dimensions being changed (height and width) and mention that the
workaround sets calendarView layout params to wrap_content for height and width
so readers of the DateTimeWidget class understand the full effect.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0290041f-b1f3-4de9-bdb5-0b4fdd15cc9a

📥 Commits

Reviewing files that changed from the base of the PR and between 9087118 and b461ac2.

📒 Files selected for processing (1)
  • app/src/org/commcare/views/widgets/DateTimeWidget.java

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.33%. Comparing base (716eb99) to head (b461ac2).
⚠️ Report is 24 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3728      +/-   ##
============================================
- Coverage     23.36%   23.33%   -0.03%     
  Complexity     3927     3927              
============================================
  Files           923      923              
  Lines         56058    56094      +36     
  Branches       6641     6643       +2     
============================================
- Hits          13096    13092       -4     
- Misses        41268    41307      +39     
- Partials       1694     1695       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant