Package-level declarations
Backup contacts.
Backup Contacts
The library provides functions for Manual and Planned backups, as well as mechanisms for tracking the backup process.
Manual Backup
The manual backup functionality is implemented by the BackupManager. Manual backup is called as follows:
val contactManager: ContactManager
val backupManager: BackupManager = contactManager.backup
val backupJob: Job = backupManager.backup()
// Than you can track backup process
lifecycleScope.launch {
backupManager.state.collect { backupState ->
when (backupState) {
is BackupState.NotActive -> {}
is BackupState.Preparation -> {}
is BackupState.Processing -> {}
is BackupState.Succeeded -> {}
is BackupState.Failed -> {}
}
}
}The ``backupManager.state`` flow emits the following state objects from the BackupState object:
NotActive - rest status;
Preparation - preparation status;
Processing - processing status with progress
`progress: Float`and status of the backup process``step: BackupStep``variables.The enum BackupStep has the following values:
``COLLECTING``- collection of local contacts from the device. It has a measurable progress: 0..1.``UPLOADING``- uploading update to backend. The progress is indeterminate = -1.Succeeded - successful completion of the backup.
Failed - error state, contains
``throwable: Throwable``.
After the backup is completed, you can reset the backup state to return the UI to its original state:
backupManager.backup.resetBackupState()To get the actual date of the last backup date, call ``getLastBackupDate``:
val contactManager: ContactManager
val backupManager: BackupManager = contactManager.backup
val date = backupManager.getLastBackupDate()
if (date > 0) {
lastBackupValue.text = dateFormatter.format(Date(date))
} else {
// no backups
}Planned Backup
To control the planned backup, you can set the backup period value:
val contactManager: ContactManager
val backupManager: BackupManager = contactManager.backup
backupManager.backupFrequency.setFrequency(BackupFrequency.DAILY)The enum BackupFrequency contains the following values: ``NONE``, ``DAILY``, ``WEEKLY``, ``MONTHLY``.
To monitor the next backup date, you need to call:
val contactManager: ContactManager
val backupManager: BackupManager = contactManager.backup
lifecycleScope.launch {
backupManager.frequency.collect { frequency -> // frequency: BackupFrequency
// Handle it...
}
}