Android 12 Developer Preview is here! Try it out, and give us your feedback!

RxSharedPreferencesMigration

interface RxSharedPreferencesMigration<T>
androidx.datastore.rxjava2.RxSharedPreferencesMigration

Client implemented migration interface.

Summary

Public methods
abstract Single<T>
migrate(sharedPreferencesView: SharedPreferencesView, currentData: T)

Maps SharedPreferences into T.

open Single<Boolean>
shouldMigrate(currentData: T)

Whether or not the migration should be run.

Public methods

migrate

abstract fun migrate(
    sharedPreferencesView: SharedPreferencesView,
    currentData: T
): Single<T>

Maps SharedPreferences into T. Implementations should be idempotent since this may be called multiple times. See DataMigration.migrate for more information. The method accepts a SharedPreferencesView which is the view of the SharedPreferences to migrate from (limited to keysToMigrate and a T which represent the current data. The function must return the migrated data.

Parameters
sharedPreferencesView: SharedPreferencesView the current state of the SharedPreferences
currentData: T the most recently persisted data
Return
a Single of the updated data

shouldMigrate

open fun shouldMigrate(currentData: T): Single<Boolean>

Whether or not the migration should be run. This can be used to skip a read from the SharedPreferences.

Parameters
currentData: T the most recently persisted data
Return
a Single indicating whether or not the migration should be run.