package Ġeu . zim bel st ern . to urn ant Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Intent Ċ import Ġandroid . graphics . Bitmap Factory Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġeu . zim bel st ern . to urn ant . databinding . Recycler Item Recipe Binding Ċ import Ġkotlin . random . Random Ċ Ċ class ĠRecipe ListAdapter ( private Ġval Ġall Recipes : ĠList < Recipe >) Ġ: ĠRecyclerView . Adapter < Recipe ListAdapter . Recipe ListView Holder >() Ġ{ ĊĊ ĉ private Ġvar Ġfiltered Recipes Ġ= Ġall Recipes ĊĊ ĉ class ĠRecipe ListView Holder ( val Ġbinding : ĠRe cycler Item Recipe Binding ) Ġ: ĠRecyclerView . ViewHolder ( binding . root ) ĊĊ ĉ override Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠRecipe ListView Holder Ġ{ Ċĉ ĉ val Ġbinding Ġ= ĠRe cycler Item Recipe Binding . inflate ( LayoutInflater . from ( parent . context ), Ġparent , Ġfalse ) Ċĉ ĉ return ĠRecipe ListView Holder ( binding ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Bind ViewHolder ( holder : ĠRecipe ListView Holder , Ġposition : ĠInt ) Ġ{ Ċĉ ĉ val Ġcontext Ġ= Ġholder . binding . root . context Ċĉ ĉ val Ġrecipe Ġ= Ġfiltered Recipes [ position ] Ċĉ ĉ if Ġ( recipe . image Ġ!= Ġnull ) Ċĉĉ ĉ holder . binding . recipe Card Image . setImage Bitmap ( Bitmap Factory . decode ByteArray ( recipe . image , Ġ 0 , Ġrecipe . image . size )) Ċĉ ĉ else Ċĉĉ ĉ holder . binding . recipe Card Image . setImage Resource ( R . drawable . ic _ d ining ) Ċĉ ĉ holder . binding . recipe Card Category . apply Ġ{ Ċĉĉ ĉ text Ġ= Ġrecipe . category Ċĉĉ ĉ val Ġcolors Ġ= Ġresources . obtain Typed Array ( R . array . material _ colors _ 7 0 0 ) Ċĉĉ ĉ val Ġcolors R ipple Ġ= Ġresources . obtain Typed Array ( R . array . material _ colors _ 9 0 0 ) Ċĉĉ ĉ val Ġhash Color Ġ= ĠRandom ( recipe . category . hashCode ()). nextInt ( resources . getString Array ( R . array . material _ colors _ 7 0 0 ). size ) Ċĉĉ ĉ chip BackgroundColor Ġ= Ġcolors . getColor State List ( hash Color ) Ċĉĉ ĉ ripple Color Ġ= Ġcolors R ipple . getColor State List ( hash Color ) Ċĉĉ ĉ colors . recycle () Ċĉĉ ĉ colors R ipple . recycle () Ċĉĉ ĉ visibility Ġ= Ġif Ġ( recipe . category Ġ!= Ġnull ) ĠView . VISIBLE Ġelse ĠView . GONE Ċĉĉ ĉ setOnClickListener Ġ{ Ċĉĉĉ ĉ if Ġ( context Ġis ĠMainActivity ) Ċĉĉĉĉ ĉ context . search For Something ( recipe . category ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ holder . binding . recipe Card C uis ine . apply Ġ{ Ċĉĉ ĉ text Ġ= Ġrecipe . cu is ine Ċĉĉ ĉ val Ġcolors Ġ= Ġresources . obtain Typed Array ( R . array . material _ colors _ 7 0 0 ) Ċĉĉ ĉ val Ġcolors R ipple Ġ= Ġresources . obtain Typed Array ( R . array . material _ colors _ 9 0 0 ) Ċĉĉ ĉ val Ġhash Color Ġ= ĠRandom ( recipe . cu is ine . hashCode ()). nextInt ( resources . getString Array ( R . array . material _ colors _ 7 0 0 ). size ) Ċĉĉ ĉ chip BackgroundColor Ġ= Ġcolors . getColor State List ( hash Color ) Ċĉĉ ĉ ripple Color Ġ= Ġcolors R ipple . getColor State List ( hash Color ) Ċĉĉ ĉ colors . recycle () Ċĉĉ ĉ colors R ipple . recycle () Ċĉĉ ĉ visibility Ġ= Ġif Ġ( recipe . cu is ine Ġ!= Ġnull ) ĠView . VISIBLE Ġelse ĠView . GONE Ċĉĉ ĉ setOnClickListener Ġ{ Ċĉĉĉ ĉ if Ġ( context Ġis ĠMainActivity ) Ċĉĉĉĉ ĉ context . search For Something ( recipe . cu is ine ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ holder . binding . recipe Card Rating . apply Ġ{ Ċĉĉ ĉ rating Ġ= Ġrecipe . rating Ġ?: Ġ 0 f Ċĉĉ ĉ visibility Ġ= Ġif Ġ( recipe . rating Ġ!= Ġnull ) ĠView . VISIBLE Ġelse ĠView . GONE Ċĉ ĉ } Ċĉ ĉ holder . binding . recipe Card Title . text Ġ= Ġrecipe . title Ċĉ ĉ holder . binding . root . setOnClickListener Ġ{ Ċĉĉ ĉ val Ġintent Ġ= ĠIntent ( holder . binding . root . context , ĠRecipe Detail :: class . java ). apply Ġ{ Ċĉĉĉ ĉ putExtra (" RE CI PE ", Ġrecipe ) Ċĉĉ ĉ } Ċĉĉ ĉ holder . binding . root . context . startActivity ( intent ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠgetItem Count (): ĠInt Ġ{ Ċĉ ĉ return Ġfiltered Recipes . size Ċ ĉ } ĊĊ ĉ @ Suppress Lint (" Notify DataSet Changed ") Ċ ĉ fun Ġfilter Recipes ( query : ĠCharSequence ?) Ġ{ Ċĉ ĉ filtered Recipes Ġ= Ġif Ġ( query Ġ!= Ġnull ) Ġall Recipes . filter Ġ{ Ċĉĉ ĉ ( it . title ?. contains ( query , Ġtrue ) Ġ?: Ġfalse ) Ċĉĉĉĉ ĉ || Ġ( it . category ?. contains ( query , Ġtrue ) Ġ?: Ġfalse ) Ċĉĉĉĉ ĉ || Ġ( it . cu is ine ?. contains ( query , Ġtrue ) Ġ?: Ġfalse ) Ċĉ ĉ } Ġelse Ġall Recipes Ċĉ ĉ notify DataSet Changed () Ċ ĉ } Ċ Ċ }