Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. object DependencyContainer {
  2.  
  3. val jobRepository: JobRepository
  4.  
  5. init {
  6. val retrofit = Retrofit.Builder()
  7. // ...
  8. .build()
  9.  
  10. val stuartApi = retrofit.create(StuartApi::class.java)
  11.  
  12. val apiJobRepository = ApiJobRepository(stuartApi)
  13.  
  14. val jobCache: JobCache = SomeJobCacheImpl()
  15.  
  16. val cachedJobRepository = CachedJobRepository(
  17. apiJobRepository, jobCache)
  18.  
  19. val webSocketPushUpdates = WebSocketPushUpdates(getContext())
  20.  
  21. val pushUpdates = MergePushUpdates(listOf(
  22. webSocketPushUpdates, FirebasePushUpdates))
  23.  
  24. val subscribedJobRepository = SubscribedJobRepository(
  25. cachedJobRepository, pushUpdates)
  26.  
  27. jobRepository = subscribedJobRepository
  28. }
  29.  
  30. private fun getContext(): Context {
  31. // ...
  32. }
  33.  
  34. }
  35.  
  36. class MainActivity : Activity() {
  37.  
  38. private val disposables = CompositeDisposable()
  39.  
  40. fun onResume() {
  41. super.onResume()
  42.  
  43. val jobRepository: = DependencyContainer.jobRepository
  44.  
  45. val disposable = jobRepository.getJob("001").subscribe({
  46. Log.d("Got a Job #${it.id}")
  47. })
  48.  
  49. disposables.add(disposable)
  50. }
  51.  
  52. fun onPause() {
  53. super.onPause()
  54. disposables.clear()
  55. }
  56.  
  57. }
Add Comment
Please, Sign In to add comment