package Ġcom . example . and rig int ing . feeds . view . main Ċ Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 7 . app . AppCompatActivity Ċ import Ġandroid . support . v 7 . widget . Divider Item Decoration Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . view . View Ċ import Ġcom . example . and rig int ing . feeds . R Ċ import Ġcom . example . and rig int ing . feeds . repo . remote . hack er news . H acker News Response Ċ import Ġcom . example . and rig int ing . feeds . repo . remote . news . News Article Data Ċ import Ġcom . example . and rig int ing . feeds . view model . Feed s ViewModel Ċ Ċ import Ġkotlinx . android . synt hetic . main . activity _ main .* Ċ import Ġkotlinx . android . synt hetic . main . content _ main .* Ċ import Ġorg . k oin . android . view model . ext . android . viewModel ĊĊ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĊĊĠĠĠ Ġprivate Ġval ĠviewModel Ġby ĠviewModel < Feed s ViewModel >() ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnews Adapter : ĠMain Adapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġhack er Adapter : ĠH acker News Adapter ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠĠĠĠĠ Ġset Support ActionBar ( toolbar _ main ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch All Repo (" us ", Ġ" technology ") ĊĊĠĠĠĠĠĠĠ Ġnews Adapter Ġ= ĠMain Adapter ( viewModel , Ġthis ) ĊĠĠĠĠĠĠĠ Ġhack er Adapter Ġ= ĠH acker News Adapter ( viewModel , Ġthis ) ĊĠĠĠĠĠĠĠ Ġsetup News Recycler ( news Adapter ) ĊĠĠĠĠĠĠĠ Ġsetup H acker Recycler ( hack er Adapter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup News Recycler ( adapter : ĠMain Adapter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġnews _ recyclerview . layout Manager Ġ= ĠLinearLayoutManager ( this , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLinearLayoutManager . HORIZONTAL , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġnews _ recyclerview . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ Ġobserve H acker News Data () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup H acker Recycler ( adapter : ĠH acker News Adapter ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhack er _ recyclerview . layout Manager Ġ= ĠLinearLayoutManager ( this , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLinearLayoutManager . VERTICAL , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġhack er _ recyclerview . addItem Decoration ( Divider Item Decoration ( application Context , ĠDiv ider Item Decoration . VERTICAL )) ĊĠĠĠĠĠĠĠ Ġhack er _ recyclerview . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ Ġobserve News Data () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġobserve News Data () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . getAll News (). observe ( this , ĠObserver < List < News Article Data >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it ?. isEmpty () !! ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnews _ recyclerview . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ ĠviewModel . get Loading Data (). observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshim mer _ view _ container _ news . visibility Ġ= Ġif Ġ( it !! ) ĠView . VISIBLE Ġelse ĠView . GONE ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġobserve H acker News Data () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . get H acker News (). observe ( this , ĠObserver < List < H acker News Response >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnews _ recyclerview . visibility Ġ= Ġif Ġ( it ?. isEmpty () !! ) ĠView . GONE Ġelse ĠView . VISIBLE ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ċ Ċ } Ċ