package Ġcom . example . my di agnosis . fragment Ċ Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . arch . lifecycle . ViewModel Providers Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . annotation . Nullable Ċ import Ġandroid . support . v 4 . app . Fragment Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġcom . example . my di agnosis . R Ċ import Ġcom . example . my di agnosis . adapter . Lab Tests Adapter Ċ import Ġcom . example . my di agnosis . model . Lab Test Ċ import Ġcom . example . my di agnosis . view model . Lab Tests ViewModel Ċ Ċ class ĠSecond Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlab Tests ViewModel : ĠLab Tests ViewModel ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġre cyclerView : ĠRecyclerView ĊĊĠĠĠ Ġprivate Ġfun Ġon Lab Tests F etched ( lab Tests Ġ: ĠList < Lab Test >, Ġre cyclerView : ĠRecyclerView ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= ĠLab Tests Adapter ( require Context (), Ġlab Tests . to Mutable List (), Ġthis . layout Inflater , Ġlab Tests ViewModel ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= ĠLinearLayoutManager ( require Context ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate (@ Nullable ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġlab Tests ViewModel Ġ= ĠViewModel Providers . of ( this ). get ( Lab Tests ViewModel :: class . java ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . second _ fragment , Ġcontainer , Ġfalse ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġre cyclerView Ġ= Ġview . findViewById ( R . id . re cyclerView Lab Tests ) ĊĊĠĠĠĠĠĠĠ Ġlab Tests ViewModel . lab Tests . observe ( this , ĠObserver Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġit ?. let { Ġon Lab Tests F etched ( it , Ġre cyclerView ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġval Ġlocal Context Ġ: ĠContext ? Ġ= Ġactivity ĊĊĠĠĠĠĠĠĠ Ġif ( local Context Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġlab Tests ViewModel . fetch Lab Tests ( local Context ) ĊĊĠĠĠ Ġ} Ċ Ċ }