package Ġcom . example . android . polit ical prepared ness . election . adapter Ċ Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . Diff Util Ċ import Ġandroidx . recyclerview . widget . ListAdapter Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . example . android . polit ical prepared ness . databinding . E lection ItemList Binding Ċ // import Ġcom . example . android . polit ical prepared ness . databinding . View holder E lection Binding Ċ import Ġcom . example . android . polit ical prepared ness . network . models . E lection Ċ Ċ class ĠE lection ListAdapter ( private Ġval Ġclick Listener : ĠE lection Listener ): ĠList Adapter < E lection , ĠE lection ListAdapter . E lection ViewHolder >( E lection Diff Callback ()) Ġ{ ĊĠĠĠ Ġclass ĠE lection ViewHolder ( private Ġval Ġbinding : E lection ItemList Binding ): ĠRecyclerView . ViewHolder ( binding . root ){ ĊĠĠĠĠĠĠĠ Ġfun Ġbind ( election : ĠE lection , election Listener : ĠE lection Listener ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . election Ġ= Ġelection ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . election Listener Ġ= Ġelection Listener ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . execute Pending Bindings () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcompanion Ġobject { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfun Ġfrom ( parent : ĠViewGroup ): ĠE lection ViewHolder Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġlayout Inflater Ġ= ĠLayoutInflater . from ( parent . context ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbinding Ġ= ĠE lection ItemList Binding . inflate ( layout Inflater , Ġparent , Ġfalse ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠE lection ViewHolder ( binding ) ĊĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠE lection ViewHolder Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠE lection ViewHolder . from ( parent ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠE lection ViewHolder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġholder . bind ( getItem ( position ), click Listener ) ĊĠĠĠ Ġ} Ċ Ċ } ĊĊ Ċ class ĠE lection Diff Callback : Diff Util . Item Callback < E lection > (){ ĊĠĠĠ Ġoverride Ġfun Ġare Items The Same ( old Item : ĠE lection , Ġnew Item : ĠE lection ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġold Item . id Ġ== Ġnew Item . id ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġare Contents The Same ( old Item : ĠE lection , Ġnew Item : ĠE lection ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġold Item Ġ== Ġnew Item ĊĠĠĠ Ġ} Ċ Ċ } ĊĊ Ċ class ĠE lection Listener ( val Ġelection Listener :( election _ id : E lection )-> Unit ){ ĊĠĠĠ Ġfun ĠonClick ( election : ĠE lection ) Ġ{ election Listener ( election )} Ċ Ċ }