package Ġcom . j pp . mp credits Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . view Models Ċ import Ġandroidx . recyclerview . widget . Divider Item Decoration Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . j pp . mp . common . extensions . observe Value Ċ import Ġcom . j pp . mp . common . extensions . set Screen Title Ċ import Ġcom . j pp . mp . common . view model . MP Generic Saved State ViewModel Factory Ċ import Ġcom . j pp . mp credits . databinding . Credits Fragment Binding Ċ import Ġdagger . android . support . Android Support Injection Ċ import Ġjavax . inject . Inject Ċ Ċ /** Ċ Ġ* ĠFragment Ġused Ġto Ġshow Ġthe Ġlist Ġof Ġcredits Ġthat Ġbelongs Ġto Ġa Ġparticular Ġmovie Ġselected Ġby Ġthe Ġuser . Ċ Ġ* Ċ Ġ* ĠWhen Ġinstantiated , Ġthis Ġfragment Ġinvokes Ġthe Ġ[ Credits ViewModel ] Ġmethods Ġin Ġorder Ġto Ġretrieve Ċ Ġ* Ġand Ġshow Ġthe Ġcredits Ġof Ġthe Ġmovie Ġthat Ġhas Ġbeen Ġselected Ġby Ġthe Ġuser . ĠThe ĠVM Ġwill Ġperform Ġthe Ċ Ġ* Ġfetch Ġand Ġwill Ġupdate Ġthe ĠUI Ġstates Ġrepresented Ġby Ġ[ Credits ViewState ] Ġand Ġthis ĠFragment Ġwill Ċ Ġ* Ġrender Ġthose Ġupdates . Ċ Ġ* Ċ Ġ* ĠPre - condition : Ġin Ġorder Ġto Ġinstantiate Ġthis ĠFragment , Ġa Ġmovie ĠID Ġmust Ġbe Ġprovided Ġin Ġthe Ġarguments Ċ Ġ* Ġof Ġthe ĠFragment . Ċ Ġ*/ Ċ class ĠCred its Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar Ġcredits ViewModel Factory : ĠCred its ViewModel Factory ĊĊĠĠĠ Ġprivate Ġvar Ġview Binding : ĠCred its Fragment Binding ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠCred its ViewModel Ġby Ġview Models Ġ{ ĊĠĠĠĠĠĠĠ ĠMP Generic Saved State ViewModel Factory ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcredits ViewModel Factory , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġvar Ġmovie Credits Rv : ĠRecyclerView ? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun Ġon Attach ( context : ĠContext ) Ġ{ ĊĠĠĠĠĠĠĠ ĠAndroid Support Injection . inject ( this ) ĊĠĠĠĠĠĠĠ Ġsuper . on Attach ( context ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠĠĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġview Binding Ġ= ĠData Binding Util . inflate ( in flater , ĠR . layout . credits _ fragment , Ġcontainer , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġreturn Ġview Binding ?. root ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġsetup Views ( view ) ĊĠĠĠĠĠĠĠ ĠviewModel . view State . observe Value ( view Lifecycle Owner , Ġ:: render ViewState ) ĊĠĠĠĠĠĠĠ ĠviewModel . on Init ( Credits Init Param . create ( this @ Credits Fragment )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġview Binding Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġmovie Credits Rv Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup Views ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġmovie Credits Rv Ġ= Ġview . findViewById < RecyclerView >( R . id . credits Rv ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Item Decoration ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDiv ider Item Decoration ( context , Ġ( layout Manager Ġas ĠLinearLayoutManager ). orientation ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrender ViewState ( view State : ĠCred its ViewState ) Ġ{ ĊĠĠĠĠĠĠĠ Ġset Screen Title ( view State . screen Title ) ĊĠĠĠĠĠĠĠ Ġmovie Credits Rv ?. adapter Ġ= ĠCred its Adapter ( view State . credits ViewState . credit Items ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . on Credit ItemSelected ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġview Binding ?. view State Ġ= Ġview State ĊĠĠĠĠĠĠĠ Ġview Binding ?. execute Pending Bindings () ĊĠĠĠ Ġ} Ċ } Ċ