package Ġcom . myapp . med led . adapters . recycler _ view Ċ Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . myapp . med led . R Ċ import Ġcom . myapp . med led . adapters . recycler _ view . view _ holders . Messages RecyclerView Holder Receiver Ċ import Ġcom . myapp . med led . adapters . recycler _ view . view _ holders . Messages RecyclerView Holder Sender Ċ import Ġcom . myapp . med led . models . Message Ċ Ċ class ĠMessages RecyclerView Adapter ( private Ġval Ġcurrent UserId : ĠString , Ġprivate Ġval Ġmessages List : ArrayList < Message >) Ġ: ĠRecyclerView . Adapter < RecyclerView . ViewHolder > (){ ĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠRecyclerView . ViewHolder Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġif ( view Type == 0 ) ĠMessages RecyclerView Holder Sender ( LayoutInflater . from ( parent . context ). inflate ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . layout . sender _ mes age _ card , parent , false )) ĊĠĠĠĠĠĠĠ Ġelse Ġ ĠMessages RecyclerView Holder Receiver ( LayoutInflater . from ( parent . context ). inflate ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . layout . receiver _ mes age _ card , parent , false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġmessages List . size ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠRecyclerView . ViewHolder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmessages List [ holder . adapter Position ] ĊĠĠĠĠĠĠĠ Ġif ( message . sender Id Ġ== Ġcurrent UserId ) Ġ( holder Ġas ĠMessages RecyclerView Holder Sender ). send Text . text Ġ= Ġmessage . content ĊĠĠĠĠĠĠĠ Ġelse Ġ( holder Ġas ĠMessages RecyclerView Holder Receiver ). receiver Text . text Ġ= Ġmessage . content ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetItem ViewType ( position : ĠInt ): ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġif ( current UserId Ġ== Ġmessages List [ position ]. sender Id ) Ġ 0 Ġelse Ġ 1 ĊĠĠĠ Ġ} Ċ }