package Ġb ry 1 3 3 7 . github . io . navigation component p oc . presentation . not elist Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Providers Ċ import Ġandroidx . navigation . Navigation . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġb ry 1 3 3 7 . github . io . navigation component p oc . R Ċ import Ġb ry 1 3 3 7 . github . io . navigation component p oc . domain . Note Ċ import Ġkotlinx . android . synt hetic . main . note _ list _ fragment .* Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġed ward . ab erg as Ġon Ġ 2 5 / 0 3 / 2 0 1 9 . Ċ Ġ* Ċ Ġ* Ġ@ author Ġed ward br yan . ab erg as @ gmail . com Ċ Ġ*/ Ċ class ĠNote List Fragment Ġ: ĠFragment () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġclick Listener : ĠClick Listener Ġ= Ġthis :: on Note Clicked ĊĊĠĠĠ Ġprivate Ġval Ġre cyclerView Adapter Ġ= ĠNote Adapter ( click Listener ) ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠNote List ViewModel ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . note _ list _ fragment , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġsetup RecyclerView () ĊĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠViewModel Providers . of ( this ). get ( Note List ViewModel :: class . java ) ĊĠĠĠĠĠĠĠ ĠviewModel . observable Not elist . observe ( this , ĠObserver Ġ{ Ġit Ġ-> Ġit ?. let Ġ{ Ġrender ( it ) Ġ} Ġ}) ĊĊĠĠĠĠĠĠĠ Ġfab . setOnClickListener Ġ{ Ġfind Nav Controller ( it ). navigate ( Note List Fragment Directions . action Notes ToAdd Note ()) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ ĠviewModel . load () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrender ( note List : ĠList < Note >) Ġ{ ĊĠĠĠĠĠĠĠ Ġre cyclerView Adapter . update Notes ( note List ) ĊĠĠĠĠĠĠĠ Ġif Ġ( note List . isEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnotes RecyclerView . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnotes NotFound . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnotes RecyclerView . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnotes NotFound . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Note Clicked ( note : ĠNote ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnav Directions Ġ= ĠNote List Fragment Directions . action Notes To Note Detail ( note . id ) ĊĠĠĠĠĠĠĠ Ġview ?. let Ġ{ Ġfind Nav Controller ( it ). navigate ( nav Directions ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup RecyclerView () Ġ{ ĊĠĠĠĠĠĠĠ Ġnotes RecyclerView . layout Manager Ġ= ĠLinearLayoutManager ( this . context ) ĊĠĠĠĠĠĠĠ Ġnotes RecyclerView . adapter Ġ= Ġre cyclerView Adapter ĊĠĠĠĠĠĠĠ Ġnotes RecyclerView . set Has Fixed Size ( true ) ĊĠĠĠ Ġ} Ċ }