package Ġcom . example . me e era . browser app . Service Ċ Ċ import Ġandroid . util . Log Ċ import Ġcom . example . me e era . browser app . Model . Article Detail Ċ import Ġcom . example . me e era . browser app . Model . Article Event Ċ import Ġcom . example . me e era . browser app . Model . Articles Ċ import Ġcom . jak ew h art on . ret rofit 2 . adapter . rx java 2 . Rx Java 2 Call Adapter Factory Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Observer Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . dis pos ables . Disposable Ċ import Ġio . reactivex . functions . Function 5 Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġio . realm . Realm Ċ import Ġio . realm . Realm List Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . converter . gson . Gson Converter Factory Ċ import Ġjava . text . SimpleDateFormat Ċ import Ġjava . util .* Ċ import Ġkotlin . properties . Deleg ates Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġme e era Ġon Ġ 1 5 / 1 0 / 1 7 . Ċ Ġ*/ Ċ class ĠNetwork Call ( var Ġdata : ĠgetData ) Ġ{ ĊĊĠĠĠ Ġvar Ġarticles Ġ= ĠRealm List < Article Detail >() ĊĠĠĠ Ġvar Ġrealm : ĠRealm Ġby ĠDeleg ates . notNull () ĊĠĠĠ Ġinternal Ġvar Ġcombined Ġ= ĠRealm List < Article Detail >() ĊĠĠĠ Ġinternal Ġvar Ġretrofit Ġ= ĠRet rofit . Builder (). baseUrl (" https :// news api . org / "). add Converter Factory ( Gson Converter Factory . create ()). add Call Adapter Factory ( Rx Java 2 Call Adapter Factory . create ()). build () ĊĠĠĠ Ġinternal Ġvar Ġbusiness Ġ= Ġretrofit . create ( New Service :: class . java ). get News (" business - ins ider ", Ġ" a 7 8 2 2 d 7 c 5 8 dd 4 e 5 0 b 1 ebb 3 e 1 b 6 9 4 8 6 b 6 "). subscribe On ( Schedulers . new Thread ()). observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġinternal Ġvar Ġes pn Ġ= Ġretrofit . create ( New Service :: class . java ). get News (" es pn ", Ġ" a 7 8 2 2 d 7 c 5 8 dd 4 e 5 0 b 1 ebb 3 e 1 b 6 9 4 8 6 b 6 "). subscribe On ( Schedulers . new Thread ()). observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġinternal Ġvar Ġtech c runch Ġ= Ġretrofit . create ( New Service :: class . java ). get News (" tech c runch ", Ġ" a 7 8 2 2 d 7 c 5 8 dd 4 e 5 0 b 1 ebb 3 e 1 b 6 9 4 8 6 b 6 "). subscribe On ( Schedulers . new Thread ()). observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġinternal Ġvar Ġm tv News Ġ= Ġretrofit . create ( New Service :: class . java ). get News (" mt v - news ", Ġ" a 7 8 2 2 d 7 c 5 8 dd 4 e 5 0 b 1 ebb 3 e 1 b 6 9 4 8 6 b 6 "). subscribe On ( Schedulers . new Thread ()). observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġinternal Ġvar Ġmet ro Ġ= Ġretrofit . create ( New Service :: class . java ). get News (" metro ", Ġ" a 7 8 2 2 d 7 c 5 8 dd 4 e 5 0 b 1 ebb 3 e 1 b 6 9 4 8 6 b 6 "). subscribe On ( Schedulers . new Thread ()). observe On ( Android Schedulers . main Thread ()) ĊĊĠĠĠ Ġinternal Ġvar Ġarticle Ġ= ĠObservable . zip ( business , Ġes pn , Ġtech c runch , Ġm tv News , Ġmet ro , ĠFunction 5 < Articles , ĠArticles , ĠArticles , ĠArticles , ĠArticles , ĠArticle Event > Ġ{ Ġarticles , Ġarticles 2 , Ġarticles 3 , Ġarticles 4 , Ġarticles 5 Ġ-> ĊĠĠĠĠĠĠĠ Ġcombined . addAll ( articles . articles ) ĊĠĠĠĠĠĠĠ Ġcombined . addAll ( articles 2 . articles ) ĊĠĠĠĠĠĠĠ Ġcombined . addAll ( articles 3 . articles ) ĊĠĠĠĠĠĠĠ Ġcombined . addAll ( articles 4 . articles ) ĊĠĠĠĠĠĠĠ Ġcombined . addAll ( articles 5 . articles ) ĊĠĠĠĠĠĠĠ ĠArticle Event ( combined ) ĊĠĠĠ Ġ}) ĊĊĠĠĠ Ġfun Ġget Sub () Ġ{ ĊĠĠĠĠĠĠĠ Ġrealm Ġ= ĠRealm . getDefaultInstance () ĊĠĠĠĠĠĠĠ Ġarticle . subscribe ( object Ġ: ĠObserver < Article Event > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Subscribe ( d : ĠDis posable ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Next ( article Event : ĠArticle Event ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġarticles Ġ= Ġarticle Event . article ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdata . get Datas ( articles ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonError ( t : ĠThrowable ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonComplete () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d (" AM IT AM IT AM IT ", Ġ" Completed ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinterface ĠgetData Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġget Datas ( articles : ĠList < Article Detail >) ĊĠĠĠ Ġ} Ċ }