package Ġcom . mo kel ab . demo . sam collection . jet pack . arch . room Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Providers Ċ import Ġandroidx . navigation . Navigation Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġcom . mo kel ab . demo . binding . Binding Fragment Ċ import Ġcom . mo kel ab . demo . sam collection . R Ċ import Ġcom . mo kel ab . demo . sam collection . databinding . Jet pack Room Basic Fragment Binding Ċ import Ġkotlinx . coroutines .* Ċ import Ġkotlin . coroutines . Coroutine Context Ċ Ċ class ĠJet pack Room Basic Fragment : ĠBinding Fragment < Jet pack Room Basic Fragment Binding >(), ĠCor outine Scope Ġ{ ĊĠĠĠ Ġprivate Ġval Ġjob Ġ= ĠJob () ĊĊĠĠĠ Ġoverride Ġval Ġcoroutine Context : ĠCor outine Context ĊĠĠĠĠĠĠĠ Ġget () Ġ= ĠDispatch ers . Main Ġ+ Ġjob ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠJet pack Room Basic ViewModel ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġadapter : ĠArticle Adapter ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġthis . viewModel Ġ= ĠViewModel Providers . of ( require Activity ()). get ( Jet pack Room Basic ViewModel :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewData Binding ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠĠĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠJet pack Room Basic Fragment Binding Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbinding Ġ= ĠJet pack Room Basic Fragment Binding . inflate ( in flater , Ġcontainer , Ġfalse ) ĊĊĠĠĠĠĠĠĠ Ġbinding . recycler . layout Manager Ġ= ĠLinearLayoutManager ( in flater . context , ĠLinearLayoutManager . VERTICAL , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġthis . adapter Ġ= ĠArticle Adapter ( in flater . context , Ġthis . listener ) ĊĠĠĠĠĠĠĠ Ġbinding . recycler . adapter Ġ= Ġthis . adapter ĊĊĠĠĠĠĠĠĠ Ġbinding . fab . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠNavigation . find Nav Controller ( view !! ). navigate ( R . id . action _ jet pack Room Basic _ to _ Create ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġbinding ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġthis . viewModel . dao . getAll (). observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . submit List ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . notify DataSet Changed () ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġlistener Ġ= ĠView . OnClickListener Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġposition Ġ= Ġbinding . recycler . getChild Adapter Position ( it ) ĊĠĠĠĠĠĠĠ Ġval Ġarticle Ġ= Ġadapter . getItem At Position ( position ) ĊĠĠĠĠĠĠĠ Ġlaunch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwith Context ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . dao . delete ( article ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Stop () ĊĠĠĠĠĠĠĠ Ġcoroutine Context . cancel Children () ĊĠĠĠ Ġ} ĊĊ Ċ }