mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Move code to extension
This commit is contained in:
@@ -208,6 +208,15 @@ fun Context.cancelScheduledAutomaticBackup() {
|
||||
alarmManager.cancel(getAutomaticBackupIntent())
|
||||
}
|
||||
|
||||
fun Context.checkAndBackupEventsOnBoot() {
|
||||
val now = getNowSeconds()
|
||||
val intervalInSeconds = AUTO_BACKUP_INTERVAL_IN_DAYS * DAY
|
||||
if (config.autoBackup && config.lastAutoBackupTime !in (now - intervalInSeconds)..now) {
|
||||
// device was probably off at the scheduled time so backup now
|
||||
backupEventsAndTasks()
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.backupEventsAndTasks() {
|
||||
ensureBackgroundThread {
|
||||
val config = config
|
||||
|
@@ -4,9 +4,6 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.AUTO_BACKUP_INTERVAL_IN_DAYS
|
||||
import com.simplemobiletools.calendar.pro.helpers.DAY
|
||||
import com.simplemobiletools.calendar.pro.helpers.getNowSeconds
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
class BootCompletedReceiver : BroadcastReceiver() {
|
||||
@@ -18,12 +15,7 @@ class BootCompletedReceiver : BroadcastReceiver() {
|
||||
notifyRunningEvents()
|
||||
recheckCalDAVCalendars(true) {}
|
||||
scheduleNextAutomaticBackup()
|
||||
val now = getNowSeconds()
|
||||
val intervalInSeconds = AUTO_BACKUP_INTERVAL_IN_DAYS * DAY
|
||||
if (config.autoBackup && config.lastAutoBackupTime !in (now - intervalInSeconds)..now) {
|
||||
// device was probably off at the scheduled time so backup now
|
||||
backupEventsAndTasks()
|
||||
}
|
||||
checkAndBackupEventsOnBoot()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user