/** Ċ Ġ* ĠSPDX - License - Identifier : ĠMIT Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 0 ĠQ azi ĠF ah im ĠFar han Ċ Ġ*/ Ċ package Ġapp . applications . news app Ċ Ċ import Ġandroid . graphics . Bitmap Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . paging . Live Paged List Builder Ċ import Ġandroidx . paging . Paged List Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġandroidx . swiper ef resh layout . widget . Swipe Refresh Layout Ċ import Ġapp . applications . news app . database . News Room Database Ċ import Ġapp . applications . news app . model . Article Ċ import Ġapp . applications . news app . model . News ApiResponse Ċ import Ġapp . applications . news app . network . Ret rofit Client Ċ import Ġapp . applications . news app . view model . News ViewModel Ċ import Ġretrofit 2 . Call Ċ import Ġretrofit 2 . Callback Ċ import Ġretrofit 2 . Response Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĠĠĠ Ġ/** ĠConst s Ġ*/ ĊĠĠĠ Ġcompanion Ġobject { ĊĠĠĠĠĠĠĠ Ġpublic Ġvar ĠTAG Ġ= ĠMainActivity :: class . java . simple Name ; ĊĠĠĠ Ġ} ĊĠĠĠ Ġ/** ĠVariables Ġ*/ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnews ViewModel : News ViewModel ; ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġswipe Refresh Layout : Swipe Refresh Layout ; ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnews Feed RecyclerView : RecyclerView ; ĊĠĠĠ Ġprivate Ġvar Ġnews Feed Adapter : News Feed Adapter ? Ġ= Ġnull ; ĊĊĠĠĠ Ġ/** ĠConstructors Ġ*/ ĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ); ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ); ĊĠĠĠĠĠĠĠ Ġinit Gui (); ĊĊĠĠĠĠĠĠĠ Ġthis . news ViewModel Ġ= ĠViewModel Provider ( this ). get ( News ViewModel :: class . java ); ĊĊĠĠĠĠĠĠĠ Ġthis . news ViewModel . news Repository . live Article List . observe ( this , ĠObserver < Paged List < Article >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpage d List Ġ-> Ġnews Feed Adapter ?. submit List ( page d List ); ĊĠĠĠĠĠĠĠ Ġ}); ĊĊĠĠĠĠĠĠĠ Ġthis . news ViewModel . news Repository . live Loader State . observe ( this , ĠObserver < Loader State >{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠnewState Ġ-> Ġnews Feed Adapter ?. set Loader State ( newState ); ĊĠĠĠĠĠĠĠ Ġ}); ĊĊĠĠĠĠĠĠĠ Ġthis . news ViewModel . news Repository . live Images List . observe ( this , ĠObserver < ArrayList < String >> { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġimages List Ġ-> Ġnews Feed Adapter ?. submit Images ( images List ); ĊĠĠĠĠĠĠĠ Ġ}); ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** Ġprivate Ġmethods Ġ*/ ĊĠĠĠ Ġprivate Ġfun Ġinit Gui (){ ĊĠĠĠĠĠĠĠ Ġnews Feed RecyclerView Ġ= ĠfindViewById ( R . id . news Feed RecyclerView ); ĊĠĠĠĠĠĠĠ Ġnews Feed Adapter Ġ= ĠNews Feed Adapter (); ĊĊĠĠĠĠĠĠĠ Ġval Ġlinear LayoutManager : Linear LayoutManager Ġ= ĠLinearLayoutManager ( this ); ĊĠĠĠĠĠĠĠ Ġnews Feed RecyclerView . layout Manager Ġ= Ġlinear LayoutManager ; ĊĠĠĠĠĠĠĠ Ġnews Feed RecyclerView . adapter Ġ= Ġnews Feed Adapter ; ĊĊĠĠĠĠĠĠĠ Ġswipe Refresh Layout Ġ= ĠfindViewById ( R . id . swipe Refresh Layout ); ĊĠĠĠĠĠĠĠ Ġswipe Refresh Layout . setOn Refresh Listener ( Swipe Refresh Layout . On Refresh Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġtodo : Ġrefresh ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnews ViewModel . news Repository . forced Refresh (); ĊĠĠĠĠĠĠĠĠĠĠĠ Ġswipe Refresh Layout . is Refresh ing Ġ= Ġfalse ; ĊĊĠĠĠĠĠĠĠ Ġ}); ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġtest Ġ-------------------------------- ------- ĊĊĠĠĠ Ġ/** Ġpublic Ġap is Ġ*/ Ċ }