package Ġcom . v ish al ga ur . shopping app . ui . home Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . core . os . bundle Of Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . activity ViewModels Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġcom . v ish al ga ur . shopping app . R Ċ import Ġcom . v ish al ga ur . shopping app . data . utils . Store Data Status Ċ import Ġcom . v ish al ga ur . shopping app . databinding . Fragment Orders Binding Ċ import Ġcom . v ish al ga ur . shopping app . view Models . Home ViewModel Ċ Ċ private Ġconst Ġval ĠTAG Ġ= Ġ" Orders Fragment " Ċ Ċ class ĠOrders Fragment Ġ: ĠFragment () Ġ{ ĊĊ ĉ private Ġlateinit Ġvar Ġbinding : ĠFragment Orders Binding Ċ ĉ private Ġlateinit Ġvar Ġorders Adapter : ĠOrders Adapter Ċ ĉ private Ġval ĠviewModel : ĠHome ViewModel Ġby Ġactivity ViewModels () ĊĊ ĉ override Ġfun ĠonCreate View ( Ċĉ ĉ in flater : ĠLayoutInflater , Ċĉ ĉ container : ĠViewGroup ?, Ċĉ ĉ savedInstanceState : ĠBundle ? Ċ ĉ ): ĠView ? Ġ{ Ċĉ ĉ binding Ġ= ĠFragment Orders Binding . inflate ( layout Inflater ) ĊĊĉ ĉ set Views () Ċĉ ĉ set Observer s () ĊĊĉ ĉ return Ġbinding . root Ċ ĉ } ĊĊ ĉ override Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . on View Created ( view , ĠsavedInstanceState ) Ċĉ ĉ viewModel . getAll Orders () Ċ ĉ } ĊĊ ĉ private Ġfun Ġset Views () Ġ{ Ċĉ ĉ binding . loader Layout . loader Frame Layout . visibility Ġ= ĠView . GONE Ċĉ ĉ binding . orders AppBar . top AppBar . title Ġ= ĠgetString ( R . string . orders _ fragment _ title ) Ċĉ ĉ binding . orders AppBar . top AppBar . set Navigation OnClickListener Ġ{ Ċĉĉ ĉ find Nav Controller (). navigate Up () Ċĉ ĉ } Ċĉ ĉ binding . orders Empty TextView . visibility Ġ= ĠView . GONE Ċĉ ĉ if Ġ( context Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ orders Adapter Ġ= ĠOrders Adapter ( emptyList (), Ġrequire Context ()) Ċĉĉ ĉ orders Adapter . on ClickListener Ġ= Ġobject Ġ: ĠOrders Adapter . OnClickListener Ġ{ Ċĉĉĉ ĉ override Ġfun Ġon Card Click ( orderId : ĠString ) Ġ{ Ċĉĉĉĉ ĉ Log . d ( TAG , Ġ" on Order Summary Click : ĠGetting Ġorder Ġdetails ") Ċĉĉĉĉ ĉ find Nav Controller (). navigate ( Ċĉĉĉĉĉ ĉ R . id . action _ orders Fragment _ to _ order Details Fragment , Ċĉĉĉĉĉ ĉ bundle Of (" orderId " Ġto ĠorderId ) Ċĉĉĉĉ ĉ ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉĉ ĉ binding . order All Orders RecyclerView . adapter Ġ= Ġorders Adapter Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġset Observer s () Ġ{ Ċĉ ĉ viewModel . store Data Status . observe ( view Lifecycle Owner ) Ġ{ Ġstatus Ġ-> Ċĉĉ ĉ when Ġ( status ) Ġ{ Ċĉĉĉ ĉ Store Data Status . LOADING Ġ-> Ġ{ Ċĉĉĉĉ ĉ binding . order All Orders RecyclerView . visibility Ġ= ĠView . GONE Ċĉĉĉĉ ĉ binding . orders Empty TextView . visibility Ġ= ĠView . GONE Ċĉĉĉĉ ĉ binding . loader Layout . loader Frame Layout . visibility Ġ= ĠView . VISIBLE Ċĉĉĉĉ ĉ binding . loader Layout . circular Loader . show Animation Behavior Ċĉĉĉ ĉ } Ċĉĉĉ ĉ else Ġ-> Ġ{ Ċĉĉĉĉ ĉ binding . loader Layout . circular Loader . hide Animation Behavior Ċĉĉĉĉ ĉ binding . loader Layout . loader Frame Layout . visibility Ġ= ĠView . GONE Ċĉĉĉ ĉ } Ċĉĉ ĉ } ĊĊĉĉ ĉ if Ġ( status Ġ!= Ġnull Ġ&& Ġstatus Ġ!= ĠStore Data Status . LOADING ) Ġ{ Ċĉĉĉ ĉ viewModel . user Orders . observe ( view Lifecycle Owner ) Ġ{ Ġorders Ġ-> Ċĉĉĉĉ ĉ if Ġ( orders . isNotEmpty ()) Ġ{ Ċĉĉĉĉĉ ĉ orders Adapter . data Ġ= Ġorders . sorted By Descending Ġ{ Ġit . order Date Ġ} Ċĉĉĉĉĉ ĉ binding . order All Orders RecyclerView . adapter ?. notify DataSet Changed () Ċĉĉĉĉĉ ĉ binding . order All Orders RecyclerView . visibility Ġ= ĠView . VISIBLE Ċĉĉĉĉ ĉ } Ġelse Ġif Ġ( orders . isEmpty ()) Ġ{ Ċĉĉĉĉĉ ĉ binding . loader Layout . circular Loader . hide Animation Behavior Ċĉĉĉĉĉ ĉ binding . loader Layout . loader Frame Layout . visibility Ġ= ĠView . GONE Ċĉĉĉĉĉ ĉ binding . orders Empty TextView . visibility Ġ= ĠView . VISIBLE Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } Ċ }