ScrollTimeStore

Persistent storage for scrolling time, breaks, streaks, and session statistics.

This object manages all time-related data storage:

  • Scrolling time: Tracks time spent scrolling per app and total per day
  • Break events: Counts when user takes breaks or gets locked
  • Avoided time: Tracks time "saved" by interventions
  • Streak tracking: Maintains consecutive days of taking breaks
  • Session statistics: Tracks warnings shown, actions taken, cooldowns, etc.

Data is stored in SharedPreferences with keys like:

  • `scroll_2025-10-30_total` - Total scroll time for a day
  • `scroll_2025-10-30_com.instagram.android` - Time for specific app
  • `scroll_2025-10-30_breaks` - Number of breaks taken
  • `scroll_2025-10-30_avoided_ms` - Time avoided in milliseconds

See also

Functions

Link copied to clipboard
fun addAvoidedMs(ctx: Context, savedMillis: Long)
Link copied to clipboard
Link copied to clipboard
fun endSession(ctx: Context, endAt: Long = System.currentTimeMillis())

Ends the current scrolling session and saves the duration.

Link copied to clipboard

Optionally: list all apps for today (to show top apps)

Link copied to clipboard
Link copied to clipboard
fun getStreak(ctx: Context): Int

For header: "🔥 4-day streak"

Link copied to clipboard
Link copied to clipboard

How many breaks user took TODAY (for "You avoided doomscroll 3 times today")

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getTodayForApp(ctx: Context, packageName: String): Long

Get per-app scroll time for today (ms)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Get total scroll time for today (ms)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Avoided doomscroll last week: sum of avoided_ms for last 7 days

Link copied to clipboard

Weekly summary (last 7 days): how many times user avoided doomscroll (for "Weekly summary 30 times")

Link copied to clipboard

Doomscrolled last week: sum of TOTAL scroll time for last 7 days (for "1h 02 min")

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun onBreakTaken(ctx: Context, savedMillis: Long = 15 * 60_000L)

Records when a user takes a break from scrolling.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun startSession(ctx: Context, packageName: String)

Starts tracking a new scrolling session for the specified app.

Link copied to clipboard