package Ġdemo . movie . app . ui . recycler . adapters Ċ Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . card view . widget . Card View Ċ import Ġandroidx . recyclerview . widget . Diff Util Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġdemo . movie . app . R Ċ import Ġdemo . movie . app . di . D agger App Component Ċ import Ġdemo . movie . app . model . dto . Cast Member Dto Ċ import Ġdemo . movie . app . ui . recycler . callbacks . Cast Diff Util Callback Ċ import Ġdemo . movie . app . util . image . Base Image Loader Ċ import Ġdemo . movie . app . util . image . Image Size Ċ import Ġkotlinx . android . extensions . Layout Container Ċ import Ġkotlinx . android . synt hetic . main . cast _ member _ card . view .* Ċ Ċ class ĠCast Adapter ( ĊĠĠĠ Ġprivate Ġval Ġon ItemClickListener : Ġ( Cast Member Dto ) Ġ-> ĠUnit , ĊĠĠĠ Ġprivate Ġval Ġimage Loader : ĠBase Image Loader Ċ ) Ġ: ĠRecyclerView . Adapter < Cast Adapter . Cast ViewHolder >() Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġitems : ĠList < Cast Member Dto > Ġ= ĠlistOf () ĊĊĠĠĠ Ġfun Ġupdate Items ( new Data : ĠList < Cast Member Dto >) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdiff Callback Ġ= ĠCast Diff Util Callback ( old List Ġ= Ġitems , Ġnew List Ġ= ĠnewData ) ĊĠĠĠĠĠĠĠ Ġval Ġdiff Result Ġ= ĠDiff Util . calculate Diff ( diff Callback ) ĊĠĠĠĠĠĠĠ Ġitems Ġ= ĠnewData ĊĠĠĠĠĠĠĠ Ġdiff Result . dispatch Updates To ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠCast ViewHolder Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcast Member Card Ġ= ĠLayoutInflater ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. from ( parent . context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. inflate ( R . layout . cast _ member _ card , Ġparent , Ġfalse ) Ġas ĠCard View ĊĠĠĠĠĠĠĠ Ġreturn ĠCast ViewHolder ( cast Member Card , Ġon ItemClickListener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠCast ViewHolder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġholder . bind ( items [ position ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetItem Count (): ĠInt Ġ= ĊĠĠĠĠĠĠĠ Ġitems . size ĊĊĠĠĠ Ġinner Ġclass ĠCast ViewHolder ( ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġcontainer View : ĠView , ĊĠĠĠĠĠĠĠ Ġon ItemClickListener : Ġ( Cast Member Dto ) Ġ-> ĠUnit ĊĠĠĠ Ġ) Ġ: ĠRecyclerView . ViewHolder ( container View ), ĠLayout Container Ġ{ ĊĊĠĠĠĠĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠD agger App Component . builder () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontainer View . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġon ItemClickListener ( items [ adapter Position ]) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun Ġbind ( cast Member : ĠCast Member Dto ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġimage Raw Path Ġ= Ġcast Member . profile _ path ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( image Raw Path Ġ!= Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġimage Loader . load Image Post er ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview With Ġ= Ġcontainer View , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġimage Raw Path Ġ= Ġimage Raw Path , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġimage Size Ġ= ĠImage Size . W 5 0 0 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġview Into Ġ= Ġcontainer View . cast _ member _ photo _ iv ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontainer View . cast _ member _ name _ tv . text Ġ= Ġcast Member . name ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontainer View . cast _ member _ role _ tv . text Ġ= Ġcast Member . character ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }