package Ġcom . yandex . pay . core . view models Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle .* Ċ import Ġcom . yandex . pay . core . actions . User Cards Action Ċ import Ġcom . yandex . pay . core . data . User Card Ċ import Ġcom . yandex . pay . core . events . Event Ċ import Ġcom . yandex . pay . core . infra . Store Ċ import Ġcom . yandex . pay . core . state . User Cards State Ċ import Ġcom . yandex . pay . core . ui . views . interfaces . IC ard Item View Ċ import Ġcom . yandex . pay . core . ui . views . interfaces . IC ards ListView Ċ import Ġcom . yandex . pay . core . ui . views . interfaces . I Header View Ċ import Ġcom . yandex . pay . core . ui . views . present ers . Card Item Presenter Ċ import Ġcom . yandex . pay . core . ui . views . present ers . Cards List Presenter Ċ import Ġcom . yandex . pay . core . ui . views . present ers . Header Presenter Ċ Ċ internal Ġclass ĠC ards List ViewModel ( ĊĠĠĠ Ġapplication : ĠApplication , ĊĠĠĠ Ġprivate Ġval Ġparent ViewModel : ĠMain ViewModel , Ċ ) Ġ: ĠBase ViewModel ( application ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġstore : ĠStore ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġparent ViewModel . store ĊĠĠĠ Ġprivate Ġval Ġuser Cards State : ĠUser Cards State ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġstore . state . user Cards . value !! ĊĊĠĠĠ Ġval Ġselected Card Changed : ĠLive Data < Int > Ġ= ĊĠĠĠĠĠĠĠ Ġstore . state . user Cards . map Ġ{ Ġit . selected Ġ}. distinct Until Changed () ĊĊĠĠĠ Ġprivate Ġval Ġheader Presenter : ĠHeader Presenter Ġ= ĠHeader Presenter () ĊĠĠĠ Ġprivate Ġval Ġlist Presenter : ĠC ards List Presenter Ġ= ĊĠĠĠĠĠĠĠ ĠC ards List Presenter ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCard Item Presenter ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġapplication . resources , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠI Card Item View . Access ory Type . Check mark ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠ Ġfun Ġupdate Header ( header : ĠI Header View ) Ġ{ ĊĠĠĠĠĠĠĠ Ġheader Presenter . present ( Header Presenter . Payload . Back Button (:: close With Back Button ), Ġheader ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġupdate Cards List ( view : ĠI Cards ListView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ( cards , Ġselected ) Ġ= Ġuser Cards State ĊĠĠĠĠĠĠĠ Ġval Ġpayload Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠC ards List Presenter . Payload ( cards . or Empty (), Ġselected , Ġ:: select Item , Ġ:: select AddNew Item ) ĊĠĠĠĠĠĠĠ Ġlist Presenter . present ( payload , Ġview ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġclose With Back Button () Ġ{ ĊĠĠĠĠĠĠĠ Ġlog Event ( Event . Card Selection Cancelled ) ĊĠĠĠĠĠĠĠ Ġclose () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġclose () Ġ{ ĊĠĠĠĠĠĠĠ Ġparent ViewModel . on Back Pressed () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġselect Item ( item : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= Ġuser Cards State . cards ! ![ item ] ĊĠĠĠĠĠĠĠ Ġlog Card Selection ( card ) ĊĠĠĠĠĠĠĠ Ġstore . dispatch ( User Cards Action . SetDefault ( card . id )) ĊĠĠĠĠĠĠĠ Ġclose () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġselect AddNew Item () Ġ{ ĊĠĠĠĠĠĠĠ Ġparent ViewModel . start New Card Binding ( true ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġlog Card Selection ( card : ĠUser Card ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew Card Ġ= Ġwith ( user Cards State ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards ?. get OrNull ( selected )?. let Ġ{ Ġit . id Ġ!= Ġcard . id Ġ} Ġ?: Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġlog Event ( Event . Card Selected ( new Card )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinternal Ġclass ĠFactory ( ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġapplication : ĠApplication , ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġparent ViewModel : ĠMain ViewModel , ĊĠĠĠ Ġ) Ġ: ĠViewModel Provider . Factory Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġ< T Ġ: ĠViewModel > Ġcreate ( model Class : ĠClass < T >): ĠT Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtake If Ġ{ Ġmodel Class Ġ== ĠC ards List ViewModel :: class . java Ġ} ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠC ards List ViewModel ( application , Ġparent ViewModel ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġas ĠT ĊĠĠĠ Ġ} Ċ } Ċ