mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-04 10:19:18 +02:00
Add deleting old used time items
This commit is contained in:
parent
b83fc541e6
commit
aa3c4d06e1
5 changed files with 148 additions and 8 deletions
|
@ -128,6 +128,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)
|
||||
|
||||
|
@ -184,6 +188,32 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
|||
// get the current time
|
||||
appLogic.realTimeLogic.getRealTime(realTime)
|
||||
|
||||
val nowTimestamp = realTime.timeInMillis
|
||||
val nowTimezone = TimeZone.getTimeZone(deviceUserEntry.timeZone)
|
||||
|
||||
val nowDate = DateInTimezone.newInstance(nowTimestamp, nowTimezone)
|
||||
val minuteOfWeek = getMinuteOfWeek(nowTimestamp, nowTimezone)
|
||||
|
||||
// eventually remove old used time data
|
||||
if (realTime.shouldTrustTimePermanently) {
|
||||
val dayChange = dayChangeTracker.reportDayChange(nowDate.dayOfEpoch)
|
||||
|
||||
fun deleteOldUsedTimes() = UsedTimeDeleter.deleteOldUsedTimeItems(
|
||||
database = appLogic.database,
|
||||
date = nowDate
|
||||
)
|
||||
|
||||
if (realTime.isNetworkTime) {
|
||||
if (dayChange == DayChangeTracker.DayChange.Now) {
|
||||
deleteOldUsedTimes()
|
||||
}
|
||||
} else {
|
||||
if (dayChange == DayChangeTracker.DayChange.NowSinceLongerTime) {
|
||||
deleteOldUsedTimes()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the categories
|
||||
val categories = childCategories.get(deviceUserEntry.id).waitForNonNullValue()
|
||||
val temporarilyAllowedApps = temporarilyAllowedApps.waitForNonNullValue()
|
||||
|
@ -242,12 +272,6 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
|
|||
))
|
||||
appLogic.platformIntegration.showAppLockScreen(foregroundAppPackageName)
|
||||
} else {
|
||||
val nowTimestamp = realTime.timeInMillis
|
||||
val nowTimezone = TimeZone.getTimeZone(deviceUserEntry.timeZone)
|
||||
|
||||
val nowDate = DateInTimezone.newInstance(nowTimestamp, nowTimezone)
|
||||
val minuteOfWeek = getMinuteOfWeek(nowTimestamp, nowTimezone)
|
||||
|
||||
// disable time limits temporarily feature
|
||||
if (realTime.shouldTrustTimeTemporarily && nowTimestamp < deviceUserEntry.disableLimitsUntil) {
|
||||
appLogic.platformIntegration.setAppStatusMessage(AppStatusMessage(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue