package Ġgr ack . dev . mov ied agger . ui . movie . catalog ue Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . lifecycle . ViewModel Providers Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġcom . google . gson . Gson Ċ import Ġcom . jak ew h art on . r xb ind ing 3 . view . click s Ċ import Ġdagger . android . support . Android Support Injection Ċ import Ġgr ack . dev . mov ied agger . App Constant Ċ import Ġgr ack . dev . mov ied agger . App Constant . DURATION _ TH RO TT LE Ċ import Ġgr ack . dev . mov ied agger . App Constant . INT ENT _ KEY _ HEADER Ċ import Ġgr ack . dev . mov ied agger . R Ċ import Ġgr ack . dev . mov ied agger . data . repository . models . general . Movies Ċ import Ġgr ack . dev . mov ied agger . data . repository . models . general . Result Ċ import Ġgr ack . dev . mov ied agger . databinding . Fragment Catalog ue Binding Ċ import Ġgr ack . dev . mov ied agger . ui . detail . Detail Activity Ċ import Ġgr ack . dev . mov ied agger . ui . movie . catalog ue . model . Child Ċ import Ġgr ack . dev . mov ied agger . ui . movie . catalog ue . model . Section Item Ċ import Ġgr ack . dev . mov ied agger . ui . movie . more . More Activity Ċ import Ġgr ack . dev . mov ied agger . ui . movie . search . Search Activity Ċ import Ġgr ack . dev . mov ied agger . utils . ClickListener Ċ import Ġgr ack . dev . mov ied agger . utils . Margin Item Decoration Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠCatalog ue Fragment ( private Ġvar Ġmovies : ĠMov ies ) Ġ: ĠFragment () Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġinternal Ġlateinit Ġvar ĠviewModel Factory : ĠViewModel Provider . Factory ĊĠ Ġprivate Ġlateinit Ġvar Ġbinding : ĠFragment Catalog ue Binding ĊĠ Ġprivate Ġlateinit Ġvar Ġcatalog ue Adapter : ĠCatalog ue Adapter ĊĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠCatalog ue ViewModel ĊĊĠ Ġprivate Ġvar Ġchild Ġ= ĠArrayList < Child >() ĊĠ Ġprivate Ġval Ġsection Ġ= ĠArrayList < Section Item >() ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠAndroid Support Injection . inject ( this ) ĊĠ Ġ} ĊĊĠ Ġ@ Suppress Lint (" Check Result ") ĊĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠ Ġ): ĠView ? Ġ{ ĊĊĠĠĠ ĠviewModel Ġ= ĠViewModel Providers . of ( this , ĠviewModel Factory ). get ( Catalog ue ViewModel :: class . java ) ĊĠĠĠ Ġbinding Ġ= ĠData Binding Util . inflate ( ĊĠĠĠĠĠ Ġinflater , ĠR . layout . fragment _ catalog ue , Ġcontainer , Ġfalse ĊĠĠĠ Ġ) ĊĠĠĠ Ġbinding . viewModel Ġ= ĠviewModel ĊĠĠĠ Ġbinding . lifecycle Owner Ġ= Ġthis ĊĊĠĠĠ Ġpopulate Movie () ĊĊĠĠĠ Ġcatalog ue Adapter Ġ= ĠCatalog ue Adapter ( activity , Ġsection , Ġobject Ġ: ĠClick Listener < Result > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġon Item Click ( t : ĠResult ?) Ġ{ ĊĠĠĠĠĠĠĠ ĠstartActivity Detail ( t ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}, Ġobject Ġ: ĠClick Listener < String > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġon Item Click ( t : ĠString ?) Ġ{ ĊĠĠĠĠĠĠĠ ĠstartActivity More ( t , Ġmovies ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ Ġbinding . recycler Catalog ue . adapter Ġ= Ġcatalog ue Adapter ĊĠĠĠ Ġbinding . recycler Catalog ue . layout Manager Ġ= ĠLinearLayoutManager ( context ) ĊĠĠĠ Ġbinding . recycler Catalog ue . addItem Decoration ( Margin Item Decoration ( 1 6 )) ĊĊĠĠĠ Ġcatalog ue Adapter . notify DataSet Changed () ĊĊĠĠĠ Ġbinding . button Search . click s () ĊĠĠĠĠĠ Ġ. throttle First ( DURATION _ TH RO TT LE , ĠTimeUnit . MILLISECONDS ) ĊĠĠĠĠĠ Ġ. subscribe Ġ{ ĊĠĠĠĠĠĠĠ ĠstartActivity ( Intent ( activity , ĠSearch Activity :: class . java )) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġbinding . root ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġpopulate Movie () Ġ{ ĊĠĠĠ Ġmovies . now Playing . forEach Indexed Ġ{ Ġindex , Ġresult Ġ-> ĊĠĠĠĠĠ Ġif Ġ( index Ġ<= Ġ 4 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġchild . add ( Child ( result )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġsection . add ( Section Item ( resources . getString ( R . string . movie _ caption _ now _ playing ), Ġchild )) ĊĊĠĠĠ Ġchild Ġ= ĠArrayList () ĊĠĠĠ Ġmovies . top R ated . forEach Indexed Ġ{ Ġindex , Ġresult Ġ-> ĊĠĠĠĠĠ Ġif Ġ( index Ġ<= Ġ 4 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġchild . add ( Child ( result )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġsection . add ( Section Item ( resources . getString ( R . string . movie _ caption _ top _ r ated ), Ġchild )) ĊĊĠĠĠ Ġchild Ġ= ĠArrayList () ĊĠĠĠ Ġmovies . popular . forEach Indexed Ġ{ Ġindex , Ġresult Ġ-> ĊĠĠĠĠĠ Ġif Ġ( index Ġ<= Ġ 4 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġchild . add ( Child ( result )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġsection . add ( Section Item ( resources . getString ( R . string . movie _ caption _ popular ), Ġchild )) ĊĊĠĠĠ Ġchild Ġ= ĠArrayList () ĊĠĠĠ Ġmovies . up coming . forEach Indexed Ġ{ Ġindex , Ġresult Ġ-> ĊĠĠĠĠĠ Ġif Ġ( index Ġ<= Ġ 4 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġchild . add ( Child ( result )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġsection . add ( Section Item ( resources . getString ( R . string . movie _ caption _ up coming ), Ġchild )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠstartActivity More ( header : ĠString ?, Ġmovies : ĠMov ies ) Ġ{ ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( activity , ĠMore Activity :: class . java ) ĊĠĠĠ Ġintent . putExtra ( App Constant . INT ENT _ KEY , ĠGson (). toJson ( movies )) ĊĠĠĠ Ġintent . putExtra ( INT ENT _ KEY _ HEADER , Ġheader ) ĊĠĠĠ ĠstartActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠstartActivity Detail ( data : ĠResult ?) Ġ{ ĊĠĠĠ Ġval Ġbundle Ġ= ĠBundle () ĊĠĠĠ Ġbundle . putString ( App Constant . INT ENT _ KEY , ĠGson (). toJson ( data )) ĊĠĠĠ Ġval Ġdetail Activity Ġ= ĠDetail Activity () ĊĠĠĠ Ġdetail Activity . arguments Ġ= Ġbundle ĊĠĠĠ Ġdetail Activity . is Cancel able Ġ= Ġfalse ĊĠĠĠ Ġdetail Activity . show ( activity !!. support FragmentManager , Ġdetail Activity . tag ) ĊĠ Ġ} Ċ Ċ } Ċ