package Ġcom . example . android . polit ical prepared ness . election Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ 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 Ġcom . example . android . polit ical prepared ness . R Ċ import Ġcom . example . android . polit ical prepared ness . databinding . Fragment E lection Binding Ċ import Ġcom . example . android . polit ical prepared ness . election . adapter . E lection ListAdapter Ċ import Ġcom . example . android . polit ical prepared ness . election . adapter . E lection Listener Ċ Ċ class ĠE lection s Fragment : ĠFragment () Ġ{ ĊĊĠĠĠ Ġ// ĠDeclare ĠViewModel ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġelection s ViewModel : ĠE lection s ViewModel ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġupcoming E lection s ListAdapter : ĠE lection ListAdapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsaved E lection s ListAdapter : ĠE lection ListAdapter ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfragment E lection Binding : ĠFragment E lection Binding ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// ĠAdd Ġbinding Ġvalues ĊĠĠĠĠĠĠĠ Ġfragment E lection Binding Ġ= ĠData Binding Util . inflate ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinflater , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . layout . fragment _ election , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontainer , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfalse ) ĊĠĠĠĠĠĠĠ Ġfragment E lection Binding . lifecycle Owner Ġ= Ġthis ĊĊĠĠĠĠĠĠĠ Ġ// ĠAdd ĠViewModel Ġvalues Ġand Ġcreate ĠViewModel ĊĊĠĠĠĠĠĠĠ Ġval Ġelection s ViewModel Factory Ġ= ĠE lection s ViewModel Factory ( require Activity (). application ) ĊĠĠĠĠĠĠĠ Ġelection s ViewModel Ġ= ĠViewModel Provider ( this , Ġelection s ViewModel Factory ). get ( E lection s ViewModel :: class . java ) ĊĠĠĠĠĠĠĠ Ġfragment E lection Binding . viewModel Ġ= Ġelection s ViewModel ĊĊĊĊ ĊĠĠĠĠĠĠĠ Ġ// ĠLink Ġelection s Ġto Ġvot er Ġinfo ĊĠĠĠĠĠĠĠ Ġ// here Ġwe ĠOb serve Ġthe Ġnavigate To Detail E lection ĠLive Data Ġand ĠNavigate Ġwhen Ġit Ġis Ġnot Ġnull . ĊĊĠĠĠĠĠĠĠ Ġelection s ViewModel . up coming E lection s . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupcoming E lection s ListAdapter . submit List ( it ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġelection s ViewModel . saved E lection s . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsaved E lection s ListAdapter . submit List ( it ) ĊĊ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġ// ĠInit iate Ġre cycler Ġadapters ĊĊĠĠĠĠĠĠĠ Ġ// ĠPopulate Ġre cycler Ġadapters ĊĊĠĠĠĠĠĠĠ Ġupcoming E lection s ListAdapter Ġ= ĠE lection ListAdapter ( E lection Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfind Nav Controller (). navigate ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠE lection s Fragment Directions . action E lection s Fragment To V oter Info Fragment ( it . id , Ġit . division )) ĊĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠ Ġfragment E lection Binding . up coming E lection s Rv . adapter Ġ= Ġupcoming E lection s ListAdapter ĊĊĠĠĠĠĠĠĠ Ġ// ĠSetup ĠRe cycler ĠView Ġfor Ġsaved Ġelection s ĊĠĠĠĠĠĠĠ Ġsaved E lection s ListAdapter Ġ= ĠE lection ListAdapter ( E lection Listener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfind Nav Controller (). navigate ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠE lection s Fragment Directions . action E lection s Fragment To V oter Info Fragment ( it . id , Ġit . division )) ĊĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠ Ġfragment E lection Binding . saved E lection s Rv . adapter Ġ= Ġsaved E lection s ListAdapter ĊĊĠĠĠĠĠĠĠ Ġreturn Ġfragment E lection Binding . root ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġ// ĠRefresh Ġadapters Ġwhen Ġfragment Ġloads Ċ }