Last active
June 19, 2018 12:44
-
-
Save ppicas/f3400f06c61f708c36f86bcab38befc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object DependencyContainer { | |
val jobRepository: JobRepository | |
init { | |
val retrofit = Retrofit.Builder() | |
// ... | |
.build() | |
val stuartApi = retrofit.create(StuartApi::class.java) | |
val apiJobRepository = ApiJobRepository(stuartApi) | |
val jobCache: JobCache = SomeJobCacheImpl() | |
val cachedJobRepository = CachedJobRepository( | |
apiJobRepository, jobCache) | |
val webSocketPushUpdates = WebSocketPushUpdates(getContext()) | |
val pushUpdates = MergePushUpdates(listOf( | |
webSocketPushUpdates, FirebasePushUpdates)) | |
val subscribedJobRepository = SubscribedJobRepository( | |
cachedJobRepository, pushUpdates) | |
jobRepository = subscribedJobRepository | |
} | |
private fun getContext(): Context { | |
// ... | |
} | |
} | |
class MainActivity : Activity() { | |
private val disposables = CompositeDisposable() | |
fun onResume() { | |
super.onResume() | |
val jobRepository: = DependencyContainer.jobRepository | |
val disposable = jobRepository.getJob("001").subscribe({ | |
Log.d("Got a Job #${it.id}") | |
}) | |
disposables.add(disposable) | |
} | |
fun onPause() { | |
super.onPause() | |
disposables.clear() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment