Move code to extension

This commit is contained in:
Naveen
2023-03-24 17:42:40 +05:30
parent 631ec37d52
commit eb1c5157af
2 changed files with 10 additions and 9 deletions

View File

@@ -208,6 +208,15 @@ fun Context.cancelScheduledAutomaticBackup() {
alarmManager.cancel(getAutomaticBackupIntent()) 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() { fun Context.backupEventsAndTasks() {
ensureBackgroundThread { ensureBackgroundThread {
val config = config val config = config

View File

@@ -4,9 +4,6 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import com.simplemobiletools.calendar.pro.extensions.* 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 import com.simplemobiletools.commons.helpers.ensureBackgroundThread
class BootCompletedReceiver : BroadcastReceiver() { class BootCompletedReceiver : BroadcastReceiver() {
@@ -18,12 +15,7 @@ class BootCompletedReceiver : BroadcastReceiver() {
notifyRunningEvents() notifyRunningEvents()
recheckCalDAVCalendars(true) {} recheckCalDAVCalendars(true) {}
scheduleNextAutomaticBackup() scheduleNextAutomaticBackup()
val now = getNowSeconds() checkAndBackupEventsOnBoot()
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()
}
} }
} }
} }