Skip to content

fix(widget): match Activity view startOfDay and add open-app button - #198

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/widget-start-of-day-and-launch
Open

fix(widget): match Activity view startOfDay and add open-app button#198
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/widget-start-of-day-and-launch

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Fixes #197 (two issues from that report).

1. Widget time matches Activity view

Root cause: The widget queried from midnight (today.atStartOfDay(zone)) while aw-webui's Activity view uses startOfDay (default "04:00") as the day boundary.

Fix: getCategoryTimesToday now reads startOfDay from the embedded server's settings API (GET /api/0/settings/startOfDay) before building the timeperiod — same source the Rust androidQuery already uses for category classes. Falls back to 4 (aw-webui default) if the server is unavailable or the setting is unset. Also mirrors aw-webui's pre-dawn logic: if the current hour is before startOfDay, the widget shows the previous calendar day's period (e.g. at 3 AM with startOfDay=4, "today" is yesterday 04:00–today 04:00).

2. Widget tap opens the app

Fix: Adds a small "open external" icon (widget_open_button) next to the "Screen time" header. Tapping it launches MainActivity. The main widget body keeps its existing single-tap-to-refresh behaviour.

Changes

  • CategoryTimeWidgetUpdater.kt: fetchStartOfDayHour() + parseStartOfDayHour() helpers; updated getCategoryTimesToday; launch PendingIntent wired to widget_open_button
  • widget_category_time.xml: header row wrapped in horizontal LinearLayout with new widget_open_button ImageView
  • drawable/ic_open.xml: Material "open in new" vector icon (new file)

Two fixes for ActivityWatch#197:

1. **startOfDay consistency**: Widget now reads `startOfDay` from the
   embedded AW server settings (GET /api/0/settings/startOfDay) before
   building the query timeperiod, so it uses the same day boundary as
   aw-webui's Activity view. Falls back to 4 AM (aw-webui default) if
   the server is unavailable or the setting is unset. Also applies the
   same pre-dawn logic as aw-webui: if the current hour is before
   startOfDay, the widget shows the previous calendar day's period.

2. **Open-app button**: Adds a small "open external" icon (widget_open_button)
   next to the "Screen time" header. Tapping it launches MainActivity.
   The main widget body keeps its existing tap-to-refresh behaviour.
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown

Greptile Summary

The PR aligns widget reporting with the configured start-of-day boundary and adds a dedicated button for opening the app.

  • Parses the start-of-day setting as a LocalTime, preserving both hours and minutes.
  • Builds the widget query interval using the configured boundary and pre-boundary date adjustment.
  • Adds an open-app PendingIntent, header button, and vector icon.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains in the fix associated with the previous review thread.

Important Files Changed

Filename Overview
mobile/src/main/java/net/activitywatch/android/widget/CategoryTimeWidgetUpdater.kt Preserves start-of-day minutes in widget query boundaries and wires the new header button to launch MainActivity.
mobile/src/main/res/layout/widget_category_time.xml Restructures the widget header to include the open-app ImageView.
mobile/src/main/res/drawable/ic_open.xml Adds the vector drawable used by the widget's open-app button.

Reviews (2): Last reviewed commit: "fix(widget): preserve minutes in startOf..." | Re-trigger Greptile

parseStartOfDayHour() took only split(":").firstOrNull() so "04:30"
became 4h00m, misaligning the widget with the Activity view for users
with a non-whole-hour boundary.

Refactored to parseStartOfDay() returning LocalTime (org.threeten.bp)
so both hour and minute are preserved. Updated fetchStartOfDay(),
getCategoryTimesToday(), and the day-boundary comparison accordingly.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

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.

Widget time differs from Activity view

1 participant