Skip to content

Add Compose time and date pickers and keep dialogs open across rotation - #1908

Open
ThomasKiljanczykDev wants to merge 7 commits into
Futsch1:mainfrom
ThomasKiljanczykDev:compose-time-pickers
Open

ThomasKiljanczykDev wants to merge 7 commits into
Futsch1:mainfrom
ThomasKiljanczykDev:compose-time-pickers

Conversation

@ThomasKiljanczykDev

@ThomasKiljanczykDev ThomasKiljanczykDev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@Futsch1 these changes have been sitting on my laptop for a while.

I've refactored the code to move the medicine panels to Compose.
This PR replaces all element that will be in the panel replacement.
The next PR will get rid of the view based panels (it has some design decisions that will need approval).
I did go through changes in batches and tested each by hand to iron out some behavior details.
A highlight for this one is it makes the modified dialogs retain state on screen rotation.

Summary

  • Add Compose time and date picker dialogs, and use the time picker for the Overview reschedule action and for the time of a manual dose.
  • Keep the tag dialog, the "Add tag" input, the stock reminder dialog, and the two time pickers open with their input across configuration changes.
  • Make ManualDoseTest#manualDoseUsesSelectedOverviewDate select yesterday, inside the one-week range of OverviewRobot.selectDay.
 core/ui/component/
+├── MedTimerTimePickerDialog.kt   # dial or keyboard input, system 12 h or 24 h, same digit size in the two modes
+└── MedTimerDatePickerDialog.kt   # dates as UTC-midnight millis, as in MaterialDatePicker
 feature/ui/overview/
+├── RescheduleDialog.kt           # time picker for the pending reschedule
+├── RescheduleViewModel.kt        # keeps the pending reschedule across configuration changes
 ├── actions/
+│   ├── Rescheduler.kt            # applies the picked time to the events
 │   └── ActionsVisitor.kt         # hands RESCHEDULE to RescheduleViewModel
 └── manualDose/ManualDoseDialog.kt  # "Log at another time" opens the Compose time picker
 feature/ui/medicine/
 ├── tags/
+│   ├── AddTagDialogFragment.kt   # "Add tag" input as a restorable child dialog
 │   └── TagsFragment.kt           # builds its data provider from its arguments, has a no-arg constructor
 └── dialogs/NewReminderStockDialog.kt  # composable, hosted in StockSettingsFragment

RescheduleDialog, ManualDoseDialog, and NewReminderStockDialog get their view model from a hiltViewModel() default parameter.
Where the hosting fragment starts a dialog, the fragment holds a by viewModels() reference to the same instance.

 reschedule
-  ActionsVisitor → MaterialTimePicker
+  ActionsVisitor → RescheduleViewModel.request(events)
+  RescheduleDialog → MedTimerTimePickerDialog
+    OK → Rescheduler.reschedule(events, time)

Evidence

  • Before:
    Rotation with the tag dialog open crashes the app with Fragment$InstantiationException: could not find Fragment constructor.
    Rotation closes the stock reminder dialog and the "Add tag" input.
    The reschedule picker is a MaterialTimePicker, which does not restore its OK listener after rotation.
    ManualDoseTest#manualDoseUsesSelectedOverviewDate fails with a timeout in OverviewRobot.selectDay.
    After:
    After activity.recreate(), each dialog stays open with its input.
TagTest#tagDialogsStayOpenWhenTheActivityIsRecreated            open tags, add a tag, recreate → dialog open, typed "Add tag" text kept
MedicineStockTest#stockReminderDialogSurvivesActivityRecreation  type 7 days, recreate, create → reminder saved (fails without fix)
ReminderTest#reschedulePickerSurvivesActivityRecreation          open picker, recreate, pick → event moved
ManualDoseTest#manualDoseTimePickerSurvivesActivityRecreation    open picker, recreate, pick → dose logged at that time
MedTimerPickerDialogsTest (7, Robolectric)                       OK, Cancel, keyboard input, 12 h and 24 h, same digit size in the two modes (fails without fix)
RescheduleTest (3, Robolectric)                                  request starts at the event time, OK moves the event, Cancel keeps it

On the branch, based on main with Compose BOM 2026.11.01, these checks pass: assembleDebug, testFullDebugUnitTest, testFossDebugUnitTest, and lint.
On API 28, the instrumented tests above pass, together with NotificationTest#scheduleReminderTest and MedicineStockTest#invalidReminderInputTest.
On API 37, the same instrumented tests pass for each commit on the earlier base 5d148543b.

Merge Danger

Door: two-way

The change contains UI code only.
It has no Room schema, migration, preference, or dependency version change.
feature/ui adds androidx.hilt:hilt-lifecycle-viewmodel-compose, which the version catalog and core/ui already contain.

Blast Radius: dialogs

  • Tag dialog of a medicine (edit medicine screen)
  • Tag filter (Overview, Medicines)
  • Stock reminder dialog (stock settings)
  • Overview reschedule, for one or more events
  • Manual dose "Log at another time"

Reminder editors, weekend mode, and advanced reminder settings use the View-based TimePickerDialogFactory and MaterialTimePicker.

🤖 Generated with Claude Code

ThomasKiljanczykDev and others added 7 commits November 24, 2026 21:22
TagsFragment received its TagDataProvider from the caller, so the system
could not rebuild it after rotation and the app crashed. The fragment now
builds the provider itself from its arguments (a medicine ID, or none for
the tag filter), so the dialog is restored with its state.

The "Add tag" input is now a child DialogFragment that returns the name as
a fragment result, so it also survives rotation with the typed text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ange

OverviewRobot.selectDay pages back only one week, so the hardcoded
2025-07-30 became unreachable. Use the day before the frozen test date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MedTimerTimePickerDialog and MedTimerDatePickerDialog wrap the Material 3
pickers with the app's labels, the system 12/24-hour setting and a
keyboard fallback when the dial does not fit. ComposePickers drives them
in instrumented tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NewReminderStockDialog attached a ComposeView to the activity's decor view
and took NewReminderViewModel from the activity, so rotation removed the
dialog. It is now a composable that obtains the view model with
hiltViewModel(), hosted inside StockSettingsFragment, which saves whether
the dialog is open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Material sets the dial's hour and minute in displayLarge but the input
fields in displayMedium, so switching modes changed the digit size.
MedTimerTimePickerDialog now gives TimeInput displayLarge as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reschedule action hands the selected events to RescheduleViewModel;
RescheduleDialog, which obtains it with hiltViewModel(), asks for the time
with MedTimerTimePickerDialog, and Rescheduler applies it. Keeping the
pending reschedule in the view model lets the picker survive
configuration changes; the View-based MaterialTimePicker lost its OK
handler on rotation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Log at another time" now opens MedTimerTimePickerDialog instead of the
View-based MaterialTimePicker; the open picker is saveable state, so it
survives configuration changes. ManualDoseDialog obtains its view model
with hiltViewModel() and wires its steps itself, so OverviewFragment only
opens it and handles the logged result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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