Skip to content

feat(mobile-android): add analytics - #4761

Open
AatmanAJ wants to merge 705 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-analytics
Open

AatmanAJ wants to merge 705 commits into
CapSoftware:mainfrom
AatmanAJ:feat/mobile-android-analytics

Conversation

@AatmanAJ

@AatmanAJ AatmanAJ commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on the settings PR (#4758), which sits on the earlier Android PRs. Only the top 13 commits are new here, from 0d29e8c18 onwards, including a merge of the settings PR at c34367b4e and two fixes from review. Once the PRs below merge this shows only its own diff.

This PR adds the Analytics tab and the analytics for a single Cap, ported from iOS.

What is in it

Someone on Cap Pro can now see how their organisation's Caps, or one Cap, were watched: totals, a trend over time, where and on what they were watched, and the most watched Caps.

  • Loading and caching. AnalyticsModel ports the iOS model: one state per organisation, range and Space (loading, loaded, Cap Pro required, failed), a single load in flight per key, and nothing loaded until the organisation is known. The organisation's cached analytics show first under the iOS key analytics-<organisation>-<space or all>-<range> and the server's answer replaces them. A Cap's analytics are never cached, as on iOS. A failure with analytics already showing becomes a toast; otherwise it shows in place.
  • The Analytics tab. The 24H, 7D, 30D and All range picker, read out as "Last 24 hours" and so on, and the states: a skeleton read as "Loading analytics", "Analytics is a Cap Pro feature" with the iOS description, or "Analytics unavailable" with the error and Try again. Pull to refresh forces a load. When the organisation has Spaces, a Filter menu offers "Whole organization" and each Space.
  • Tiles. Views, Comments and Reactions, plus Caps for the organisation, each with its tinted icon, the number in the locale's grouping and its title, read as one element. The design system gains the purple the Caps tile uses, light and dark, matching the iOS system purple.
  • Trend chart. Views, Comments or Reactions over time, picked from a menu and drawn on a Canvas: a gradient area under a monotone line, dashed grid lines with round-number labels and up to four date labels. Dragging selects the nearest point, changes the subtitle to " on " and ticks on each change of point. With no points the card says "No activity in this period.", and TalkBack reads the chart as " over time".
  • Breakdowns. Locations (Countries and Cities) and Technology (Browsers, OS and Devices), each listing up to eight rows with a flag where there is a country code, the views, the share and a bar scaled to the largest row.
  • Top Caps and per-Cap analytics. The organisation screen lists its ten most watched Caps; tapping one opens that Cap inside the Analytics tab, so back returns to Analytics. Analytics on the Cap screen now opens the same screen for that Cap, with a back button, the Cap's title and no Caps tile. To let a Cap open from either tab, the Cap, editor and Cap analytics routes go back on the stack of the tab that shows them.

Screenshots

Light Dark
Analytics tab, loaded
Cap Pro required
Error, with Try again
Loading skeleton
Trend chart samples in the gallery

All on the API 37 emulator, signed in to the fixture server, from builds of the live updates PR stacked on this one (0ac84d286 and 38847eef8), which change nothing on these screens. The Cap Pro state uses the fixture's account without analytics. The error state was taken at 38847eef8 by loading 7D, stopping the fixture server and then picking 24H (light) and 30D (dark), ranges that had not loaded yet.

Not captured: the chart while dragging, because the emulator captures did not show the selection; the analytics for one Cap; and the skeleton and gallery in dark, because the gallery's theme extra did not switch that screen.

Where it differs from iOS, on purpose

  • The chart is drawn by hand on a Compose Canvas rather than with a charting library, so the app takes on no new dependency for its one chart.

Fixes from review

  • The settings PR is merged in. Its latest commits, up to c34367b4e, come in through a merge rather than a rebase, so the commits the device runs below were made on stay in the branch.
  • Analytics follow the organisation switch. Organisation analytics are asked for without naming the organisation, so the server answers for whichever one is active. A load still running when the user switched organisation could store, and cache on disk, the new organisation's numbers under the one they had left. Switching organisation now cancels every analytics load in flight, and any reply or failure that arrives for an organisation that is no longer current is dropped. AnalyticsModelTest gains two tests for this.
  • Skeleton with the server down. With the fixture server stopped and the app's data cleared, the tab stayed on the loading skeleton. That is the iOS behaviour rather than a stuck request: neither app loads analytics until the organisation is known, and that needs the server. Once the organisation has loaded, a failed load shows the error state above, or a toast over analytics already showing.
  • Analytics stay with their organisation while the tab is closed. Only the Analytics screen told the model about an organisation switch, so a load still running while the user switched organisation from Settings could save the new organisation's numbers under the one they had left. The session now tells the organisation's analytics itself: a switch cancels their loads and holds new ones back until it has finished, and they then follow the new organisation. A switch that fails keeps the Space filter. SessionModelTest holds the analytics reply and the switch with deferreds and checks that nothing is saved under the organisation left.
  • Vertical swipes on the chart scroll the page. The chart took every pointer move, so a swipe up or down that started on it picked points instead of scrolling. It now waits for a horizontal drag before taking the moves, and a vertical drag goes to the page.
  • Gallery labels. The gallery's accessibility label inventory now expects the two trend charts read as "Views over time".

Tests

  • capkit, :capkit:test: 231 tests, none new in this PR.
  • JVM, :app:testDebugUnitTest: 462 tests, 20 of them new in this PR and 6 from the settings commits merged in. SessionModelTest gains one test for analytics during an organisation switch. AnalyticsModelTest (12) covers the Space filter surviving a switch that does not happen, and covers cached analytics showing first and the server's replacing them, Cap Pro being required, a failure shown in place or as a toast over loaded analytics, loading again only when forced, each range and Space kept apart, nothing loading before the organisation is known, the Space filter clearing on an organisation switch, a Cap's analytics never being cached, and a switch of organisation cancelling the load in flight and dropping its reply. TrendChartTest (4) covers dropped buckets, the round-number axis, the nearest point to a touch and the four date labels. BreakdownCardTest (3) covers the row labels, including ", " and "Unknown".
  • Instrumented, new AnalyticsTest (1) against the fixture server: each range is asked for once, 7d first and then 24h, 30d and lifetime, and the picked range shows as selected.
  • Instrumented, new TrendChartGestureTest (1): a downward swipe that starts on the chart in the gallery scrolls the page. On the API 37 emulator it fails without the fix, with the chart at 1899 px before and after the swipe, and passes with it.
  • Instrumented, new TrendChartScreenshotTest (1): the chart with no points, one point and many points, checked by the pixels drawn in the accent colour. GalleryTest also renders the new section in light, dark and at font scale 2, and its label inventory now includes the two charts.

Device runs, connectedDebugAndroidTest once per API against the fixture server. They ran on the live updates PR stacked on this one, which contains every commit here:

  • API 37 emulator, at 0ac84d286: 85 tests, 81 passed. Three failures are CapDetailTest playback tests: playAndPause and aShareLinkWithATimeOpensTheCapThere timed out waiting for Compose to go idle, and aChosenSpeedIsKeptAfterTheAppIsOpenedAgain found no "Playback speed 1×" button. They failed the same way when the class was run again, and this PR does not touch playback. The fourth, LiveUpdateShadeTest, belongs to the live updates PR and is fixed there.
  • API 29 emulator, at 38847eef8: 85 tests, 85 passed.
  • On both, AnalyticsTest, TrendChartScreenshotTest and all four GalleryTest cases pass, including componentsCarryTheIosAccessibilityLabels with the two trend charts.

Checked

  • ./gradlew spotlessCheck :capkit:test :app:testDebugUnitTest :app:lintDebug :app:assembleDebug :app:assembleRelease :app:assembleDebugAndroidTest passes on the last commit, 091f9bfbf: capkit 231 tests and JVM 462 tests with no failures, and no lint errors or warnings. It also passed on the settings merge, dacb7306f, and before it, on 6cc094a7a.

Not checked

  • TrendChartScreenshotTest matches the accent colour exactly at the centre of the dot and the line. If antialiasing or a colour space conversion shifts those pixels on a device, it needs a tolerance.
  • Opening a Cap from Top Caps and editing it from the Analytics tab, on a device.
  • Scrubbing, haptics and TalkBack speech, and a physical phone.

Confidence Score: 2/5RetriggerView in Greptile

The PR is not ready to merge because organization analytics remain unreachable, the folder shortcut can open no dialog, and cancelled uploads can remain unfinished.

Findings

  1. P1 Folder shortcut opens no dialog ▶
  2. P1 Cancelled uploads stay unfinished ▶
  3. P1 Organization analytics cannot open ▶
Fix with agent prompt
### Issue 1
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:383-386
If the user left a Cap or folder open before visiting Settings, the new Folders shortcut returns to that page. It switches tabs without returning `capsStack` to `Route.Caps`.

`NewFolderSheet` is only drawn by `HomeScreen`, so the requested dialog never appears. Return to the library root before starting folder creation, or show the dialog above the tab’s pages.

### Issue 2
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/services/UploadActions.kt:53-58
When the server cannot be reached, cancelling an upload loses the request to delete it. The receiver cancels the upload work, removes its saved record and files, then calls `deleteCap()` and ignores any failure. Nothing retries that deletion when the connection returns, so the cancelled Cap can remain in the library as an unfinished upload.

The call also keeps `goAsync()` open while allowing a 120-second request, which can exceed Android’s broadcast deadline. Keep a saved cancellation request until deletion succeeds, and run the server cleanup in durable background work.

### Issue 3
apps/mobile-android/app/src/main/kotlin/so/cap/mobile/MainShell.kt:242-244
Removing the Analytics tab and its route leaves no way to open organization analytics. The only remaining `AnalyticsScreen` caller uses `AnalyticsScope.Cap`, so Pro users cannot reach organization totals, the Space filter, or Top Caps described in this PR.

Keep an entry point to the organization screen and a test that opens it through `MainShell`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This update keeps transcript search above the scrolling list and limits the comment scroll adjustment to when the composer has focus.

  • Cap Pro users can explore viewing trends and breakdowns for an organization or one Cap.
  • Android users can sign in and use Cap's library, viewing, editing, settings, and upload screens.
  • The mobile API supports organization-aware sharing and sign-in callbacks.
  • CI now checks Android formatting, tests, lint, and release builds.

Reviews (19) · Last reviewed commit: "Merge commit '9941a81ce301111da7a948dc1d..." · Reviewed by Greptile

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@AatmanAJ is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

2 similar comments
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

1 similar comment
@AatmanAJ

AatmanAJ commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@AatmanAJ

AatmanAJ commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

The switch put a Material ripple on its 44dp square touch target, so
pressing a toggle showed a grey box around the 44x26 track. CapTheme now
provides a press indication that fades the control's own pixels and draws
a focus ring only for keyboard focus, so every clickable, selectable and
toggleable in the design system presses without a box. The switch itself
stretches its knob while held, and CapSwitchTrack lets toggleable rows
show the same switch.
The sign-in and first-run heroes blurred each cloud with Modifier.blur
inside a fixed box. RenderEffect clips the blur to that box, the widest
box was squeezed to the screen width, a page-coloured slab under the
bottom cloud blurred into a black smear in dark mode, nothing outside
the hero was clipped, and API 29 and 30 had no blur at all. SkyHero now
draws the design's exact gradient, rings and clouds, renders the clouds
once into a software bitmap with BlurMaskFilter so every API level and
vendor gets the same result, clips to its bounds and ends in the page
colour. In dark mode the sky runs from blue into the page instead of
through a white cloud bank. Both heroes now reach under the status bar,
which gains a scrim once the page scrolls.
…ttings

Notification rows drew the stock Material switch, which is a different
size and colour from the 44x26 design switch every other settings row
uses. They now show CapSwitchTrack. The two switch lines on Recording
defaults each drew a top and a bottom hairline, so the rule between them
was twice as thick as every other divider.
Keeps this layer's theme root, which already wraps Root in the picture
in picture box.

This branch has not been deployed

No deployments
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