package Ġmobile . se oul ing . com . application Ċ Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . Maybe Ċ import Ġio . reactivex . rx kotlin . addTo Ċ import Ġmobile . se oul ing . com . application . data . vo . Plan Ċ import Ġmobile . se oul ing . com . application . home . plan . Plan Repository Ċ import Ġmobile . se oul ing . com . framework . rx . kt . observe On Main Ċ import Ġmobile . se oul ing . com . framework . rx . kt . subscribe WithError Consumer Ċ Ċ class ĠPlan ViewModel ( scheduler Provider : ĠBase Scheduler Provider , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġplan Repository : ĠPlan Repository Ċ ) Ġ: ĠBase ViewModel ( scheduler Provider ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġlisting Ġ= Ġplan Repository . get Plan Listing () ĊĊĠĠĠ Ġval Ġitems Ġ= Ġlisting . item ĊĊĠĠĠ Ġval ĠisLoading Initial Ġ= Ġlisting . load Initial ĊĠĠĠ Ġval Ġis More Loading Ġ= Ġlisting . more Loading ĊĠĠĠ Ġval ĠisEmpty Ġ= Ġlisting . isEmpty ĊĠĠĠ Ġval Ġplan Event Ġ= Ġlisting . plan Event . default If Empty ( Plan Event . NONE ) ĊĊĠĠĠ Ġprivate Ġfun Ġget Plan ( plan Id : ĠInt ): ĠMaybe < Plan > Ġ= Ġplan Repository . get Plan As Maybe ( plan Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. switch If Empty ( plan Repository . load Plan ( plan Id ). and Then ( plan Repository . get Plan As Maybe ( plan Id ))) ĊĊĠĠĠ Ġfun Ġget Plan Title ( plan Id : ĠInt ) Ġ= Ġget Plan ( plan Id ). map Ġ{ Ġit . name Ġ} ĊĠĠĠ Ġfun Ġget Plan Start ( plan Id : ĠInt ) Ġ= Ġget Plan ( plan Id ). map Ġ{ Ġit . start Ġ} ĊĠĠĠ Ġfun Ġget Plan End ( plan Id : ĠInt ) Ġ= Ġget Plan ( plan Id ). map Ġ{ Ġit . end Ġ} ĊĊĠĠĠ Ġfun Ġcreate Plan ( title : ĠString , ĠstartDate : ĠString , ĠendDate : ĠString ): ĠComp letable Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġplan Repository . create Plan ( title , ĠstartDate , ĠendDate ). subscribe On IO () ĊĠĠĠ Ġ} Ċ }