/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠFl orian ĠSch uster . ĠAll Ġrights Ġreserved . Ċ Ġ* Ċ Ġ* Ġ ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġ Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* Ġ ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġat . fl or ians ch uster . watch ables . ui . watch ables . recyclerview Ċ Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . recyclerview . widget . Diff Util Ċ import Ġandroidx . recyclerview . widget . ListAdapter Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġat . fl or ians ch uster . watch ables . R Ċ import Ġcom . ta ilo red apps . android util . ui . extensions . inflate Ċ import Ġkotlinx . android . extensions . Layout Container Ċ import Ġkotlinx . android . synt hetic . main . item _ watch able _ show _ episode .* Ċ Ċ data Ġclass ĠWatch able Episode ( val Ġseason Id : ĠString , Ġval Ġseason Index : ĠString , Ġval Ġepisode : ĠString , Ġval Ġw atched : ĠBoolean ) Ġ{ ĊĠĠĠ Ġval Ġid Ġ= Ġ"${ season Id } S ${ season Index } E $ episode " Ċ } Ċ Ċ class ĠWatch able Episode Adapter Ġ: ĠList Adapter < Watch able Episode , ĠWatch able Episode ViewHolder >( episodes Diff ) Ġ{ ĊĠĠĠ Ġvar Ġinteraction : Ġ(( Watch ables Adapter Interaction ) Ġ-> ĠUnit )? Ġ= Ġnull ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ): ĠWatch able Episode ViewHolder Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠWatch able Episode ViewHolder ( parent . inflate ( R . layout . item _ watch able _ show _ episode )) ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠWatch able Episode ViewHolder , Ġposition : ĠInt ) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġholder . bind ( getItem ( position ), Ġinteraction ) Ċ } Ċ Ċ private Ġval Ġepisode s Diff Ġ= Ġobject Ġ: ĠDiff Util . Item Callback < Watch able Episode >() Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġare Items The Same ( old Item : ĠWatch able Episode , Ġnew Item : ĠWatch able Episode ): ĠBoolean Ġ= Ġold Item . id Ġ== Ġnew Item . id ĊĠĠĠ Ġoverride Ġfun Ġare Contents The Same ( old Item : ĠWatch able Episode , Ġnew Item : ĠWatch able Episode ): ĠBoolean Ġ= Ġold Item Ġ== Ġnew Item Ċ } Ċ Ċ class ĠWatch able Episode ViewHolder ( ĊĠĠĠ Ġoverride Ġval Ġcontainer View : ĠView Ċ ) Ġ: ĠRecyclerView . ViewHolder ( container View ), ĠLayout Container Ġ{ ĊĠĠĠ Ġfun Ġbind ( watch able Episode : ĠWatch able Episode , Ġclicks : Ġ(( Watch ables Adapter Interaction ) Ġ-> ĠUnit )? Ġ= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtv Episode . text Ġ= Ġcontainer View . resources . getString ( R . string . episode _ name , Ġwatch able Episode . season Index , Ġwatch able Episode . episode ) ĊĠĠĠĠĠĠĠ Ġtv Episode . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclicks ?. invoke ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠWatch ables Adapter Interaction . W atched Episode ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwatch able Episode . season Id , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwatch able Episode . episode , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ! watch able Episode . w atched ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtv Episode . setOn Long ClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclicks ?. invoke ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠWatch ables Adapter Interaction . Episode Options ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwatch able Episode . season Id , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwatch able Episode . season Index , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwatch able Episode . episode ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġiv W atched . visibility Ġ= Ġif Ġ( watch able Episode . w atched ) ĠView . VISIBLE Ġelse ĠView . IN VISIBLE ĊĠĠĠ Ġ} Ċ } Ċ