package Ġwork . cal mat o . pre stop ay . ui . group List Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . activity . On Back Pressed Callback Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġkotlinx . android . synt hetic . main . fragment _ home .* Ċ import Ġwork . cal mat o . pre stop ay . R Ċ import Ġwork . cal mat o . pre stop ay . databinding . Fragment Group List Binding Ċ import Ġwork . cal mat o . pre stop ay . network . Group Property Response Ċ import Ġwork . cal mat o . pre stop ay . util . Adapter Group Plane Ċ import Ġwork . cal mat o . pre stop ay . util . ViewModel Group Ċ Ċ class ĠGroup List Fragment Ġ: ĠFragment () Ġ{ ĊĠ Ġprivate Ġval ĠviewModel Group : ĠViewModel Group Ġby Ġlazy Ġ{ ĊĠĠĠ ĠViewModel Provider ( this ). get ( ViewModel Group :: class . java ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġvar Ġre cycle Group ListAdapter : ĠAdapter Group Plane ? Ġ= Ġnull ĊĠ Ġprivate Ġlateinit Ġvar Ġgroup List Arg : ĠList < Group Property Response > ĊĊĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠ Ġgroup List Arg Ġ= ĠGroup List Fragment Args . from Bundle ( require Arguments ()). groups List !!. groups ĊĠĠĠ Ġif Ġ( group List Arg . isEmpty ()) Ġ{ ĊĠĠĠĠĠ ĠviewModel Group . groups List . observe ( view Lifecycle Owner , ĠObserver < List < Group Property Response >> Ġ{ ĊĠĠĠĠĠĠĠ Ġit ?. apply Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġgroup List Arg Ġ= Ġit ĊĠĠĠĠĠĠĠĠĠ Ġre cycle Group ListAdapter ?. group List Ġ= Ġit ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġre cycle Group ListAdapter ?. group List Ġ= Ġgroup List Arg ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġlateinit Ġvar Ġclick Listener Home Group : ĠAdapter Group Plane . OnClickListener ĊĊĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠ Ġ): ĠView Ġ{ ĊĠĠĠ Ġval Ġbinding : ĠFragment Group List Binding Ġ= ĊĠĠĠĠĠ ĠData Binding Util . inflate ( in flater , ĠR . layout . fragment _ group _ list , Ġcontainer , Ġfalse ) ĊĊĠĠĠ Ġbinding . lifecycle Owner Ġ= Ġthis ĊĠĠĠ Ġbinding . viewModel Group List Ġ= ĠviewModel Group ĊĊĠĠĠ Ġclick Listener Home Group Ġ= ĊĠĠĠĠĠ ĠAdapter Group Plane . OnClickListener Ġ{ ĠviewModel Group . item Is Clicked Group ( it ) Ġ} ĊĠĠĠ Ġre cycle Group ListAdapter Ġ= ĠAdapter Group Plane ( click Listener Home Group , require Activity (), false ) ĊĠĠĠ Ġbinding . group Choice Re cycle . apply Ġ{ ĊĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( context ) ĊĠĠĠĠĠ Ġadapter Ġ= Ġre cycle Group ListAdapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġbinding . root ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠ ĠviewModel Group . groups List . observe ( view Lifecycle Owner , ĠObserver < List < Group Property Response >> Ġ{ ĊĠĠĠĠĠ Ġit ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġre cycle Group ListAdapter ?. group List Ġ= Ġit ĊĠĠĠĠĠĠĠ ĠviewModel Group . end Refresh ing () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ ĠviewModel Group . refresh ing . observe ( view Lifecycle Owner , ĠObserver < Boolean > Ġ{ ĊĠĠĠĠĠ Ġit ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġswipe Container . is Refresh ing Ġ= Ġit ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ Ġswipe Container . setOn Refresh Listener Ġ{ ĊĠĠĠĠĠ ĠviewModel Group . group ListView () ĊĠĠĠ Ġ} ĊĠĠĠ ĠviewModel Group . item Clicked Group . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠ Ġit ?. apply Ġ{ ĊĠĠĠĠĠĠĠ Ġnavigate ToAdd Expense ( it ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ Ġset Has Options Menu ( true ) ĊĠĠĠ Ġrequire Activity (). on Back Pressed Dispatcher . add Callback ( ĊĠĠĠĠĠ Ġview Lifecycle Owner , ĊĠĠĠĠĠ Ġobject Ġ: ĠOn Back Pressed Callback ( true ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġhandle On Back Pressed () Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġgo Back Home () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġgo Back Home () Ġ{ ĊĠĠĠ Ġthis . find Nav Controller (). navigate ( ĊĠĠĠĠĠ ĠGroup List Fragment Directions . action Group List Fragment To Home Fragment () ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġnavigate ToAdd Expense ( group : Group Property Response ){ ĊĠĠĠ Ġthis . find Nav Controller (). navigate ( ĊĠĠĠĠĠ ĠGroup List Fragment Directions . action Group List Fragment ToAdd Payment ( group , null ) ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ Ċ } Ċ