package Ġorg . simple . clin ic . drug s . selection . entry Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . res . Configuration Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View . GONE Ċ import Ġandroid . view . View . VISIBLE Ċ 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 Ġio . github . in fl ation x . view pump . View Pump Context Wrapper Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . rx kotlin . of Type Ċ import Ġio . reactivex . subjects . Publish Subject Ċ import Ġorg . simple . clin ic . Clin ic App Ċ import Ġorg . simple . clin ic . R Ċ import Ġorg . simple . clin ic . Report Analytics Events Ċ import Ġorg . simple . clin ic . databinding . Sheet Custom Pre scription Entry Binding Ċ import Ġorg . simple . clin ic . di . Injector Provider Context Wrapper Ċ import Ġorg . simple . clin ic . drug s . selection . entry . confirm removed ialog . Confirm Remove Pre scription Dialog Ċ import Ġorg . simple . clin ic . drug s . selection . entry . di . Custom Pre scription Entry Sheet Component Ċ import Ġorg . simple . clin ic . feature . Features Ċ import Ġorg . simple . clin ic . mob ius . Mob ius Delegate Ċ import Ġorg . simple . clin ic . util . unsafe Lazy Ċ import Ġorg . simple . clin ic . util . with Locale Ċ import Ġorg . simple . clin ic . util . wrap Ċ import Ġorg . simple . clin ic . widgets . Bottom Sheet Activity Ċ import Ġorg . simple . clin ic . widgets . Screen Destroyed Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ import Ġorg . simple . clin ic . widgets . setText And Cursor Ċ import Ġorg . simple . clin ic . widgets . text Changes Ċ import Ġjava . util . Locale Ċ import Ġjava . util . UUID Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠCustom Pre scription Entry Sheet Ġ: ĠBottom Sheet Activity (), ĠCustom Pre scription Entry Ui , ĠCustom Pre scription Entry Ui Actions Ġ{ ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġlocale : ĠLocale ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġeffect Handler Factory : ĠCustom Pre scription Entry Effect Handler . Factory ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġfeatures : ĠFeatures ĊĊĠ Ġprivate Ġlateinit Ġvar Ġcomponent : ĠCustom Pre scription Entry Sheet Component ĊĊĠ Ġprivate Ġval Ġon Dest ro ys Ġ= ĠPublish Subject . create < Screen Destroyed >() ĊĊĠ Ġprivate Ġval Ġopen As Ġby Ġunsafe Lazy Ġ{ ĊĠĠĠ Ġintent . get Parcelable Extra < Open As >( KEY _ OPEN _ AS ) !! ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġevents Ġby Ġunsafe Lazy Ġ{ ĊĠĠĠ ĠObservable ĊĠĠĠĠĠĠĠ Ġ. merge Array ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdrug Name Changes (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdrug Dos age Changes (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdrug Dos age Focus Changes (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsave Click s (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġremove Click s ()) ĊĠĠĠĠĠĠĠ Ġ. compose ( Report Analytics Events ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġui Renderer Ġ= ĠCustom Pre scription Entry Ui Renderer ( this ) ĊĊĠ Ġprivate Ġval Ġdelegate : ĠMob ius Delegate < Custom Pre scription Entry Model , ĠCustom Pre scription Entry Event , ĠCustom Pre scription Entry Effect > Ġby Ġunsafe Lazy Ġ{ ĊĠĠĠ ĠMob ius Delegate . for Activity ( ĊĠĠĠĠĠĠĠ Ġevents Ġ= Ġevents . of Type (), ĊĠĠĠĠĠĠĠ Ġdefault Model Ġ= ĠCustom Pre scription Entry Model . create ( open As ), ĊĠĠĠĠĠĠĠ Ġupdate Ġ= ĠCustom Pre scription Entry Update (), ĊĠĠĠĠĠĠĠ Ġeffect Handler Ġ= Ġeffect Handler Factory . create ( this ). build (), ĊĠĠĠĠĠĠĠ Ġinit Ġ= ĠCustom Pre scription Entry Init (), ĊĠĠĠĠĠĠĠ Ġmodel Update Listener Ġ= Ġui Renderer :: render ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġlateinit Ġvar Ġbinding : ĠSheet Custom Pre scription Entry Binding ĊĊĠ Ġprivate Ġval Ġroot Layout ĊĠĠĠ Ġget () Ġ= Ġbinding . root Layout ĊĊĠ Ġprivate Ġval Ġdrug Name EditText ĊĠĠĠ Ġget () Ġ= Ġbinding . drug Name EditText ĊĊĠ Ġprivate Ġval Ġdrug Dos age EditText ĊĠĠĠ Ġget () Ġ= Ġbinding . drug Dos age EditText ĊĊĠ Ġprivate Ġval Ġsave Button ĊĠĠĠ Ġget () Ġ= Ġbinding . save Button ĊĊĠ Ġprivate Ġval Ġremove Med icine Button ĊĠĠĠ Ġget () Ġ= Ġbinding . remove Med icine Button ĊĊĠ Ġprivate Ġval Ġenter Med icine TextView ĊĠĠĠ Ġget () Ġ= Ġbinding . enter Med icine TextView ĊĊĠ Ġprivate Ġval Ġedit Med icine TextView ĊĠĠĠ Ġget () Ġ= Ġbinding . edit Med icine TextView ĊĊĠ Ġ@ Suppress Lint (" Check Result ") ĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠ Ġbinding Ġ= ĠSheet Custom Pre scription Entry Binding . inflate ( layout Inflater ) ĊĠĠĠ ĠsetContentView ( binding . root ) ĊĊĠĠĠ Ġdelegate . on Restore InstanceState ( savedInstanceState ) ĊĊĠĠĠ Ġ// ĠDis miss Ġthis Ġsheet Ġwhen Ġthe Ġkeyboard Ġis Ġdis missed . ĊĠĠĠ Ġroot Layout . back KeyPress Interceptor Ġ= Ġ{ Ġsuper . on Background Click () Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġattach Base Context ( base Context : ĠContext ) Ġ{ ĊĠĠĠ Ġsetup Di Graph () ĊĊĠĠĠ Ġval Ġwrapped Context Ġ= Ġbase Context ĊĠĠĠĠĠĠĠ Ġ. wrap Ġ{ ĠInject or Provider Context Wrapper . wrap ( it , Ġcomponent ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. wrap Ġ{ ĠView Pump Context Wrapper . wrap ( it ) Ġ} ĊĊĠĠĠ Ġsuper . attach Base Context ( wrapped Context ) ĊĠĠĠ Ġapply Override Configuration ( Configuration ()) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġapply Override Configuration ( override Configuration : ĠConfiguration ) Ġ{ ĊĠĠĠ Ġsuper . apply Override Configuration ( override Configuration . with Locale ( locale , Ġfeatures )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Di Graph () Ġ{ ĊĠĠĠ Ġcomponent Ġ= ĠC lin ic App . app Component ĊĠĠĠĠĠĠĠ Ġ. custom Pre scription Entry Sheet Component () ĊĠĠĠĠĠĠĠ Ġ. create ( activity Ġ= Ġthis ) ĊĊĠĠĠ Ġcomponent . inject ( this ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonStart () Ġ{ ĊĠĠĠ Ġsuper . onStart () ĊĠĠĠ Ġdelegate . start () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Stop () Ġ{ ĊĠĠĠ Ġdelegate . stop () ĊĠĠĠ Ġsuper . on Stop () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Save InstanceState ( out State : ĠBundle ) Ġ{ ĊĠĠĠ Ġdelegate . on Save InstanceState ( out State ) ĊĠĠĠ Ġsuper . on Save InstanceState ( out State ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Destroy () Ġ{ ĊĠĠĠ Ġon Dest ro ys . onNext ( Screen Destroyed ()) ĊĠĠĠ Ġsuper . on Destroy () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Background Click () Ġ{ ĊĠĠĠ Ġval Ġdrug Name Empty Ġ= Ġdrug Name EditText . text . isNull Or Blank () ĊĠĠĠ Ġval Ġdos age Empty Ġ= Ġdrug Dos age EditText . text . isNull Or Blank () ĊĠĠĠĠĠĠĠ Ġ|| Ġdrug Dos age EditText . text . toString (). trim () Ġ== ĠgetString ( R . string . cust omp re scription _ dos age _ placeholder ) ĊĊĠĠĠ Ġif Ġ( drug Name Empty Ġ&& Ġdos age Empty ) Ġ{ ĊĠĠĠĠĠ Ġsuper . on Background Click () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdrug Name Changes () Ġ= Ġdrug Name EditText . text Changes (:: Custom Pre scription Dr ug Name TextChanged ) ĊĊĠ Ġprivate Ġfun Ġdrug Dos age Changes () Ġ= Ġdrug Dos age EditText . text Changes (:: Custom Pre scription Dr ug Dos age TextChanged ) ĊĊĠ Ġprivate Ġfun Ġdrug Dos age Focus Changes () Ġ= Ġdrug Dos age EditText ĊĠĠĠĠĠ Ġ. focus Changes () ĊĠĠĠĠĠ Ġ. map (:: Custom Pre scription Dr ug Dos age Focus Changed ) ĊĊĠ Ġ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 Ġ{ ĠSave Custom Pre scription Clicked Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġremove Click s (): ĠObservable < Ui Event > Ġ= ĊĠĠĠĠĠ Ġremove Med icine Button ĊĠĠĠĠĠĠĠĠĠ Ġ. click s () ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠRemove Custom Pre scription Clicked Ġ} ĊĊĠ Ġoverride Ġfun Ġset Save Button Enabled ( enabled : ĠBoolean ) Ġ{ ĊĠĠĠ Ġsave Button . isEnabled Ġ= Ġenabled ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Dr ug Dos age Text ( text : ĠString ) Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . setText ( text ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġmove Dr ug Dos age Cursor To Beginning () Ġ{ ĊĠĠĠ Ġ// ĠPost ing Ġto ĠEditText 's Ġhandler Ġis Ġintention al . ĠThe Ġcursor Ġgets Ġoverridden Ġotherwise . ĊĠĠĠ Ġdrug Dos age EditText . post Ġ{ Ġdrug Dos age EditText . setSelection ( 0 ) Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Enter New Pre scription Title () Ġ{ ĊĠĠĠ Ġenter Med icine TextView . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Edit Pre scription Title () Ġ{ ĊĠĠĠ Ġedit Med icine TextView . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Remove Button () Ġ{ ĊĠĠĠ Ġremove Med icine Button . visibility Ġ= ĠVIS IBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Remove Button () Ġ{ ĊĠĠĠ Ġremove Med icine Button . visibility Ġ= ĠG ONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Med icine Name ( drug Name : ĠString ) Ġ{ ĊĠĠĠ Ġdrug Name EditText . setText And Cursor ( drug Name ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Dos age ( dos age : ĠString ?) Ġ{ ĊĠĠĠ Ġdrug Dos age EditText . setText And Cursor ( dos age Ġ?: Ġ"") ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Confirm Remove Med icine Dialog ( pre scribed Dr ug Uuid : ĠUUID ) Ġ{ ĊĠĠĠ ĠConfirm Remove Pre scription Dialog . show For Pre scription ( pre scribed Dr ug Uuid , Ġsupport FragmentManager ) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġconst Ġval ĠKEY _ OPEN _ AS Ġ= Ġ" open As " ĊĊĠĠĠ Ġfun Ġintent For AddNew Pre scription ( context : ĠContext , Ġpatient Uuid : ĠUUID ): ĠIntent Ġ{ ĊĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( context , ĠCustom Pre scription Entry Sheet :: class . java ) ĊĠĠĠĠĠ Ġintent . putExtra ( KEY _ OPEN _ AS , ĠOpen As . New ( patient Uuid )) ĊĠĠĠĠĠ Ġreturn Ġintent ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġintent For Updating Pre scription ( context : ĠContext , Ġpatient Uuid : ĠUUID , Ġpre scribed Dr ug Uuid : ĠUUID ): ĠIntent Ġ{ ĊĠĠĠĠĠ Ġval Ġintent Ġ= ĠIntent ( context , ĠCustom Pre scription Entry Sheet :: class . java ) ĊĠĠĠĠĠ Ġintent . putExtra ( KEY _ OPEN _ AS , ĠOpen As . Update ( patient Uuid , Ġpre scribed Dr ug Uuid )) ĊĠĠĠĠĠ Ġreturn Ġintent ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ