package Ġio . pet ros . posts . kotlin . activity . posts . fragment Ċ Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . arch . lifecycle . ViewModel Providers Ċ import Ġandroid . databinding . Data Binding Util Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 4 . widget . Swipe Refresh Layout Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . ViewGroup Ċ import Ġcom . github . sal om on br ys . kode in . instance Ċ import Ġio . pet ros . posts . kotlin . R Ċ import Ġio . pet ros . posts . kotlin . activity . Base Fragment Ċ import Ġio . pet ros . posts . kotlin . activity . posts . fragment . adapter . On Post Item View ClickListener Ċ import Ġio . pet ros . posts . kotlin . activity . posts . fragment . adapter . Posts Adapter Ċ import Ġio . pet ros . posts . kotlin . activity . posts . fragment . view model . Posts ViewModel Ċ import Ġio . pet ros . posts . kotlin . databinding . Fragment Posts Binding Ċ import Ġio . pet ros . posts . kotlin . model . Post Ċ Ċ class ĠPosts Fragment Ġ: ĠBase Fragment < Fragment Posts Binding , ĠPosts ViewModel >(), ĠSw ipe Refresh Layout . On Refresh Listener Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġposts Adapter : ĠPosts Adapter Ġby Ġinjector . instance () ĊĊĠĠĠ Ġ// ĠCONTRACT Ġ// Ġ***************************************************************** ******************************************************** ĊĊĠĠĠ Ġoverride Ġfun Ġconstruct Binding ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?): ĠFragment Posts Binding Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠData Binding Util . inflate ( in flater , ĠR . layout . fragment _ posts , Ġcontainer , Ġfalse ) ĊĊĠĠĠ Ġoverride Ġfun Ġconstruct ViewModel (): ĠPosts ViewModel Ġ= ĠViewModel Providers . of ( this ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. get ( Posts ViewModel :: class . java ) ĊĊĠĠĠ Ġ// ĠL IF EC Y CLE Ġ// Ġ***************************************************************** ************************************************ ******* ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġset Swipe Refresh Layout () ĊĠĠĠĠĠĠĠ Ġset RecyclerView () ĊĠĠĠĠĠĠĠ Ġsubscribe To Posts () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġset Swipe Refresh Layout () Ġ{ ĊĠĠĠĠĠĠĠ Ġbinding . swipe Refresh Layout . setOn Refresh Listener ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġset RecyclerView () Ġ{ ĊĠĠĠĠĠĠĠ Ġposts Adapter . listener Ġ= ĠOn Post Item View ClickListener ( activity ) ĊĠĠĠĠĠĠĠ Ġbinding . posts RecyclerView . adapter Ġ= Ġposts Adapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsubscribe To Posts () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . posts . observe ( this , ĠObserver < List < Post >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġposts Adapter . setData ( it !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . swipe Refresh Layout . is Refresh ing Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Refresh () Ġ{ ĊĠĠĠĠĠĠĠ Ġbinding . swipe Refresh Layout . is Refresh ing Ġ= Ġtrue ĊĠĠĠĠĠĠĠ ĠviewModel . load Posts () ĊĠĠĠ Ġ} Ċ Ċ } Ċ