package Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . fragments Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . common . adapters . Base ListAdapter Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . common . base . Base Fragment Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . common . utils . li ved ata event . LiveData Event Observer Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . entities . Car Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . entities . Make Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . BR Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . Inventory Activity Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . Inventory ViewModel Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . R Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . databinding . Car ListItem Binding Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . databinding . C ars Fragment Binding Ċ import Ġcom . inion gun group . mobile . d roid . aut ocheck mobile . inventory . databinding . Make ListItem Binding Ċ Ċ class ĠC ars Fragment Ġ: ĠBase Fragment < C ars Fragment Binding , ĠInventory ViewModel >() Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġinventory ViewModel Ġby Ġlazy Ġ{ Ġ( require Activity () Ġas ĠInventory Activity ). inventory ViewModel Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġbinding : ĠC ars Fragment Binding ĊĊĠĠĠ Ġoverride Ġfun Ġget ViewModel () Ġ= Ġinventory ViewModel ĊĊĠĠĠ Ġoverride Ġfun Ġget Layout Id () Ġ= ĠR . layout . cars _ fragment ĊĊĠĠĠ Ġoverride Ġfun Ġget Binding Variable () Ġ= ĠBR . viewModel ĊĊĠĠĠ Ġoverride Ġfun Ġget Layout Binding ( binding : ĠC ars Fragment Binding ) Ġ{ Ġthis . binding Ġ= Ġbinding Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġmakes Adapter Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ Ġobject Ġ: ĠBase ListAdapter < Make ListItem Binding , ĠMake >( inventory ViewModel , ĠR . layout . make _ list _ item ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Entity Binding Variable () Ġ= ĠBR . make ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget ViewModel Binding Variable () Ġ= ĠBR . viewModel ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġcars Adapter Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ Ġobject Ġ: ĠBase ListAdapter < Car ListItem Binding , ĠCar >( inventory ViewModel , ĠR . layout . car _ list _ item ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Entity Binding Variable () Ġ= ĠBR . car ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget ViewModel Binding Variable () Ġ= ĠBR . viewModel ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġsetup C ars And M akes Recycler Views () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsetup C ars And M akes Recycler Views () Ġ{ ĊĠĠĠĠĠĠĠ Ġwith ( binding ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmakes RecyclerView . adapter Ġ= Ġmakes Adapter ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcars RecyclerView . add On Scroll Listener ( object Ġ: ĠRecyclerView . On Scroll Listener () Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Scroll StateChanged ( re cyclerView : ĠRecyclerView , ĠnewState : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsuper . on Scroll StateChanged ( re cyclerView , ĠnewState ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ(! re cyclerView . can Scroll Vert ically ( 1 ) Ġ&& ĠnewState Ġ== ĠRecyclerView . SCROLL _ STATE _ IDLE ) Ġ{} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġ Ġinventory ViewModel . get More C ars () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcars RecyclerView . adapter Ġ= Ġcars Adapter ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġset ViewModel Observer s () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . set ViewModel Observer s () ĊĠĠĠĠĠĠĠ Ġobserve C ars And M akes () ĊĠĠĠĠĠĠĠ Ġobserve Show Car Details () ĊĠĠĠĠĠĠĠ Ġobserve C ars () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġobserve C ars And M akes () Ġ{ ĊĠĠĠĠĠĠĠ Ġinventory ViewModel . cars And M akes . observe ( this , Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmakes Adapter . submit List ( it . second ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcars Adapter . submit List ( it . first ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġobserve C ars () Ġ{ ĊĠĠĠĠĠĠĠ Ġinventory ViewModel . cars . observe ( this , Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcars Adapter . submit List ( it ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġobserve Show Car Details () Ġ{ ĊĠĠĠĠĠĠĠ Ġinventory ViewModel . show Car Details . observe ( this , ĠLive Data Event Observer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To ( C ars Fragment Directions . action C ars Fragment To Car Details Fragment ()) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Loading () Ġ{ Ġbinding . progress Bar . visibility Ġ= ĠView . VISIBLE Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġhide Loading () Ġ{ Ġbinding . progress Bar . visibility Ġ= ĠView . GONE Ġ} Ċ }