package Ġorg . simple . clin ic . drug s . selection . custom Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Parcelable Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . View . GONE Ċ import Ġandroid . view . View . VISIBLE Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . view . input method . Editor Info Ċ import Ġcom . jak ew h art on . r xb ind ing 3 . view . click s Ċ import Ġcom . jak ew h art on . r xb ind ing 3 . view . focus Changes Ċ import Ġcom . jak ew h art on . r xb ind ing 3 . widget . editor Actions Ċ import Ġcom . spotify . mob ius . functions . Consumer Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . rx kotlin . cast Ċ import Ġio . reactivex . subjects . Publish Subject Ċ import Ġkotlinx . parcel ize . Ignored On Parcel Ċ import Ġkotlinx . parcel ize . Parcel ize Ċ import Ġorg . simple . clin ic . R Ċ import Ġorg . simple . clin ic . Report Analytics Events Ċ import Ġorg . simple . clin ic . databinding . Sheet Custom Dr ug Entry Binding Ċ import Ġorg . simple . clin ic . di . injector Ċ import Ġorg . simple . clin ic . drug s . search . Dr ug Frequency Ċ import Ġorg . simple . clin ic . drug s . selection . Pre scribed Dr ug s Screen Key Ċ import Ġorg . simple . clin ic . drug s . selection . custom . drug frequency . Select Dr ug Frequency Dialog Ċ import Ġorg . simple . clin ic . feature . Features Ċ import Ġorg . simple . clin ic . navigation . v 2 . Router Ċ import Ġorg . simple . clin ic . navigation . v 2 . Screen Key Ċ import Ġorg . simple . clin ic . navigation . v 2 . Succeeded Ċ import Ġorg . simple . clin ic . navigation . v 2 . fragments . Base Bottom Sheet Ċ import Ġorg . simple . clin ic . util . set Fragment Result Listener Ċ import Ġorg . simple . clin ic . util . unsafe Lazy Ċ import Ġorg . simple . clin ic . widgets . Progress Material Button . Button State . InProgress Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ import Ġorg . simple . clin ic . widgets . hide Keyboard Ċ import Ġorg . simple . clin ic . widgets . show Keyboard Ċ import Ġorg . simple . clin ic . widgets . text Changes Ċ import Ġjava . util . Locale Ċ import Ġjava . util . UUID Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠCustom Dr ug Entry Sheet Ġ: ĠBase Bottom Sheet < ĊĠĠĠ ĠCustom Dr ug Entry Sheet . Key , ĊĠĠĠ ĠSheet Custom Dr ug Entry Binding , ĊĠĠĠ ĠCustom Dr ug Entry Model , ĊĠĠĠ ĠCustom Dr ug Entry Event , ĊĠĠĠ ĠCustom Dr ug Entry Effect , ĊĠĠĠ ĠUnit >(), ĠCustom Dr ug Entry Ui , ĠCustom Dr ug Entry Sheet Ui Actions Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġlocale : ĠLocale ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġfeatures : ĠFeatures ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġrouter : ĠRouter ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġeffect Handler Factory : ĠCustom Dr ug Entry Effect Handler . Factory ĊĊĠ Ġprivate Ġval Ġhot Events : ĠPublish Subject < Custom Dr ug Entry Event > Ġ= ĠPublish Subject . create () ĊĊĠ Ġprivate Ġval Ġopen As Ġby Ġunsafe Lazy Ġ{ Ġscreen Key . open As Ġ} ĊĊĠ Ġprivate Ġval Ġtitle TextView ĊĠĠĠ Ġget () Ġ= Ġbinding . title TextView ĊĊĠ Ġprivate Ġval Ġremove Button ĊĠĠĠ Ġget () Ġ= Ġbinding . remove Button ĊĊĠ Ġprivate Ġval Ġdrug Dos age EditText ĊĠĠĠ Ġget () Ġ= Ġbinding . drug Dos age EditText ĊĊĠ Ġprivate Ġval Ġdrug Frequency EditText ĊĠĠĠ Ġget () Ġ= Ġbinding . drug Frequency EditText ĊĊĠ Ġprivate Ġval Ġsave Button ĊĠĠĠ Ġget () Ġ= Ġbinding . save Button ĊĊĠ Ġprivate Ġval Ġcustom Dr ug Entry Sheet Ui Group ĊĠĠĠ Ġget () Ġ= Ġbinding . custom Dr ug Entry Sheet Ui Group ĊĊĠ Ġprivate Ġval Ġsave Button Frame ĊĠĠĠ Ġget () Ġ= Ġbinding . save Button Frame ĊĠĠĠĠĊĠ Ġprivate Ġval Ġprogress Indicator ĊĠĠĠ Ġget () Ġ= Ġbinding . progress Indicator ĊĊĠ Ġoverride Ġfun Ġdefault Model () Ġ= ĠCustom Dr ug Entry Model . default ( open As , ĠgetString ( R . string . custom _ drug _ entry _ sheet _ dos age _ placeholder )) ĊĊĠ Ġoverride Ġfun Ġbind View ( ĊĠĠĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠĠĠ Ġcontainer : ĠViewGroup ? ĊĠ Ġ) Ġ= ĠSheet Custom Dr ug Entry Binding . inflate ( in flater , Ġcontainer , Ġfalse ) ĊĊĠ Ġoverride Ġfun Ġui Renderer () Ġ= ĠCustom Dr ug Entry Ui Renderer ( this , ĠgetString ( R . string . custom _ drug _ entry _ sheet _ dos age _ placeholder )) ĊĊĠ Ġoverride Ġfun Ġcreate Update () Ġ= ĠCustom Dr ug Entry Update () ĊĊĠ Ġoverride Ġfun Ġcreate Init () Ġ= ĠCustom Dr ug Entry Init () ĊĊĠ Ġoverride Ġfun Ġcreate Effect Handler ( view Effects Consumer : ĠConsumer < Unit >) Ġ= Ġeffect Handler Factory . create ( this ). build () ĊĊĠ Ġoverride Ġfun Ġevents () Ġ= ĠObservable ĊĠĠĠĠĠ Ġ. merge Array ( ĊĠĠĠĠĠĠĠĠĠ Ġdrug Dos age Changes (), ĊĠĠĠĠĠĠĠĠĠ Ġdrug Dos age Focus Changes (), ĊĠĠĠĠĠĠĠĠĠ Ġsave Click s (), ĊĠĠĠĠĠĠĠĠĠ Ġremove Click s (), ĊĠĠĠĠĠĠĠĠĠ Ġedit Frequency Click s (), ĊĠĠĠĠĠĠĠĠĠ Ġ ime Action Done Click s (), ĊĠĠĠĠĠĠĠĠĠ Ġhot Events ĊĠĠĠĠĠ Ġ). compose ( Report Analytics Events ()) ĊĠĠĠĠĠ Ġ. cast < Custom Dr ug Entry Event >() ĊĊĠ Ġprivate Ġfun Ġ ime Action Done Click s () Ġ= Ġdrug Dos age EditText . editor Actions Ġ{ Ġit Ġ== ĠEditor Info . IME _ ACTION _ DONE Ġ}. map Ġ{ ĠI me Action Done Clicked Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attach ( context : ĠContext ) Ġ{ ĊĠĠĠ Ġsuper . on Attach ( context ) ĊĊĠĠĠ Ġcontext . injector < Injector >(). inject ( this ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdrug Dos age Changes () Ġ= Ġdrug Dos age EditText . text Changes (:: Dos age Edited ) ĊĊĠ Ġprivate Ġfun Ġdrug Dos age Focus Changes () Ġ= Ġdrug Dos age EditText . focus Changes (). map (:: Dos age Focus Changed ) ĊĊĠ Ġprivate Ġfun Ġedit Frequency Click s () Ġ= Ġdrug Frequency EditText . click s (). map Ġ{ ĠEdit Frequency Clicked Ġ} ĊĊĠ Ġprivate Ġfun Ġsave Click s (): ĠObservable < Ui Event > Ġ{ ĊĠĠĠ Ġval Ġdos age I me Click s Ġ= Ġdrug Dos age EditText ĊĠĠĠĠĠĠĠ Ġ. editor Actions Ġ{ Ġit Ġ== ĠEditor Info . IME _ ACTION _ DONE Ġ} ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠUnit Ġ} ĊĊĠĠĠ Ġreturn Ġsave Button ĊĠĠĠĠĠĠĠ Ġ. click s () ĊĠĠĠĠĠĠĠ Ġ. merge With ( dos age I me Click s ) ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠAdd Med icine Button Clicked ( screen Key . patient Uuid ) Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġremove Click s (): ĠObservable < Ui Event > Ġ= ĊĠĠĠĠĠ Ġremove Button ĊĠĠĠĠĠĠĠĠĠ Ġ. click s () ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠRemove Dr ug Button Clicked Ġ} ĊĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠ Ġset Fragment Result Listener ( Select Dr ug Frequency ) Ġ{ Ġ_, Ġresult Ġ-> ĊĠĠĠĠĠ Ġif Ġ( result Ġis ĠSuc ceeded ) ĊĠĠĠĠĠĠĠ Ġhot Events . onNext ( Frequency Edited ( Select Dr ug Frequency Dialog . read Dr ug Frequency ( result ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġdrug Dos age EditText . ime Options Ġ= ĠEditor Info . IME _ ACTION _ DONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Edit Frequency Dialog ( frequency : ĠDr ug Frequency ?) Ġ{ ĊĠĠĠ Ġrouter . push Expecting Result ( Select Dr ug Frequency , ĠSelect Dr ug Frequency Dialog . Key ( frequency )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Dr ug Frequency ( frequency Label : ĠString ) Ġ{ ĊĠĠĠ Ġdrug Frequency EditText . setText ( frequency Label ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Sheet Title ( drug Name : ĠString ?, Ġdos age : ĠString ?, Ġfrequency Label : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġhas Dr ug Frequency Ġ= Ġfrequency Label Ġ!= ĠgetString ( R . string . custom _ drug _ entry _ sheet _ frequency _ none ) ĊĠĠĠ Ġval Ġfrequency Ġ= Ġif Ġ( has Dr ug Frequency ) Ġfrequency Label Ġelse Ġnull ĊĊĠĠĠ Ġtitle TextView . text Ġ= ĠlistOf NotNull ( drug Name , Ġdos age , Ġfrequency ). join ToString () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow ProgressBar () Ġ{ ĊĠĠĠ Ġprogress Indicator . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Custom Dr ug Entry Ui () Ġ{ ĊĠĠĠ Ġcustom Dr ug Entry Sheet Ui Group . visibility Ġ= ĠG ONE ĊĠĠĠ Ġsave Button Frame . visibility Ġ= ĠG ONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide ProgressBar () Ġ{ ĊĠĠĠ Ġprogress Indicator . visibility Ġ= ĠG ONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Custom Dr ug Entry Ui () Ġ{ ĊĠĠĠ Ġcustom Dr ug Entry Sheet Ui Group . visibility Ġ= ĠVIS IBLE ĊĠĠĠ Ġsave Button Frame . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Keyboard () Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . show Keyboard () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġclear Focus From Dos age EditText () Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . clear Focus () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Cursor Position ( position : ĠInt ) Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . post Ġ{ Ġdrug Dos age EditText . setSelection ( position ) Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Save Button Progress State () Ġ{ ĊĠĠĠ Ġsave Button . set Button State ( InProgress ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġclose Sheet And Go To Edit Med icine Screen () Ġ{ ĊĠĠĠ Ġrouter . pop Until ( Pre scribed Dr ug s Screen Key ( screen Key . patient Uuid )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Keyboard () Ġ{ ĊĠĠĠ Ġbinding . root Layout . hide Keyboard () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Dr ug Dos age Text ( dos age : ĠString ) Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . setText ( dos age ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Dr ug Dos age ( dos age : ĠString ?) Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . setText ( dos age ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġmove Dr ug Dos age Cursor To Beginning () Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . post Ġ{ Ġdrug Dos age EditText . setSelection ( 0 ) Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Remove Button () Ġ{ ĊĠĠĠ Ġremove Button . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Remove Button () Ġ{ ĊĠĠĠ Ġremove Button . visibility Ġ= ĠG ONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset ButtonText As Save () Ġ{ ĊĠĠĠ Ġsave Button . text Ġ= ĠgetString ( R . string . custom _ drug _ entry _ sheet _ save _ button _ text ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset ButtonText As Add () Ġ{ ĊĠĠĠ Ġsave Button . text Ġ= ĠgetString ( R . string . custom _ drug _ entry _ sheet _ add _ button _ text ) ĊĠ Ġ} ĊĊĠ Ġ@ Parcel ize ĊĠ Ġdata Ġclass ĠKey ( ĊĠĠĠĠĠ Ġval Ġopen As : ĠOpen As , ĊĠĠĠĠĠ Ġval Ġpatient Uuid : ĠUUID , ĊĠĠĠĠĠ Ġoverride Ġval Ġanalytics Name : ĠString Ġ= Ġ" Custom ĠDr ug ĠEntry ĠSheet " ĊĠ Ġ) Ġ: ĠScreen Key () Ġ{ ĊĠĠĠ Ġ@ Ignored On Parcel ĊĠĠĠ Ġoverride Ġval Ġtype Ġ= ĠScreen Type . Modal ĊĊĠĠĠ Ġoverride Ġfun Ġinstantiate Fragment () Ġ= ĠCustom Dr ug Entry Sheet () ĊĠ Ġ} ĊĊĠ Ġinterface ĠInject or Ġ{ ĊĠĠĠ Ġfun Ġinject ( target : ĠCustom Dr ug Entry Sheet ) ĊĠ Ġ} ĊĊĠ Ġ@ Parcel ize ĊĠ Ġobject ĠSelect Dr ug Frequency Ġ: ĠParcel able Ċ } Ċ