package Ġcom . android . t ait asci ore . ch ht est . feature . user portfolio . view Ċ Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . arch . lifecycle . ViewModel Providers Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 4 . app . Fragment Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġcom . android . t ait asci ore . ch ht est . R Ċ import Ġcom . android . t ait asci ore . ch ht est . domain . model . Coin Ċ import Ġcom . android . t ait asci ore . ch ht est . domain . model . User Coin Ċ import Ġcom . android . t ait asci ore . ch ht est . feature . user portfolio . User Portfolio Ui Event Ċ import Ġcom . android . t ait asci ore . ch ht est . feature . user portfolio . User Portfolio ViewState Ċ import Ġcom . android . t ait asci ore . ch ht est . feature . user portfolio . view model . User Portfolio ViewModel Ċ import Ġcom . android . t ait asci ore . ch ht est . feature . user portfolio . view model . User Portfolio ViewModel Factory Ċ import Ġcom . android . t ait asci ore . ch ht est . presentation . base . Base View Ċ import Ġcom . android . t ait asci ore . ch ht est . util .* Ċ import Ġcom . jak ew h art on . r xb ind ing 2 . view . Rx View Ċ import Ġio . reactivex . Observable Ċ import Ġkotlinx . android . synt hetic . main . fragment _ user _ portfolio .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ list .* Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠUser Portfolio Fragment Ġ: ĠFragment (), ĠBase View < User Portfolio Ui Event , ĠUser Portfolio ViewState > Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġcoins : ĠArrayList < Coin >? Ġ= Ġnull ĊĊĠĠĠ Ġ@ Inject Ġlateinit Ġvar Ġfactory : ĠUser Portfolio ViewModel Factory ĊĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠUser Portfolio ViewModel Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠViewModel Providers . of ( this , Ġfactory )[ User Portfolio ViewModel :: class . java ] ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser Portfolio Adapter : ĠUser Portfolio Adapter ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġnew Instance ( coins : ĠList < Coin >? Ġ= Ġnull ): ĠUser Portfolio Fragment Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfragment Ġ= ĠUser Portfolio Fragment () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġextras Ġ= ĠBundle () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġextras . put Serializable (" coins ", Ġcoins Ġas ĠArrayList ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment . arguments Ġ= Ġextras ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġfragment ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . fragment _ user _ portfolio , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġget Base Application ()?. component ?. inject ( this ) ĊĠĠĠĠĠĠĠ ĠsetTitle (" Portfolio ") ĊĊĠĠĠĠĠĠĠ Ġcoins Ġ= Ġarguments ?. get Serializable (" coins ") Ġas ĠArrayList < Coin > ĊĊĠĠĠĠĠĠĠ Ġsetup RecyclerView () ĊĊĠĠĠĠĠĠĠ ĠviewModel . states (). observe ( this , ĠObserver Ġ{ Ġrender ( it !! ) Ġ}) ĊĠĠĠĠĠĠĠ ĠviewModel . process Ui Events ( events ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup RecyclerView () Ġ{ ĊĠĠĠĠĠĠĠ Ġlist . is Nested Scrolling Enabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġlist . add Divider ( activity !! , ĠR . drawable . divider ) ĊĠĠĠĠĠĠĠ Ġuser Portfolio Adapter Ġ= ĠUser Portfolio Adapter ( coins !! ) ĊĠĠĠĠĠĠĠ Ġlist . adapter Ġ= Ġuser Portfolio Adapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinitial Event () Ġ= ĠObservable . just ( User Portfolio Ui Event . Initial ()) ĊĊĠĠĠ Ġprivate Ġfun Ġretry Event () Ġ= ĠRx View . click s ( button _ retry ). map Ġ{ ĠUser Portfolio Ui Event . Retry () Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġevents (): ĠObservable < User Portfolio Ui Event > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠObservable . merge ( initial Event (), Ġretry Event ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġrender ( state : ĠUser Portfolio ViewState ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . loading Ġ-> Ġrender Loading State () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . user Coins Ġ!= Ġnull Ġ-> Ġshow User Coins ( state . user Coins ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate . error Ġ!= Ġnull Ġ-> Ġshow Error ( state . error ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrender Loading State () Ġ{ ĊĠĠĠĠĠĠĠ Ġshow Progress () ĊĠĠĠĠĠĠĠ Ġhide View ( layout _ error ) ĊĠĠĠĠĠĠĠ Ġhide View ( user _ portfolio _ text _ view _ total _ price ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Progress () Ġ{ ĊĠĠĠĠĠĠĠ Ġshow View ( progress _ wheel ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġhide Progress () Ġ{ ĊĠĠĠĠĠĠĠ Ġhide View ( progress _ wheel ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow User Coins ( coins : ĠList < User Coin >) Ġ{ ĊĠĠĠĠĠĠĠ Ġuser Portfolio Adapter . add ( coins ) ĊĠĠĠĠĠĠĠ Ġuser _ portfolio _ text _ view _ total _ price . text Ġ= Ġ"$ ${ viewModel . getTotal Price ( coins )}" ĊĠĠĠĠĠĠĠ Ġhide Progress () ĊĠĠĠĠĠĠĠ Ġhide View ( layout _ error ) ĊĠĠĠĠĠĠĠ Ġshow View ( user _ portfolio _ text _ view _ total _ price ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Error ( error : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhide Progress () ĊĠĠĠĠĠĠĠ Ġshow View ( layout _ error ) ĊĠĠĠĠĠĠĠ Ġhide View ( user _ portfolio _ text _ view _ total _ price ) ĊĠĠĠ Ġ} Ċ }