v1.4.0
Full Changelog: v1.3.0...v1.4.0
feat(stats): implement local database history syncing and overlay retrograde support
Optimized historical usage logging and overlay accuracy by shifting to a database-first local cache fallback and implementing retrograde sync on startup.
-
UsageDao.kt:
- Added
@QuerymethodupdateSeconds(pkg, date, seconds)to overwrite total seconds for a package on a specific day without resetting session metadata.
- Added
-
ScreenUsageHelper.kt:
- Added
syncUsageHistory(context, usageStatsManager, dao)to run in the background and sync system stats from the last 8 days into the Room DB (UsageDb->daily_totals). This operates for all apps to establish a permanent offline copy of usage data.
- Added
-
OverlayService.kt:
- Replaced duplicate DB query blocks and synchronous
runBlockingcalls with a single asynchronous coroutine onDispatchers.IOat startup. - Invokes
ScreenUsageHelper.syncUsageHistory(...)on startup to fetch today's accumulated usage up to the second the service starts, resolving the issue where starting the service mid-day would display00:00:00instead of the true ticking total.
- Replaced duplicate DB query blocks and synchronous
-
AppUsageViewModel.kt:
- Added Room DB
UsageDaoinitialization usingUsageDb.get(context).dao(). - Added
syncUsageHistory(...)call on view initialization (loadInitialData()). - Added
getUsageForDateandgetUsageForRangehelper methods to query the local Room database first (priority 1), falling back toUsageStatsManager(priority 2). - Modified
generateWeeklyData()andfilterAndSortDataSync()to query the DB first viagetUsageForDateandgetUsageForRange. - Added
hasUsageForOffset(offset)helper method to query the DB or system for the presence of records on preceding days/weeks. - Dynamically updates
_canGoPrevious.valueat the end ofloadChartDataSync(), effectively disabling the previous page (<) button when no records are available.
- Added Room DB
-
Maintenance:
- Change app
versionNameandversionCodeto1.4.0and4.
- Change app