Skip to content

Load the activity statistics through a ViewModel - #620

Open
greenart7c3 wants to merge 2 commits into
masterfrom
refactor/activity-stats-viewmodel
Open

greenart7c3 wants to merge 2 commits into
masterfrom
refactor/activity-stats-viewmodel

Conversation

@greenart7c3

@greenart7c3 greenart7c3 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Step 6 of docs/architecture.md (keep ui/ off the database), second screen.

ActivityStatsCard (on the activity screens, account-wide and per app) opened the history DAO itself. Now ActivityStatsViewModel does:

  • loads the accepted/rejected counts for the last 24 hours, 7 days and 30 days, once, the first time the card is opened (as the card did), per account and app (the ViewModel is keyed on both)
  • WindowStats and loadStats move there unchanged

The card takes the ViewModel as a default argument (viewModel(key, factory), as the Compose ViewModelInjection rule wants) and only renders.

Architecture allow-list −1 (ActivityStatsCard), detekt baseline −1 (LongMethod for the card), none added. New ActivityStatsViewModelTest: per-app vs account-wide counts, and no second query when the card is opened again. Free and offline unit tests, :architecture-tests:test, detektAll and the pre-push test lint pass.

Review fix: the card kept its counts in remember, so coming back to the screen used to load fresh ones, but the ViewModel outlives that. forget() drops the counts (and cancels a load in flight) when the card leaves composition, so that stays as before; coming back to the screen loads fresh counts covers it.

ActivityStatsCard read the history DAO itself. ActivityStatsViewModel now
loads the accepted/rejected counts for the three windows once, the first
time the card is opened, as the card did; the card leaves the databaseInUi
allow-list and its LongMethod baseline entry. No behaviour change.
Review of #620: the card kept its counts in remember, so coming back to the screen loaded fresh ones; the ViewModel outlives that, and would have shown stale counts. forget() drops them (and cancels a load in flight) when the card is disposed.
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