mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-03-04 03:17:51 +01:00
Move automatic backup interval to constants
This commit is contained in:
parent
f86dafd528
commit
631ec37d52
@ -192,7 +192,7 @@ fun Context.getAutomaticBackupIntent(): PendingIntent {
|
|||||||
|
|
||||||
fun Context.scheduleNextAutomaticBackup() {
|
fun Context.scheduleNextAutomaticBackup() {
|
||||||
if (config.autoBackup) {
|
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 pendingIntent = getAutomaticBackupIntent()
|
||||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
try {
|
try {
|
||||||
|
@ -73,6 +73,8 @@ const val YEAR = 31536000
|
|||||||
const val EVENT_PERIOD_TODAY = -1
|
const val EVENT_PERIOD_TODAY = -1
|
||||||
const val EVENT_PERIOD_CUSTOM = -2
|
const val EVENT_PERIOD_CUSTOM = -2
|
||||||
|
|
||||||
|
const val AUTO_BACKUP_INTERVAL_IN_DAYS = 1
|
||||||
|
|
||||||
const val EVENT_LIST_PERIOD = "event_list_period"
|
const val EVENT_LIST_PERIOD = "event_list_period"
|
||||||
|
|
||||||
// Shared Preferences
|
// Shared Preferences
|
||||||
|
@ -4,6 +4,7 @@ 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.DAY
|
||||||
import com.simplemobiletools.calendar.pro.helpers.getNowSeconds
|
import com.simplemobiletools.calendar.pro.helpers.getNowSeconds
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
@ -18,7 +19,8 @@ class BootCompletedReceiver : BroadcastReceiver() {
|
|||||||
recheckCalDAVCalendars(true) {}
|
recheckCalDAVCalendars(true) {}
|
||||||
scheduleNextAutomaticBackup()
|
scheduleNextAutomaticBackup()
|
||||||
val now = getNowSeconds()
|
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
|
// device was probably off at the scheduled time so backup now
|
||||||
backupEventsAndTasks()
|
backupEventsAndTasks()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user