Restore on Device
#
Fetch BooksBefore 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:
disposable += ContactManager.restoreProcessor.getBooks() .observeOn(AndroidSchedulers.mainThread()) .subscribeBy { val books: List<BookItem> = it }
#
Begin RestoreAfter receiving a list of books, you can restore the contacts related to these books by calling:
ContactManager.restoreProcessor.restore(books)
To cancel the restore, you need to call:
ContactManager.restoreProcessor.cancelRestore()
To track the status of a restore, you can subscribe to an observable by calling getRestoreStateObservable
:
val disposable = CompositeDisposable()
disposable += ContactManager.restoreProcessor.getRestoreStateObservable() .observeOn(AndroidSchedulers.mainThread()) .subscribe { restoreState -> when (restoreState) { is RestoreProcessor.RestoreState.None -> {} is RestoreProcessor.RestoreState.Processing -> { when (restoreState.restoreStep) { RestoreProcessor.RestoreStep.COLLECTING -> {} RestoreProcessor.RestoreStep.UPLOADING -> {} RestoreProcessor.RestoreStep.PROCESSING -> {} RestoreProcessor.RestoreStep.DOWNLOADING -> {} RestoreProcessor.RestoreStep.ADDING -> {} } } is RestoreProcessor.RestoreState.Failed -> {} is RestoreProcessor.RestoreState.Succeeded -> {} } }
The getRestoreStateObservable
method emits the following state objects from the RestoreProcessor.RestoreState object:
- None - rest status;
- Processing - processing status with progress
progress: Float
and status of the restore processrestoreStep: BackupStep
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.
- The enum RestoreStep has the following values:
- Succeeded - successful completion of the backup.
- Failed - error state, contains
throwable: Throwable
.