package Ġcom . ray w ender lich . android . us pace . ui . fragments Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . view Models Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . recyclerview . widget . Divider Item Decoration Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġcom . ray w ender lich . android . us pace . R Ċ import Ġcom . ray w ender lich . android . us pace . databinding . Fragment Drag ons Binding Ċ import Ġcom . ray w ender lich . android . us pace . repository . Space Result Ċ import Ġcom . ray w ender lich . android . us pace . ui . adapters . Dragon Adapter Ċ import Ġcom . ray w ender lich . android . us pace . ui . view models . Dragon ViewModel Ċ import Ġcom . ray w ender lich . android . us pace . utils . show Snackbar Ċ import Ġdagger . android . support . Android Support Injection Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠDrag ons Fragment Ġ: ĠFragment () Ġ{ ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġfun Ġcreate Instance () Ġ= ĠDrag ons Fragment () ĊĠ Ġ} ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar ĠviewModel Factory : ĠViewModel Provider . Factory ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġadapter : ĠDrag on Adapter ĊĠ Ġprivate Ġval ĠviewModel : ĠDrag on ViewModel Ġby Ġview Models Ġ{ ĠviewModel Factory Ġ} ĊĠ Ġprivate Ġvar Ġbinding : ĠFragment Drag ons Binding ? Ġ= Ġnull ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ ĠAndroid Support Injection . inject ( this ) ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠ Ġ): ĠView ? Ġ{ ĊĠĠĠ Ġbinding Ġ= ĠFragment Drag ons Binding . inflate ( in flater ) ĊĠĠĠ Ġreturn Ġbinding ?. root ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠ Ġbinding ?. apply Ġ{ ĊĠĠĠĠĠ Ġdrag ons List . layout Manager Ġ= ĠLinearLayoutManager ( require Context ()) ĊĠĠĠĠĠ Ġdrag ons List . adapter Ġ= Ġadapter ĊĠĠĠĠĠ Ġdrag ons List . addItem Decoration ( Divider Item Decoration ( require Context (), ĠDiv ider Item Decoration . VERTICAL )) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠviewModel . drag ons . observe ( view Lifecycle Owner ) Ġ{ Ġresult Ġ-> ĊĠĠĠĠĠ Ġbinding ?. loading Ġ= Ġfalse ĊĠĠĠĠĠ Ġwhen Ġ( result ) Ġ{ ĊĠĠĠĠĠĠĠ ĠSpace Result . Error Ġ-> Ġbinding ?. root . show Snackbar ( R . string . error _ loading _ data , ĠR . string . try _ again ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠviewModel . get Drag ons () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġis ĠSpace Result . Dragon Result Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġadapter . add Items ( result . drag ons ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġbinding ?. loading Ġ= Ġtrue ĊĠĠĠ ĠviewModel . get Drag ons () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠ Ġbinding Ġ= Ġnull ĊĠ Ġ} Ċ }