File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
app/src/main/kotlin/de/markusfisch/android/screentime Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -125,14 +125,7 @@ class MainActivity : Activity() {
125125 val d = days + 1
126126 val daysString = resources.getQuantityString(R .plurals.days, d, d)
127127 scope.launch {
128- val now = System .currentTimeMillis()
129- val availableHistoryInDays = db.getAvailableHistoryInDays(now)
130- if (availableHistoryInDays < 1 ) {
131- // Insert an initial SCREEN_ON event if the database is
132- // empty because we can only find an empty database if
133- // the user has started this app for the first time.
134- db.insertScreenEvent(now, true , 0f )
135- }
128+ val availableHistoryInDays = db.getAvailableHistoryInDays()
136129 val bitmap = chart.draw(
137130 timestamp,
138131 days,
Original file line number Diff line number Diff line change @@ -16,11 +16,19 @@ class Database {
1616 db = OpenHelper (context).writableDatabase
1717 }
1818
19- fun getAvailableHistoryInDays (now : Long ): Int {
19+ fun getAvailableHistoryInDays (
20+ now : Long = System .currentTimeMillis()
21+ ): Int {
2022 val earliestTimestamp = db.getEarliestTimestamp()
2123 if (earliestTimestamp > - 1 ) {
2224 val msBetween = startOfDay(now) - startOfDay(earliestTimestamp)
2325 return ceil(msBetween / 86400000.0 ).toInt()
26+ } else {
27+ // Insert an initial SCREEN_ON event if the database is
28+ // empty because we can only find an empty database if
29+ // the user has started this app for the first time,
30+ // in which case the screen must be on.
31+ insertScreenEvent(now, true , 0f )
2432 }
2533 return 0
2634 }
You can’t perform that action at this time.
0 commit comments