package Ġcom . yt . grad uation . UI . Account Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . recyclerview . widget . Grid LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . yt . grad uation . UI . Adapters . On Sale Products Adapter Ċ import Ġcom . yt . grad uation . databinding . Fragment On Sale Products Binding Ċ import Ġcom . yt . grad uation . model . Product ĊĊ Ċ class ĠOn Sale Products Fragment Ġ: ĠFragment () Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġ_ binding : ĠFragment On Sale Products Binding ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval Ġbinding Ġget () Ġ= Ġ_ binding !! ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġre cyclerView Ġ: ĠRecyclerView ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠOn Sale Products ViewModel ĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠviewModel ĠĠ Ġ= ĠViewModel Provider ( this ). get ( On Sale Products ViewModel :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ binding Ġ= ĠFragment On Sale Products Binding . inflate ( in flater , Ġcontainer , Ġfalse ) ĊĊĠĠĠĠĠĠĠ Ġre cyclerView Ġ= Ġbinding . On Sale RecyclerView ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= ĠGrid LayoutManager ( context , 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= ĠOn Sale Products Adapter ( ArrayList < Product >(), viewModel ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ ĠviewModel . product List . observe ( view Lifecycle Owner ){ Ġproducts Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . refresh Data ( products ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġ// ĠInf late Ġthe Ġlayout Ġfor Ġthis Ġfragment ĊĠĠĠĠĠĠĠ Ġreturn Ġbinding . root ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ ĠviewModel . refresh Products () ĊĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠĠĠĠĠ Ġ_ binding Ġ= Ġnull ĊĠĠĠ Ġ} Ċ Ċ }