package Ġcom . example . android . polit ical prepared ness . represent ative . 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 . Item Represent ative Binding Ċ import Ġcom . example . android . polit ical prepared ness . represent ative . adapter . Represent ative ListAdapter . ViewHolder Ċ import Ġcom . example . android . polit ical prepared ness . represent ative . model . Represent ative Ċ Ċ class ĠRepresent ative ListAdapter ( private Ġval Ġlistener : ĠListener ): ĠList Adapter < Represent ative , ĠViewHolder >( Diff Callback ) Ġ{ ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ) Ġ= ĠViewHolder . from ( parent ) ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠViewHolder , Ġposition : ĠInt ) Ġ= Ġholder . bind ( getItem ( position ), Ġlistener ) ĊĊĠĠĠ Ġinterface ĠListener Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġon Web Click ( item : ĠRepresent ative ) ĊĠĠĠĠĠĠĠ Ġfun Ġon Facebook Click ( item : ĠRepresent ative ) ĊĠĠĠĠĠĠĠ Ġfun Ġon Twitter Click ( item : ĠRepresent ative ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠViewHolder ( private Ġval Ġbinding : ĠItem Represent ative Binding ): ĠRecyclerView . ViewHolder ( binding . root ) Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġbind ( item : ĠRepresent ative , Ġlistener : ĠListener ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . represent ative Ġ= Ġitem ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . web Image . setOnClickListener Ġ{ Ġlistener . on Web Click ( item ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . facebook Image . setOnClickListener Ġ{ Ġlistener . on Facebook Click ( item ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbinding . twitter Image . setOnClickListener Ġ{ Ġlistener . on Twitter Click ( item ) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfun Ġfrom ( parent : ĠViewGroup ) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠViewHolder ( Item Represent ative Binding . inflate ( LayoutInflater . from ( parent . context ), Ġparent , Ġfalse )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject ĠDiff Callback Ġ: ĠDiff Util . Item Callback < Represent ative >() Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġare Items The Same ( old Item : ĠRepresent ative , Ġnew Item : ĠRepresent ative ) Ġ= Ġold Item . official . name Ġ== Ġnew Item . official . name ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġare Contents The Same ( old Item : ĠRepresent ative , Ġnew Item : ĠRepresent ative ) Ġ= Ġold Item Ġ== Ġnew Item ĊĊĠĠĠ Ġ} Ċ Ċ } Ċ