package Ġorg . wit . guild manager app . adapters Ċ Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġkotlinx . android . synt hetic . main . recycler _ view _ character . view .* Ċ import Ġorg . wit . guild manager app . R Ċ import Ġorg . wit . guild manager app . listeners . Character RecyclerView Listener Ċ import Ġorg . wit . guild manager app . models . Character Model Ċ Ċ class ĠCharacter Model Adapter Ġ: ĠRecyclerView . Adapter < Character Model Adapter . Character ViewModel >() Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġcharacters Ġ= Ġmutable ListOf < Character Model >() ĊĠĠĠ Ġvar Ġlistener : ĠCharacter RecyclerView Listener ? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ) Ġ= ĠCharacter ViewModel ( ĊĠĠĠĠĠĠĠ ĠLayoutInflater . from ( parent . context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. inflate ( R . layout . recycler _ view _ character , Ġparent , Ġfalse ) ĊĠĠĠ Ġ) ĊĊĊĠĠĠ Ġoverride Ġfun ĠgetItem Count () Ġ= Ġcharacters . size ĊĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠCharacter ViewModel , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġholder . view . text _ view _ name . text Ġ= Ġcharacters [ position ]. name ĊĠĠĠĠĠĠĠ Ġholder . view . text _ view _ race . text Ġ= Ġcharacters [ position ]. race ĊĠĠĠĠĠĠĠ Ġholder . view . text _ view _ class . text Ġ= Ġcharacters [ position ]. class Type ĊĊĠĠĠĠĠĠĠ Ġholder . view . edit _ character . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener ?. on RecyclerView Button Click ( it , Ġcharacters [ position ]) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġholder . view . delete _ character . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener ?. on RecyclerView Button Click ( it , Ġcharacters [ position ]) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġset Characters ( characters : ĠList < Character Model >) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . characters Ġ= Ġcharacters Ġas ĠMutable List < Character Model > ĊĠĠĠĠĠĠĠ Ġnotify DataSet Changed () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/* ĊĠĠĠ Ġfunction Ġthat Ġchecks Ġif Ġa Ġcharacter Ġis Ġalready Ġin Ġthe Ġlist Ġbefore Ġadding ĊĠĠĠ Ġchecks Ġif Ġchar Deleted Ġis Ġtrue Ġor Ġfalse Ġfor Ġdeleting Ġand Ġalso Ġchecks Ġwhich Ġindex Ġthe Ġcharacter ĊĠĠĠ Ġis Ġat Ġfor Ġediting . Ġnotify Dataset Ch aged Ġis Ġthen Ġcalled Ġso Ġthe Ġre cycler Ġview Ġupdates Ġand Ġdisplays ĊĠĠĠ Ġthe Ġchanges ĊĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġfun Ġadd Character ( character : ĠCharacter Model ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! characters . contains ( character )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacters . add ( character ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnotify DataSet Changed () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġindex Ġ= Ġcharacters . indexOf ( character ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( character . char Deleted ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcharacters . remove At ( index ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcharacters [ index ] Ġ= Ġcharacter ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġnotify DataSet Changed () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠCharacter ViewModel ( val Ġview : ĠView ) Ġ: ĠRecyclerView . ViewHolder ( view ) Ċ }