Skip to content

Instantly share code, notes, and snippets.

@scottroemeschke
Last active May 21, 2017 20:51
Show Gist options
  • Save scottroemeschke/7ae07bec2361b74eda853c230d1bdc25 to your computer and use it in GitHub Desktop.
Save scottroemeschke/7ae07bec2361b74eda853c230d1bdc25 to your computer and use it in GitHub Desktop.
kotlin implementation of persisted login details repo
class PersistedLoginDetailsRepo(internal val persistence: RxPaperBook): LoginDetailsRepo {
internal object PersistenceKeys {
val details = "details"
val method = "method"
}
internal val detailsRelay = BehaviorRelay.create<LoginDetails>()
internal val methodRelay = BehaviorRelay.create<LoginMethod>()
override fun observeLoginDetails(): Observable<LoginDetails> {
return detailsRelay.withInitIfEmpty { persistence.read(PersistenceKeys.details, LoginDetails.empty) }
}
override fun observePreferredLoginMethod(): Observable<LoginMethod> {
return methodRelay.withInitIfEmpty { persistence.read(PersistenceKeys.method, LoginMethod.UNKNOWN) }
}
override fun updateLoginDetails(details: LoginDetails): Completable {
return persistance.writeThenForward(PersistenceKeys.details, details, detailsRelay)
}
override fun updateLoginMethod(method: LoginMethod): Completable {
return persistance.writeThenForward(PersistenceKeys.method, method, methodRelay)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment