package Ġgps . x . an 3 0 0 0 qi application . view Ċ Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Toast Ċ import Ġco il . api . load Ċ import Ġco il . transform . Circle Crop Transformation Ċ import Ġgps . x . an 3 0 0 0 qi application . R Ċ import Ġgps . x . an 3 0 0 0 qi application . controller . Character Detail Controller Ċ import Ġgps . x . an 3 0 0 0 qi application . extensions . get Episode Number Ċ import Ġgps . x . an 3 0 0 0 qi application . model . Character Detail Ċ import Ġgps . x . an 3 0 0 0 qi application . view . cont aints . CHARACTER _ ID _ B UNDLE Ċ import Ġgps . x . an 3 0 0 0 qi application . view . interfaces . Detail View Ċ import Ġkotlinx . android . synt hetic . main . activity _ detail .* Ċ import Ġkotlinx . android . synt hetic . main . character _ layout . view .* Ċ Ċ class ĠDetail Activity Ġ: ĠAppCompatActivity (), ĠDetail View Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġcharacter Controller Ġby Ġlazy Ġ{ ĠCharacter Detail Controller ( this ) Ġ} ĊĠĠĠ Ġprivate Ġvar Ġcharacter Id Ġ= Ġ 0 ĊĠĠĠ Ġprivate Ġvar Ġis Favorite Ġ= Ġfalse ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ detail ) ĊĠĠĠĠĠĠĠ Ġintent . getString Extra ( CHARACTER _ ID _ B UNDLE )?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter Controller . get Character Detail ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfavorite _ button . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( is Favorite ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter Controller . remove Favorite ( character Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter Controller . add Favorite ( character Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdefine Favorite Button ( character Id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġupdate Text ( character : ĠCharacter Detail ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcharacter _ image . character _ image . load ( character . image ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcross fade ( true ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplaceholder ( R . drawable . img _ placeholder ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtransformations ( Circle Crop Transformation ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcharacter _ name . text Ġ= Ġcharacter . name ĊĠĠĠĠĠĠĠ Ġcharacter _ status . text Ġ= Ġcharacter . status ĊĠĠĠĠĠĠĠ Ġcharacter _ gender . text Ġ= Ġcharacter . gender ĊĠĠĠĠĠĠĠ Ġcharacter _ species . text Ġ= Ġcharacter . species ĊĠĠĠĠĠĠĠ Ġcharacter _ origin . text Ġ= Ġcharacter . origin . name ĊĠĠĠĠĠĠĠ Ġcharacter _ location . text Ġ= Ġcharacter . location . name ĊĠĠĠĠĠĠĠ Ġcharacter _ episode . text Ġ= Ġcharacter . episode . join ToString (",") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . get Episode Number () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġcharacter Id Ġ= Ġcharacter . id ĊĠĠĠĠĠĠĠ Ġprogress _ circular . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠ Ġdefine Favorite Button ( character . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġshow Err ( err Ġ: ĠString ? ){ ĊĠĠĠĠĠĠĠ ĠToast . makeText ( this @ Detail Activity , Ġ"$ err ", ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġfun Ġdefine Favorite Button ( id : ĠInt ){ ĊĠĠĠĠĠĠĠ Ġfavorite _ button . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠ Ġis Favorite Ġ= Ġcharacter Controller . request Favorite State ( id ) ĊĠĠĠĠĠĠĠ Ġif Ġ( is Favorite ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite _ button . text Ġ= ĠgetString ( R . string . remove _ favorite ) ĊĠĠĠĠĠĠĠ Ġ} else { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite _ button . text Ġ= ĠgetString ( R . string . add _ favorite ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ