Skip to content

Instantly share code, notes, and snippets.

@AlexGladkov
Created February 24, 2021 11:39
Show Gist options
  • Save AlexGladkov/fa09d81f63435eb5e2a27aa62361ca35 to your computer and use it in GitHub Desktop.
Save AlexGladkov/fa09d81f63435eb5e2a27aa62361ca35 to your computer and use it in GitHub Desktop.
Repositories
class CatalogVersionRepositoryImpl @Inject constructor(
private val catalogVersionRemoteDataSource: CatalogVersionRemoteDataSource,
private val catalogVersionLocalDataSource: CatalogVersionLocalDataSource
) : CatalogVersionRepository {
override fun checkNeedUpdate(): Single<Boolean> {
return catalogVersionRemoteDataSource.getCurrentCatalogVersion()
.map { remoteCatalogueVersion ->
val localCatalogueVersion = catalogVersionLocalDataSource.getCurrentCatalogVersion()
val hasActualVersion = localCatalogueVersion == remoteCatalogueVersion
catalogVersionLocalDataSource.saveCurrentCatalogVersion(remoteCatalogueVersion)
!hasActualVersion
}
.onErrorTypeJust<RemoteCatalogueVersionFetchError, Boolean>(false)
}
override fun clearCatalogVersion(): Completable {
return Completable.create { catalogVersionLocalDataSource.clearCurrentCatalogVersion() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment