package Ġorg . simple . clin ic . setup Ċ Ċ import Ġcom . spotify . mob ius . Next Ċ import Ġcom . spotify . mob ius . Update Ċ import Ġorg . simple . clin ic . app config . Country Ċ import Ġorg . simple . clin ic . mob ius . dispatch Ċ import Ġorg . simple . clin ic . mob ius . next Ċ import Ġorg . simple . clin ic . setup . r uncheck . Allowed Ċ import Ġorg . simple . clin ic . setup . r uncheck . Dis allowed Ċ import Ġorg . simple . clin ic . user . User Ċ import Ġjava . util . Optional Ċ import Ġorg . simple . clin ic . util . isEmpty Ċ import Ġorg . simple . clin ic . util . isNotEmpty Ċ import Ġjava . time . Duration Ċ import Ġjava . time . Instant Ċ Ċ class ĠSetup Activity Update ( ĊĠĠĠ Ġprivate Ġval Ġdatabase Maintenance Interval : ĠDuration Ċ ) Ġ: ĠUpdate < Setup Activity Model , ĠSetup Activity Event , ĠSetup Activity Effect > Ġ{ ĊĊĠ Ġconstructor ( config : ĠSetup Activity Config ) Ġ: Ġthis ( database Maintenance Interval Ġ= Ġconfig . database Maintenance Task Interval ) ĊĊĠ Ġoverride Ġfun Ġupdate ( ĊĠĠĠĠĠ Ġmodel : ĠSetup Activity Model , ĊĠĠĠĠĠ Ġevent : ĠSetup Activity Event ĊĠ Ġ): ĠNext < Setup Activity Model , ĠSetup Activity Effect > Ġ{ ĊĠĠĠ Ġreturn Ġwhen Ġ( event ) Ġ{ ĊĠĠĠĠĠ Ġis ĠUser Details F etched Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġupdated Model Ġ= Ġmodel ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with LoggedIn User ( event . logged In User ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Selected Country ( event . user Selected Country ) ĊĠĠĠĠĠĠĠ Ġval Ġeffect Ġ= Ġgo To Next Screen Effect ( event . logged In User , Ġevent . has User Completed On boarding , Ġevent . user Selected Country ) ĊĊĠĠĠĠĠĠĠ Ġnext ( updated Model , Ġeffect ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġis ĠDatabase Initialized Ġ-> Ġdispatch ( Fetch Database Maintenance Last Run At Time ) ĊĠĠĠĠĠ Ġis ĠF allback Country Set As Selected Ġ-> Ġdispatch ( Go To MainActivity ) ĊĠĠĠĠĠ Ġis ĠDatabase Maintenance Completed Ġ-> Ġdispatch ( Fetch UserDetails ) ĊĠĠĠĠĠ Ġis ĠDatabase Maintenance Last Run At Time Loaded Ġ-> Ġrun Database Maintenance If Required ( event , Ġmodel ) ĊĠĠĠĠĠ Ġis ĠApp Allowed To Run Check Completed Ġ-> Ġinitialize Database ( event ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġinitialize Database ( ĊĠĠĠĠĠ Ġevent : ĠApp Allowed To Run Check Completed ĊĠ Ġ): ĠNext < Setup Activity Model , ĠSetup Activity Effect > Ġ{ ĊĠĠĠ Ġval Ġeffect Ġ= Ġwhen Ġ( event . allowed To Run ) Ġ{ ĊĠĠĠĠĠ ĠAllowed Ġ-> ĠInitialize Database ĊĠĠĠĠĠ Ġis ĠDis allowed Ġ-> ĠShow Not Allowed To Run Message ( event . allowed To Run . reason ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġdispatch ( effect ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrun Database Maintenance If Required ( ĊĠĠĠĠĠ Ġevent : ĠDatabase Maintenance Last Run At Time Loaded , ĊĠĠĠĠĠ Ġmodel : ĠSetup Activity Model ĊĠ Ġ): ĠNext < Setup Activity Model , ĠSetup Activity Effect > Ġ{ ĊĠĠĠ Ġval Ġlast Database Maintenance Run At Ġ= Ġevent . run At ĊĊĠĠĠ Ġval Ġeffect Ġ= Ġlast Database Maintenance Run At ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġlast Run At Ġ-> Ġeffect For Running Database Maintenance ( last Run At , Ġmodel ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. orElse ( Run Database Maintenance ) ĊĊĠĠĠ Ġreturn Ġdispatch ( effect ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġeffect For Running Database Maintenance ( ĊĠĠĠĠĠ Ġlast Run At : ĠInstant , ĊĠĠĠĠĠ Ġmodel : ĠSetup Activity Model ĊĠ Ġ): ĠSetup Activity Effect Ġ{ ĊĠĠĠ Ġval Ġshould Run Database Maintenance Ġ= ĠDuration . between ( last Run At , Ġmodel . screen Opened At ) Ġ> Ġdatabase Maintenance Interval ĊĊĠĠĠ Ġreturn Ġif Ġ( should Run Database Maintenance ) ĊĠĠĠĠĠ ĠRun Database Maintenance ĊĠĠĠ Ġelse ĊĠĠĠĠĠ ĠFetch UserDetails ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġgo To Next Screen Effect ( ĊĠĠĠĠĠ Ġlogged In User : ĠOptional < User >, ĊĠĠĠĠĠ Ġhas User Completed On boarding : ĠBoolean , ĊĠĠĠĠĠ Ġselected Country : ĠOptional < Country > ĊĠ Ġ): ĠSetup Activity Effect Ġ{ ĊĠĠĠ Ġval Ġhas User LoggedIn Comp let ely Ġ= Ġlogged In User . isNotEmpty () Ġ&& Ġselected Country . isNotEmpty () ĊĠĠĠ Ġval Ġuser Present But Country Not Selected Ġ= Ġlogged In User . isNotEmpty () Ġ&& Ġselected Country . isEmpty () ĊĊĠĠĠ Ġreturn Ġwhen Ġ{ ĊĠĠĠĠĠ Ġhas User LoggedIn Comp let ely Ġ-> ĠGo To MainActivity ĊĠĠĠĠĠ Ġuser Present But Country Not Selected Ġ-> ĠSet Fallback Country As Current Country ĊĠĠĠĠĠ Ġhas User Completed On boarding . not () Ġ-> ĠShow On boarding Screen ĊĠĠĠĠĠ Ġelse Ġ-> ĠShow Country Selection Screen ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ