Add deleting old used time items

This commit is contained in:
Jonas L 2019-03-11 00:00:00 +00:00
parent 114b798eaa
commit fe56e19075
4 changed files with 118 additions and 5 deletions

View file

@ -118,6 +118,10 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
private var usedTimeUpdateHelper: UsedTimeItemBatchUpdateHelper? = null
private var previousMainLogicExecutionTime = 0
private var previousMainLoopEndTime = 0L
private val dayChangeTracker = DayChangeTracker(
timeApi = appLogic.timeApi,
longDuration = 1000 * 60 * 10 /* 10 minutes */
)
private val appTitleCache = QueryAppTitleCache(appLogic.platformIntegration)
@ -149,6 +153,18 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
try {
// get the current time
val nowTimestamp = appLogic.timeApi.getCurrentTimeInMillis()
val nowTimezone = TimeZone.getTimeZone(deviceUserEntry.timeZone)
val nowDate = DateInTimezone.newInstance(nowTimestamp, nowTimezone)
val minuteOfWeek = getMinuteOfWeek(nowTimestamp, nowTimezone)
// eventually remove old used time data
if (dayChangeTracker.reportDayChange(nowDate.dayOfEpoch) == DayChangeTracker.DayChange.NowSinceLongerTime) {
UsedTimeDeleter.deleteOldUsedTimeItems(
database = appLogic.database,
date = nowDate
)
}
// get the categories
val categories = childCategories.get(deviceUserEntry.id).waitForNonNullValue()
@ -206,11 +222,6 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
))
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
} else {
val nowTimezone = TimeZone.getTimeZone(deviceUserEntry.timeZone)
val nowDate = DateInTimezone.newInstance(nowTimestamp, nowTimezone)
val minuteOfWeek = getMinuteOfWeek(nowTimestamp, nowTimezone)
// disable time limits temporarily feature
if (nowTimestamp < deviceUserEntry.disableLimitsUntil) {
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(