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())
|
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
|
||||||
|
@@ -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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user