package Ġcom . yt . grad uation . UI . Homepage Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view .* Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Grid LayoutManager Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġandroidx . swiper ef resh layout . widget . Swipe Refresh Layout Ċ import Ġcom . google . firebase . auth . Firebase Auth Ċ import Ġcom . yt . grad uation . R Ċ import Ġcom . yt . grad uation . UI . Adapters . All Products Adapter Ċ import Ġcom . yt . grad uation . databinding . Fragment All Products Binding Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . launch ĊĊ Ċ class ĠAll Products Fragment Ġ: ĠFragment (), ĠSw ipe Refresh Layout . On Refresh Listener { ĊĠĠĠ Ġprivate Ġvar Ġ_ binding : ĠFragment All Products Binding ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval Ġbinding Ġget () Ġ= Ġ_ binding !! ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġre cyclerView Ġ: ĠRecyclerView ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠAll Products ViewModel ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠviewModel ĠĠ Ġ= ĠViewModel Provider ( this ). get ( All Products ViewModel :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ binding Ġ= ĠFragment All Products Binding . inflate ( in flater , Ġcontainer , Ġfalse ) ĊĊĠĠĠĠĠĠĠ Ġre cyclerView Ġ= Ġbinding . Homepage RecyclerView ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= ĠGrid LayoutManager ( context , 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= Ġ ĠAll Products Adapter ( ArrayList ()) ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ ĠviewModel . product List . observe ( view Lifecycle Owner ){ Ġproducts Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . Main Ġ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproducts . let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġadapter . refresh Data ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠviewModel . sign Status . observe ( view Lifecycle Owner ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ(! it ) Ġfind Nav Controller (). navigate ( R . id . login Fragment ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġbinding . root ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġbinding . swipe Refresh . setOn Refresh Listener ( this ) ĊĠĠĠĠĠĠĠ Ġbinding . swipe Refresh . setColor Scheme Resources ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . color . primary Color , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġandroid . R . color . holo _ green _ dark , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġandroid . R . color . holo _ orange _ dark , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġandroid . R . color . holo _ blue _ dark ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĠĠĠĠĠĠĠ ĠviewModel . refresh Products () ĊĠĠĠĠĠĠĠ ĠviewModel . is Signed () ĊĠĠĠ Ġ} ĊĠĠĠ Ġoverride Ġfun Ġon Refresh () Ġ{ ĊĠĠĠĠĠĠ ĠviewModel . refresh Products () ĊĠĠĠĠĠĠĠ Ġbinding . swipe Refresh . is Refresh ing Ġ= Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠĠĠĠĠ Ġ_ binding Ġ= Ġnull ĊĠĠĠ Ġ} Ċ Ċ } ĊĊ