Move automatic backup interval to constants

This commit is contained in:
Naveen 2023-03-24 17:35:41 +05:30
parent f86dafd528
commit 631ec37d52
3 changed files with 6 additions and 2 deletions

View file

@ -192,7 +192,7 @@ fun Context.getAutomaticBackupIntent(): PendingIntent {
fun Context.scheduleNextAutomaticBackup() {
if (config.autoBackup) {
val backupAtMillis = DateTime.now().plusDays(1).withHourOfDay(6).millis
val backupAtMillis = DateTime.now().withHourOfDay(6).plusDays(AUTO_BACKUP_INTERVAL_IN_DAYS).millis
val pendingIntent = getAutomaticBackupIntent()
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
try {

View file

@ -73,6 +73,8 @@ const val YEAR = 31536000
const val EVENT_PERIOD_TODAY = -1
const val EVENT_PERIOD_CUSTOM = -2
const val AUTO_BACKUP_INTERVAL_IN_DAYS = 1
const val EVENT_LIST_PERIOD = "event_list_period"
// Shared Preferences

View file

@ -4,6 +4,7 @@ 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
@ -18,7 +19,8 @@ class BootCompletedReceiver : BroadcastReceiver() {
recheckCalDAVCalendars(true) {}
scheduleNextAutomaticBackup()
val now = getNowSeconds()
if (config.autoBackup && config.lastAutoBackupTime !in (now - DAY)..now) {
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()
}