package Ġcom . all sof td roid . feature . book _ details . presentation . re cyclerView . adapter Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . Diff Util Ċ import Ġandroidx . recyclerview . widget . ListAdapter Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . all sof td roid . common . base . store . downloader . Download Event Store Ċ import Ġcom . all sof td roid . feature . book _ details . domain . model . Audio Book Track Domain Model Ċ import Ġcom . all sof td roid . feature . book _ details . presentation . re cyclerView . views . Track Item ViewHolder Ċ import Ġcom . all sof td roid . feature . book _ details . utils . Download Status Event Ċ Ċ /** Ċ Ġ* ĠRe cycler ĠAdapter Ġuses Ġefficient Ġway Ġto Ġfind Ġthe Ġchange Ġin Ġthe Ġlist Ġitem . Ċ Ġ* ĠIt Ġuses ĠDiff Utils Ġfor Ġefficient Ġmanagement Ġof Ġthe Ġre cycler Ġview Ġlist Ġitem Ċ Ġ*/ Ċ Ċ class ĠAudio Book Track Adapter ( ĊĠĠĠ Ġprivate Ġval Ġdownload Event Store : ĠDownload Event Store , ĊĠĠĠ Ġprivate Ġval Ġbook Id : String , ĊĠĠĠ Ġprivate Ġval Ġclicked Listener : ĠTrack Item Clicked Listener , ĊĠĠĠ Ġprivate Ġval Ġprogress bar Item Clicked Listener : ĠProgress bar Item Clicked Listener , ĊĠĠĠ Ġprivate Ġval Ġdownload Item Clicked Listener : ĠDownload Item Clicked Listener ): ĠList Adapter < Audio Book Track Domain Model , ĠRecyclerView . ViewHolder >( Track Diff Callback ()) Ġ{ ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠCreate Ġview ĠH older Ġof Ġtype ĠBook ViewHolder ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠRecyclerView . ViewHolder Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠTrack Item ViewHolder . from ( parent ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠBind Ġthe ĠViewHolder Ġwith Ġthe Ġdata Ġitem ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠRecyclerView . ViewHolder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen ( holder ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠTrack Item ViewHolder Ġ-> { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġdata Item Ġ= ĠgetItem ( position ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġholder . bind ( download Event Store , book Id , data Item , clicked Listener , progressbar Item Clicked Listener , download Item Clicked Listener ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠException (" View ĠH older Ġtype Ġis Ġunknown :$ holder ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } ĊĊĊĊ Ċ /** Ċ class Ġto Ġsmart ly Ġcheck Ġfor Ġdifference Ġin Ġnew Ġloaded Ġlist Ġand Ġold Ġlist Ċ It Ġenhance Ġthe Ġperformance Ġof Ġthe Ġre cycler Ġview Ċ Ġ*/ Ċ class ĠTrack Diff Callback Ġ: ĠDiff Util . Item Callback < Audio Book Track Domain Model > (){ ĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠCompare Ġitems Ġbased Ġon Ġname Ġfield Ġas Ġit Ġis Ġunique Ġamong Ġtrack ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġoverride Ġfun Ġare Items The Same ( old Item : ĠAudio Book Track Domain Model , Ġnew Item : ĠAudio Book Track Domain Model ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġold Item . filename == new Item . filename Ġ&& Ġold Item . is Playing Ġ!= Ġnew Item . is Playing Ġ&& Ġold Item . download Status Ġ== Ġnew Item . download Status ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠCheck Ġevery Ġfields Ġto Ġverify Ġfor Ġsame Ġcontent . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Suppress Lint (" Diff Util Equals ") ĊĠĠĠ Ġoverride Ġfun Ġare Contents The Same ( old Item : ĠAudio Book Track Domain Model , Ġnew Item : ĠAudio Book Track Domain Model ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġ/* ĊĠĠĠĠĠĠĠ ĠSince Ġbook Ġis Ġdata Ġclass Ġso Ġhere Ġall Ġthe Ġfields Ġare Ġautomatically Ġchecked ĊĠĠĠĠĠĠĠĠ Ġ*/ ĊĠĠĠĠĠĠĠ Ġreturn Ġold Item Ġ== Ġnew Item ĊĠĠĠ Ġ} Ċ } ĊĊ Ċ /* Ċ listener Ġto Ġcheck Ġfor Ġthe Ġclick Ġevent Ċ Ġ*/ Ċ class ĠTrack Item Clicked Listener ( val Ġclick Listener Ġ: Ġ( track Number Ġ: ĠInt ?, filename : String , track Title : String ? )-> Unit ){ ĊĠĠĠ Ġfun Ġon Track Item Clicked ( track Ġ: ĠAudio Book Track Domain Model ) Ġ= Ġclick Listener ( track . track Number , track . filename , track . title ) Ċ } Ċ Ċ /** Ċ Ġ* ĠDownload Ġbutton Ġlistener Ċ Ġ*/ Ċ class ĠDownload Item Clicked Listener ( val Ġclick Listener Ġ: Ġ( track Id Ġ: ĠString , download Status : ĠDownload Status Event )-> Unit ){ ĊĠĠĠ Ġfun Ġon Download Item Clicked ( track Ġ: ĠAudio Book Track Domain Model ) Ġ= Ġclick Listener ( track . track Id , track . download Status ) Ċ } Ċ Ċ /** Ċ Ġ* ĠCancel Ġrunning Ġdownload Ġlistener Ċ Ġ*/ Ċ class ĠProgress bar Item Clicked Listener ( val Ġclick Listener Ġ: Ġ( track Id Ġ: ĠString )-> Unit ){ ĊĠĠĠ Ġfun Ġon Progress bar Item Clicked ( track Ġ: ĠAudio Book Track Domain Model ) Ġ= Ġclick Listener ( track . track Id ) Ċ }