RxSharedPreferencesMigration

interface RxSharedPreferencesMigration<T extends Object>


Client implemented migration interface.

Summary

Public methods

abstract @NonNull Single<@NonNull T>
migrate(
    @NonNull SharedPreferencesView sharedPreferencesView,
    @NonNull T currentData
)

Maps SharedPreferences into T.

@NonNull Single<@NonNull Boolean>
shouldMigrate(@NonNull T currentData)

Whether or not the migration should be run.

Public methods

migrate

@NonNull
public abstract Single<@NonNull T> migrate(
    @NonNull SharedPreferencesView sharedPreferencesView,
    @NonNull T currentData
)

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.

If SharedPreferences is empty or does not contain any keys which you specified, this callback will not run.

Parameters
@NonNull SharedPreferencesView sharedPreferencesView

the current state of the SharedPreferences

@NonNull T currentData

the most recently persisted data

Returns
Single<@NonNull T>

a Single of the updated data

shouldMigrate

@NonNull
public Single<@NonNull BooleanshouldMigrate(@NonNull T currentData)

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

Parameters
@NonNull T currentData

the most recently persisted data

Returns
Single<@NonNull Boolean>

a Single indicating whether or not the migration should be run.