/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠM os by X Ġcontributors Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . g art es k . mos by x . m vi . sample . view . product . category Ċ Ċ import Ġcom . g art es k . mos by x . m vi . M vi Base Presenter Ċ import Ġcom . g art es k . mos by x . m vi . sample . business logic . http . Product Backend Api Decorator Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ Ċ class ĠCategory Presenter ( private Ġval Ġbackend Api : ĠProduct Backend Api Decorator ) Ġ: Ċ ĉ M vi Base Presenter < Category View , ĠCategory ViewState >() Ġ{ ĊĊ ĉ override Ġfun Ġbind Intent s () Ġ{ Ċĉ ĉ val Ġcategory ViewState Observable : ĠObservable < Category ViewState > Ġ= Ġintent Ġ{ Ġit . load Intent s () Ġ} Ċĉĉ ĉ . flatMap Ġ{ Ġcategory Name Ġ-> Ċĉĉĉ ĉ backend Api . getAll Products Of Category ( category Name ) Ċĉĉĉĉ ĉ . subscribe On ( Schedulers . io ()) Ċĉĉĉĉ ĉ . map < Category ViewState > Ġ{ Ġproducts Ġ-> Ċĉĉĉĉĉ ĉ Category ViewState . Data State ( Ċĉĉĉĉĉĉ ĉ products Ċĉĉĉĉĉ ĉ ) Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ . start With ( Category ViewState . Loading State ) Ċĉĉĉĉ ĉ . onError Return Ġ{ Ċĉĉĉĉĉ ĉ Category ViewState . Error State ( Ċĉĉĉĉĉĉ ĉ it Ċĉĉĉĉĉ ĉ ) Ċĉĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉĉ ĉ . observe On ( Android Schedulers . main Thread ()) ĊĊĉ ĉ subscribe ViewState ( category ViewState Observable ) Ġ{ Ġview , Ġview State Ġ-> Ċĉĉ ĉ view . render ( view State ) Ċĉ ĉ } Ċ ĉ } Ċ Ċ }