Package-level declarations

Restore

Restore on Device

Fetch Books

Before restoring contacts, you need to get a set of user books linked to the account. The book BookItem is a data structure that contains all the information about your backed up contacts.

To fetch user books, you need to call:

val contactManager: ContactManager
val restoreManager: RestoreManager = contactManager.restore


lifecycleScope.launch {
restoreManager.getBooks.collect { books -> // books: List<BookItem>
// Handle it...
}
}

Begin Restore

After receiving a list of books, you can restore the contacts related to these books by calling:

val contactManager: ContactManager
val restoreManager: RestoreManager = contactManager.restore

val restoreJob: Job = restoreManager.restore()

// Than you can track restore process

lifecycleScope.launch {
restoreManager.state.collect { restoreState ->
when (backupState) {
is BackupState.NotActive -> {}
is BackupState.Preparation -> {}
is BackupState.Processing -> {}
is BackupState.Succeeded -> {}
is BackupState.Failed -> {}
}
}
}

The ``restoreManager.state`` method emits the following state objects from the RestoreStep object:

  • NotActive - rest status;

  • Preparation - preparation status;

  • Processing - processing status with progress `progress: Float` and status of the restore process ``step: RestoreStep`` variables.

    • The enum RestoreStep 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.

      • ``PROCESSING`` - processing update on backend. The progress is indeterminate = -1.

      • ``DOWNLOADING`` - downloading updated book from backend. The progress is indeterminate = -1.

      • ``ADDING`` - creating contacts on the device. It has a measurable progress: 0..1.

  • Succeeded - successful completion of the backup.

  • Failed - error state, contains ``throwable: Throwable``.

Types

Link copied to clipboard
interface RestoreManager
Link copied to clipboard
sealed class RestoreState
Link copied to clipboard

Defines the step of restore process: collecting - collection of local contacts from the device. It has measurable progress: 0..1. uploading - uploading update to backend. Progress is indeterminate = -1. processing - processing update on backend. Progress is indeterminate = -1. downloading - downloading updated book from backend. Progress is indeterminate = -1. adding - creating contacts on the device. It has measurable progress: 0..1.