package Ġorg . opp ia . android . app . hint sand solution Ċ Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġorg . opp ia . android . R Ċ import Ġorg . opp ia . android . app . fragment . Fragment Scope Ċ import Ġorg . opp ia . android . app . model . State Ċ import Ġorg . opp ia . android . app . view model . ViewModel Provider Ċ import Ġorg . opp ia . android . databinding . Hints And Solution Fragment Binding Ċ import Ġorg . opp ia . android . util . g cs resource . Default Resource Bucket Name Ċ import Ġorg . opp ia . android . util . parser . Ex ploration Html Parser EntityType Ċ import Ġorg . opp ia . android . util . parser . Html Parser Ċ import Ġjavax . inject . Inject Ċ Ċ /** ĠPres enter Ġfor Ġ[ Hints And Solution Dialog Fragment ], Ġsets Ġup Ġbindings Ġfrom ĠViewModel . Ġ*/ Ċ @ Fragment Scope Ċ class ĠH ints And Solution Dialog Fragment Presenter Ġ@ Inject Ġconstructor ( ĊĠ Ġprivate Ġval Ġfragment : ĠFragment , ĊĠ Ġprivate Ġval ĠviewModel Provider : ĠViewModel Provider < Hints ViewModel >, ĊĠ Ġprivate Ġval Ġhtml Parser Factory : ĠHtml Parser . Factory , ĊĠ Ġ@ Default Resource Bucket Name Ġprivate Ġval Ġresource Bucket Name : ĠString , ĊĠ Ġ@ Ex ploration Html Parser EntityType Ġprivate Ġval Ġentity Type : ĠString Ċ ) Ġ{ ĊĊĠ Ġprivate Ġvar Ġcurrent Expanded Hint List Index : ĠInt ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġindex : ĠInt ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġis Hint Re ve aled : ĠBoolean ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġsolution Index : ĠInt ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġis Solution Re ve aled : ĠBoolean ? Ġ= Ġnull ĊĠ Ġprivate Ġlateinit Ġvar Ġexpanded Hint List Index Listener : ĠEx pan ded Hint List Index Listener ĊĠ Ġprivate Ġlateinit Ġvar Ġhints And Solution Adapter : ĠH ints And Solution Adapter ĊĠ Ġprivate Ġlateinit Ġvar Ġbinding : ĠH ints And Solution Fragment Binding ĊĠ Ġprivate Ġlateinit Ġvar Ġstate : ĠState ĊĊĠ Ġval ĠviewModel Ġby Ġlazy Ġ{ ĊĠĠĠ Ġget Hints And Solution ViewModel () ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠSets Ġup Ġdata Ġbinding Ġand Ġtoolbar . ĊĠĠ Ġ* ĠHost Ġactivity Ġmust Ġinherit ĠH ints And Solution Listener Ġto Ġdismiss Ġthis Ġfragment . ĊĠĠ Ġ*/ ĊĠ Ġfun Ġhandle Create View ( ĊĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠ Ġstate : ĠState , ĊĠĠĠ Ġid : ĠString ?, ĊĠĠĠ Ġcurrent Expanded Hint List Index : ĠInt ?, ĊĠĠĠ Ġnew Available Hint Index : ĠInt , ĊĠĠĠ Ġall Hints Ex hausted : ĠBoolean , ĊĠĠĠ Ġexpanded Hint List Index Listener : ĠEx pan ded Hint List Index Listener , ĊĠĠĠ Ġindex : ĠInt ?, ĊĠĠĠ Ġis Hint Re ve aled : ĠBoolean ?, ĊĠĠĠ Ġsolution Index : ĠInt ?, ĊĠĠĠ Ġis Solution Re ve aled : ĠBoolean ? ĊĠ Ġ): ĠView ? Ġ{ ĊĊĠĠĠ Ġbinding Ġ= ĊĠĠĠĠĠ ĠH ints And Solution Fragment Binding . inflate ( in flater , Ġcontainer , Ġ/* Ġattach To Root = Ġ*/ Ġfalse ) ĊĠĠĠ Ġthis . current Expanded Hint List Index Ġ= Ġcurrent Expanded Hint List Index ĊĠĠĠ Ġthis . expanded Hint List Index Listener Ġ= Ġexpanded Hint List Index Listener ĊĠĠĠ Ġthis . index Ġ= Ġindex ĊĠĠĠ Ġthis . is Hint Re ve aled Ġ= Ġis Hint Re ve aled ĊĠĠĠ Ġthis . solution Index Ġ= Ġsolution Index ĊĠĠĠ Ġthis . is Solution Re ve aled Ġ= Ġis Solution Re ve aled ĊĠĠĠ Ġbinding . hints And Solution Toolbar . set Navigation Icon ( R . drawable . ic _ close _ white _ 2 4 dp ) ĊĠĠĠ Ġbinding . hints And Solution Toolbar . set Navigation OnClickListener Ġ{ ĊĠĠĠĠĠ Ġ( fragment . require Activity () Ġas ? ĠH ints And Solution Listener )?. dismiss () ĊĠĠĠ Ġ} ĊĠĠĠ Ġbinding . let Ġ{ ĊĠĠĠĠĠ Ġit . viewModel Ġ= Ġthis . viewModel ĊĠĠĠĠĠ Ġit . lifecycle Owner Ġ= Ġfragment ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġthis . state Ġ= Ġstate ĊĠĠĠ Ġ// ĠThe Ġnew Available Hint Index Ġreceived Ġhere Ġis Ġcoming Ġfrom Ġstate Ġplayer Ġbut Ġin Ġthis Ġimplementation ĊĠĠĠ Ġ// Ġhints / solutions Ġare Ġshown Ġon Ġevery Ġeven Ġindex Ġand Ġon Ġevery Ġodd Ġindex Ġwe Ġshow Ġa Ġdivider . ĊĠĠĠ Ġ// ĠTherefore Ġmultiply ing Ġthe Ġoriginal Ġindex Ġby Ġ 2 . ĊĠĠĠ ĠviewModel . new Available Hint Index . set ( new Available Hint Index Ġ* Ġ 2 ) ĊĠĠĠ ĠviewModel . all Hints Ex hausted . set ( all Hints Ex hausted ) ĊĠĠĠ ĠviewModel . ex ploration Id . set ( id ) ĊĊĠĠĠ Ġload Hints And Solution ( state ) ĊĊĠĠĠ Ġreturn Ġbinding . root ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġload Hints And Solution ( state : ĠState ) Ġ{ ĊĠĠĠ Ġ// ĠCheck Ġif Ġhints Ġare Ġavailable Ġfor Ġthis Ġstate . ĊĠĠĠ Ġif Ġ( state . interaction . hint List . size Ġ!= Ġ 0 ) Ġ{ ĊĠĠĠĠĠ ĠviewModel . set Hints List ( state . interaction . hint List ) ĊĠĠĠĠĠ ĠviewModel . set Solution ( state . interaction . solution ) ĊĊĠĠĠĠĠ Ġhints And Solution Adapter Ġ= ĊĠĠĠĠĠĠĠ ĠH ints And Solution Adapter ( ĊĠĠĠĠĠĠĠĠĠ Ġfragment , ĊĠĠĠĠĠĠĠĠĠ ĠviewModel . process Hint List (), ĊĠĠĠĠĠĠĠĠĠ Ġexpanded Hint List Index Listener , ĊĠĠĠĠĠĠĠĠĠ Ġcurrent Expanded Hint List Index , ĊĠĠĠĠĠĠĠĠĠ ĠviewModel . ex ploration Id . get (), ĊĠĠĠĠĠĠĠĠĠ Ġhtml Parser Factory , ĊĠĠĠĠĠĠĠĠĠ Ġresource Bucket Name , ĊĠĠĠĠĠĠĠĠĠ Ġentity Type , ĊĠĠĠĠĠĠĠĠĠ Ġindex , ĊĠĠĠĠĠĠĠĠĠ Ġis Hint Re ve aled , ĊĠĠĠĠĠĠĠĠĠ Ġsolution Index , ĊĠĠĠĠĠĠĠĠĠ Ġis Solution Re ve aled ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġbinding . hints And Solution RecyclerView . apply Ġ{ ĊĠĠĠĠĠĠĠ Ġadapter Ġ= Ġhints And Solution Adapter ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġif Ġ( viewModel . new Available Hint Index . get () Ġ!= Ġ- 1 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhandle New Available Hint ( viewModel . new Available Hint Index . get ()) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġif Ġ( viewModel . all Hints Ex hausted . get () !! ) Ġ{ ĊĠĠĠĠĠĠĠ Ġhandle All Hints Ex hausted ( viewModel . all Hints Ex hausted . get () !! ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle All Hints Ex hausted ( all Hints Ex hausted : ĠBoolean ) Ġ{ ĊĠĠĠ Ġhints And Solution Adapter . set Solution Can Be Re ve aled ( all Hints Ex hausted ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Hints And Solution ViewModel (): ĠH ints ViewModel Ġ{ ĊĠĠĠ Ġreturn ĠviewModel Provider . get For Fragment ( fragment , ĠH ints ViewModel :: class . java ) ĊĠ Ġ} ĊĊĠ Ġfun Ġhandle Re veal Solution () Ġ{ ĊĠĠĠ Ġhints And Solution Adapter . set Re veal Solution () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle New Available Hint ( hint Index : ĠInt ?) Ġ{ ĊĠĠĠ Ġhints And Solution Adapter . set New Hint Is Available ( hint Index !! ) ĊĠ Ġ} ĊĊĠ Ġfun Ġon Expand Clicked ( index : ĠInt ?) Ġ{ ĊĠĠĠ Ġcurrent Expanded Hint List Index Ġ= Ġindex ĊĠĠĠ Ġif Ġ( index Ġ!= Ġnull ) ĊĠĠĠĠĠ Ġhints And Solution Adapter . notify Item Changed ( index ) ĊĠ Ġ} ĊĊĠ Ġfun Ġon Re veal Hint Clicked ( index : ĠInt ?, Ġis Hint Re ve aled : ĠBoolean ?) Ġ{ ĊĠĠĠ Ġthis . index Ġ= Ġindex ĊĠĠĠ Ġthis . is Hint Re ve aled Ġ= Ġis Hint Re ve aled ĊĠ Ġ} ĊĊĠ Ġfun Ġon Re veal Solution Clicked ( solution Index : ĠInt ?, Ġis Solution Re ve aled : ĠBoolean ?) Ġ{ ĊĠĠĠ Ġthis . solution Index Ġ= Ġsolution Index ĊĠĠĠ Ġthis . is Solution Re ve aled Ġ= Ġis Solution Re ve aled ĊĠ Ġ} Ċ } Ċ