package Ġcom . tam j 0 rd 2 . sk ull king calculator Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Button Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . constraint layout . widget . Barrier Ċ import Ġandroidx . constraint layout . widget . Constraint Layout Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . commit Ċ import Ġcom . tam j 0 rd 2 . sk ull king calculator . components . Player Input Ċ import Ġcom . tam j 0 rd 2 . sk ull king calculator . view models . Player Ċ Ċ class ĠGame Setup Fragment Ġ: ĠFragment ( R . layout . fragment _ game _ setup ) Ġ{ ĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠFragment Tag Ġ= Ġ" game Setup Fragment " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġplayer Count TextView : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtop Level Layout : ĠConstraint Layout ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġremove Player Button : ĠButton ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġadd Player Button : ĠButton ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġplayer Config Barrier : ĠBar rier ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġstart Game Button : ĠButton ĊĊĠĠĠ Ġprivate Ġval Ġplayers Ġ= Ġmutable ListOf ( Player ( 1 ), ĠPlayer ( 2 )) ĊĠĠĠ Ġprivate Ġval Ġplayer Inputs Ġ= Ġmutable ListOf < Player Input >() ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġthis . activity ?. title Ġ= Ġthis . resources . getString ( R . string . game Setup Title ) ĊĊĠĠĠĠĠĠĠ Ġthis . top Level Layout Ġ= Ġview . findViewById ( R . id . top Level Layout ) ĊĠĠĠĠĠĠĠ Ġthis . player Config Barrier Ġ= Ġview . findViewById ( R . id . player Config ) ĊĠĠĠĠĠĠĠ Ġthis . player Count TextView Ġ= Ġview . findViewById ( R . id . player Count ) ĊĊĠĠĠĠĠĠĠ Ġthis . remove Player Button Ġ= Ġview . findViewById ( R . id . remove Player ) ĊĠĠĠĠĠĠĠ Ġthis . remove Player Button . setOnClickListener Ġ{ Ġthis . remove Player Input () Ġ} ĊĊĠĠĠĠĠĠĠ Ġthis . add Player Button Ġ= Ġview . findViewById ( R . id . add Player ) ĊĠĠĠĠĠĠĠ Ġthis . add Player Button . setOnClickListener Ġ{ Ġthis . add New Player () Ġ} ĊĊĠĠĠĠĠĠĠ Ġthis . start Game Button Ġ= Ġview . findViewById ( R . id . start Game ) ĊĠĠĠĠĠĠĠ Ġthis . start Game Button . setOnClickListener Ġ{ Ġthis . start Game () Ġ} ĊĊĠĠĠĠĠĠĠ Ġthis . players . forEach Ġ{ Ġplayer Ġ-> Ġthis . add Player Input ( player ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠĠĠĠĠ Ġthis . players . forEach Indexed Ġ{ Ġindex , Ġplayer Ġ-> Ġplayer . name Ġ= Ġthis . player Inputs [ index ]. getInput Value () Ġ} ĊĠĠĠĠĠĠĠ Ġthis . player Inputs . clear () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġadd New Player () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġplayer Ġ= ĠPlayer ( this . players . size Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġthis . players . add ( player ) ĊĠĠĠĠĠĠĠ Ġthis . add Player Input ( player ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġadd Player Input ( player : ĠPlayer ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Params Ġ= ĠConstraint Layout . LayoutParams ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠConstraint Layout . LayoutParams . MATCH _ CONSTRAINT , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠConstraint Layout . LayoutParams . WRAP _ CONTENT ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġlayout Params . start To Start Ġ= Ġthis . top Level Layout . id ĊĠĠĠĠĠĠĠ Ġlayout Params . end ToEnd Ġ= Ġthis . top Level Layout . id ĊĠĠĠĠĠĠĠ Ġlayout Params . top To Bottom Ġ= Ġthis . player Inputs . last OrNull ()?. id Ġ?: Ġthis . player Config Barrier . id ĊĊĠĠĠĠĠĠĠ Ġval Ġplayer Input Ġ= ĠPlayer Input ( this . context , Ġnull , Ġplayer ) ĊĠĠĠĠĠĠĠ Ġplayer Input . id Ġ= ĠView . generate View Id () ĊĠĠĠĠĠĠĠ Ġplayer Input . layout Params Ġ= Ġlayout Params ĊĊĠĠĠĠĠĠĠ Ġplayer Inputs . add ( player Input ) ĊĠĠĠĠĠĠĠ Ġthis . top Level Layout . addView ( player Input ) ĊĠĠĠĠĠĠĠ Ġthis . update Count And Button Statuses () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġremove Player Input () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlast Player Input Ġ= Ġthis . player Inputs . remove At ( this . player Inputs . size Ġ- Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġthis . top Level Layout . remove View ( last Player Input ) ĊĠĠĠĠĠĠĠ Ġthis . update Count And Button Statuses () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Count And Button Statuses () Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . remove Player Button . isEnabled Ġ= Ġthis . player Inputs . size Ġ> Ġ 2 ĊĠĠĠĠĠĠĠ Ġthis . add Player Button . isEnabled Ġ= Ġthis . player Inputs . size Ġ< Ġ 6 ĊĠĠĠĠĠĠĠ Ġthis . player Count TextView . text Ġ= Ġthis . player Inputs . size . toString () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstart Game () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġplayers Ġ= Ġthis . players ĊĠĠĠĠĠĠĠ Ġthis . parent FragmentManager . commit Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Re ordering Allowed ( true ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠaddTo Back Stack ( null ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreplace ( R . id . fragment _ container _ view , ĠDe al And Bet Fragment . newInstance ( players , Ġ 1 )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ