Added backup settings

This commit is contained in:
merkost 2023-07-15 13:50:09 +10:00
parent cc332fb0a8
commit 5120ba7863
2 changed files with 49 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.contacts.pro.helpers
import android.content.Context
import android.os.Environment
import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.commons.helpers.SHOW_TABS
@ -12,4 +13,24 @@ class Config(context: Context) : BaseConfig(context) {
var showTabs: Int
get() = prefs.getInt(SHOW_TABS, ALL_TABS_MASK)
set(showTabs) = prefs.edit().putInt(SHOW_TABS, showTabs).apply()
var autoBackup: Boolean
get() = prefs.getBoolean(AUTO_BACKUP, false)
set(enableAutomaticBackups) = prefs.edit().putBoolean(AUTO_BACKUP, enableAutomaticBackups).apply()
var autoBackupFolder: String
get() = prefs.getString(AUTO_BACKUP_FOLDER, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath)!!
set(autoBackupPath) = prefs.edit().putString(AUTO_BACKUP_FOLDER, autoBackupPath).apply()
var autoBackupFilename: String
get() = prefs.getString(AUTO_BACKUP_FILENAME, "")!!
set(autoBackupFilename) = prefs.edit().putString(AUTO_BACKUP_FILENAME, autoBackupFilename).apply()
var autoBackupContactSources: Set<String>
get() = prefs.getStringSet(AUTO_BACKUP_CONTACT_SOURCES, setOf())!!
set(autoBackupContactTypes) = prefs.edit().remove(AUTO_BACKUP_CONTACT_SOURCES).putStringSet(AUTO_BACKUP_CONTACT_SOURCES, autoBackupContactTypes).apply()
var lastAutoBackupTime: Long
get() = prefs.getLong(LAST_AUTO_BACKUP_TIME, 0L)
set(lastAutoBackupTime) = prefs.edit().putLong(LAST_AUTO_BACKUP_TIME, lastAutoBackupTime).apply()
}

View file

@ -3,6 +3,7 @@ package com.simplemobiletools.contacts.pro.helpers
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
import com.simplemobiletools.commons.helpers.TAB_GROUPS
import org.joda.time.DateTime
const val GROUP = "group"
const val IS_FROM_SIMPLE_CONTACTS = "is_from_simple_contacts"
@ -13,6 +14,16 @@ const val DEFAULT_FILE_NAME = "contacts.vcf"
const val AVOID_CHANGING_TEXT_TAG = "avoid_changing_text_tag"
const val AVOID_CHANGING_VISIBILITY_TAG = "avoid_changing_visibility_tag"
const val AUTOMATIC_BACKUP_REQUEST_CODE = 10001
const val AUTO_BACKUP_INTERVAL_IN_DAYS = 1
const val AUTO_BACKUP = "auto_backup"
const val AUTO_BACKUP_FOLDER = "auto_backup_folder"
const val AUTO_BACKUP_FILENAME = "auto_backup_filename"
const val LAST_AUTO_BACKUP_TIME = "last_auto_backup_time"
const val AUTO_BACKUP_CONTACT_SOURCES = "auto_backup_contact_sources"
// extras used at third party intents
const val KEY_NAME = "name"
const val KEY_EMAIL = "email"
@ -53,3 +64,20 @@ const val SIGNAL = "signal"
const val VIBER = "viber"
const val TELEGRAM = "telegram"
const val THREEMA = "threema"
// 6 am is the hardcoded automatic backup time, intervals shorter than 1 day are not yet supported.
fun getNextAutoBackupTime(): DateTime {
val now = DateTime.now()
val sixHour = now.withHourOfDay(6)
return if (now.millis < sixHour.millis) {
sixHour
} else {
sixHour.plusDays(AUTO_BACKUP_INTERVAL_IN_DAYS)
}
}
fun getPreviousAutoBackupTime(): DateTime {
val nextBackupTime = getNextAutoBackupTime()
return nextBackupTime.minusDays(AUTO_BACKUP_INTERVAL_IN_DAYS)
}