package Ġcom . v ish al ga ur . shopping app . ui . home Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . v ish al ga ur . shopping app . R Ċ import Ġcom . v ish al ga ur . shopping app . data . UserData Ċ import Ġcom . v ish al ga ur . shopping app . databinding . Layout Order Summary Card Binding Ċ import Ġjava . time . Month Ċ import Ġjava . util .* Ċ Ċ class ĠOrders Adapter ( orders List : ĠList < UserData . Order Item >, Ġprivate Ġval Ġcontext : ĠContext ) Ġ: Ċ ĉ RecyclerView . Adapter < Orders Adapter . ViewHolder >() Ġ{ ĊĊ ĉ late init Ġvar ĠonClick Listener : ĠOn ClickListener Ċ ĉ var Ġdata : ĠList < UserData . Order Item > Ġ= Ġorders List ĊĊ ĉ inner Ġclass ĠViewHolder ( private Ġval Ġbinding : ĠLayout Order Summary Card Binding ) Ġ: Ċĉ ĉ RecyclerView . ViewHolder ( binding . root ) Ġ{ Ċĉ ĉ fun Ġbind ( order Data : ĠUser Data . Order Item ) Ġ{ Ċĉĉ ĉ binding . order Summary Card . setOnClickListener Ġ{ ĠonClick Listener . on Card Click ( order Data . orderId ) Ġ} Ċĉĉ ĉ binding . order Summary Id Tv . text Ġ= Ġorder Data . orderId Ċĉĉ ĉ val Ġcalendar Ġ= ĠCalendar . getInstance () Ċĉĉ ĉ calendar . time Ġ= Ġorder Data . order Date Ċĉĉ ĉ binding . order Summary Date Tv . text Ġ= Ċĉĉĉ ĉ context . getString ( Ċĉĉĉĉ ĉ R . string . order _ date _ text , Ċĉĉĉĉ ĉ Month . values ()[ ( calendar . get ( Calendar . MONTH )) ]. name , Ċĉĉĉĉ ĉ calendar . get ( Calendar . DAY _ OF _ MONTH ). toString (), Ċĉĉĉĉ ĉ calendar . get ( Calendar . YEAR ). toString () Ċĉĉĉ ĉ ) Ċĉĉ ĉ binding . order Summary Status Value Tv . text Ġ= Ġorder Data . status Ċĉĉ ĉ val Ġtotal Items Ġ= Ġorder Data . items . map Ġ{ Ġit . quantity Ġ}. sum () Ċĉĉ ĉ binding . order Summary Items Count Tv . text Ġ= Ċĉĉĉ ĉ context . getString ( R . string . order _ items _ count _ text , Ġtotal Items . toString ()) Ċĉĉ ĉ var Ġtotal Amount Ġ= Ġ 0 . 0 Ċĉĉ ĉ order Data . items Prices . forEach Ġ{ Ġ( itemId , Ġprice ) Ġ-> Ċĉĉĉ ĉ total Amount Ġ+= Ġprice Ġ* Ġ( order Data . items . find Ġ{ Ġit . itemId Ġ== ĠitemId Ġ} ?. quantity Ġ?: Ġ 1 ) Ċĉĉ ĉ } Ċĉĉ ĉ binding . order Summary Total Amount Tv . text Ġ= Ċĉĉĉ ĉ context . getString ( R . string . price _ text , Ġtotal Amount . toString ()) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠViewHolder Ġ{ Ċĉ ĉ return ĠViewHolder ( Ċĉĉ ĉ Layout Order Summary Card Binding . inflate ( Ċĉĉĉ ĉ LayoutInflater . from ( parent . context ), Ċĉĉĉ ĉ parent , Ċĉĉĉ ĉ false Ċĉĉ ĉ ) Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Bind ViewHolder ( holder : ĠViewHolder , Ġposition : ĠInt ) Ġ{ Ċĉ ĉ holder . bind ( data [ position ]) Ċ ĉ } ĊĊ ĉ override Ġfun ĠgetItem Count () Ġ= Ġdata . size ĊĊ ĉ interface ĠOn ClickListener Ġ{ Ċĉ ĉ fun Ġon Card Click ( orderId : ĠString ) Ċ ĉ } Ċ }