package Ġid . must of a . paging ret rofit Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . activity . view Models Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġid . must of a . paging ret rofit . adapter . Movie Adapter Ċ import Ġid . must of a . paging ret rofit . data . Network State Ċ import Ġkotlinx . android . synt hetic . main . activity _ main .* Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĊĠ Ġprivate Ġvar Ġhas Data Ġ= Ġfalse ĊĠ Ġprivate Ġval ĠviewModel : ĠMain ViewModel Ġby Ġview Models Ġ{ ĊĠĠĠ Ġobject Ġ: ĠViewModel Provider . Factory Ġ{ ĊĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel ?> Ġcreate ( model Class : ĠClass < T >): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠMain ViewModel () Ġas ĠT ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠ Ġsetup List () ĊĠĠĠ Ġsetup Refresh er () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup List () Ġ{ ĊĠĠĠ Ġval Ġadapter Ġ= ĠMovie Adapter Ġ{ ĠviewModel . retry () Ġ} ĊĠĠĠ Ġmain List . layout Manager Ġ= ĠLinearLayoutManager ( this ) ĊĠĠĠ Ġmain List . adapter Ġ= Ġadapter ĊĠĠĠ ĠviewModel . network State . observe ( this , ĠObserver Ġ{ Ġadapter . set Network State ( it ) Ġ}) ĊĠĠĠ ĠviewModel . movies . observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠ Ġadapter . submit List ( it ) ĊĠĠĠĠĠ Ġhas Data Ġ= Ġ! it . isNull OrEmpty () ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Refresh er () Ġ{ ĊĠĠĠ Ġmain Container . setOn Refresh Listener Ġ{ ĠviewModel . refresh () Ġ} ĊĠĠĠ ĠviewModel . refresh State . observe ( this , ĠObserver Ġ{ ĊĠĠĠĠĠ Ġmain Container . is Refresh ing Ġ= Ġit Ġ== ĠNetwork State . LOADING Ġ&& Ġhas Data ĊĠĠĠ Ġ}) ĊĠ Ġ} Ċ } Ċ