package Ġio . github . z wi eb ack . family finance . app . lifecycle . creator Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . util . Log Ċ import Ġio . github . z wi eb ack . family finance . R Ċ import Ġio . github . z wi eb ack . family finance . business . account . lifecycle . creator . Account Creator Ċ import Ġio . github . z wi eb ack . family finance . business . article . lifecycle . creator . Article Entries Creator Ċ import Ġio . github . z wi eb ack . family finance . business . article . lifecycle . creator . Article Folders Creator Ċ import Ġio . github . z wi eb ack . family finance . business . article . lifecycle . creator . Article Root Creator Ċ import Ġio . github . z wi eb ack . family finance . business . article . lifecycle . creator . exception . No Article Found Exception Ċ import Ġio . github . z wi eb ack . family finance . business . currency . lifecycle . creator . Currency Creator Ċ import Ġio . github . z wi eb ack . family finance . business . exchange _ rate . lifecycle . creator . Exchange Rate Creator Ċ import Ġio . github . z wi eb ack . family finance . business . person . lifecycle . creator . Person Creator Ċ import Ġio . github . z wi eb ack . family finance . business . sms _ pattern . lifecycle . creator . Sms Pattern Creator Ċ import Ġio . github . z wi eb ack . family finance . business . template . lifecycle . creator . Template Creator Ċ import Ġio . github . z wi eb ack . family finance . core . lifecycle . creator . Entity Creator Ċ import Ġio . github . z wi eb ack . family finance . core . model .* Ċ import Ġio . github . z wi eb ack . family finance . core . preference . config . Database Prefs Ċ import Ġio . reactivex . Single Ċ import Ġio . reactivex . functions . Consumer Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġio . re query . Persist able Ċ import Ġio . re query . reactivex . Reactive Entity Store Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . run Blocking Ċ Ċ class ĠDatabase Table Creator ( ĊĠĠĠ Ġprivate Ġval Ġcontext : ĠContext , ĊĠĠĠ Ġprivate Ġval Ġdata : ĠReactive Entity Store < Persist able > Ċ ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġdatabase Prefs : ĠDatabase Prefs Ġ= Ġrun Blocking ( Dispatch ers . IO ) Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase Prefs . with ( context ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcreate Tables () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcurrency Creator Ġ= ĠCurrency Creator ( context , Ġdata ) ĊĠĠĠĠĠĠĠ Ġcreate Table ( currency Creator , Ġon C urrencies Created ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġ< E Ġ: ĠI Base Entity > Ġcreate Table ( ĊĠĠĠĠĠĠĠ Ġcreator : ĠEntity Creator < E >, ĊĠĠĠĠĠĠĠ Ġon Entities Created : ĠConsumer < Iterable < E >> ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ ĠSingle . from Callable ( creator ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġsingle Ġ-> Ġsingle Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ( on Entities Created ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon C urrencies Created (): ĠConsumer < Iterable < Currency >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ Ġc urrencies Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcurrency Ġ= Ġc urrencies . iterator (). next () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . currency Id Ġ= Ġcurrency . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Currency Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Exchange Rate Creator ( context , Ġdata ), Ġon Exchange Rates Created ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Person Creator ( context , Ġdata ), Ġon People Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Exchange Rates Created (): ĠConsumer < Iterable < Exchange Rate >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Exchange Rate Creator :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon People Created (): ĠConsumer < Iterable < Person >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ Ġpeople Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġch ief Ġ= Ġpeople . iterator (). next () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . person Id Ġ= Ġch ief . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Person Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Account Creator ( context , Ġdata ), Ġon Accounts Created ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Article Root Creator ( context , Ġdata ), Ġon Article Roots Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Accounts Created (): ĠConsumer < Iterable < Account >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ Ġaccounts Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaccount Ġ= Ġaccounts . iterator (). next () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . accountId Ġ= Ġaccount . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Account Creator :: class . java ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Article Roots Created (): ĠConsumer < Iterable < Article >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ Ġarticles Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġincome s Name Ġ= Ġcontext . resources . getString ( R . string . article _ income s ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexp enses Name Ġ= Ġcontext . resources . getString ( R . string . article _ exp enses ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġincome s Article Ġ= Ġfind Article ( articles , Ġincome s Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexp enses Article Ġ= Ġfind Article ( articles , Ġexp enses Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . income s Article Id Ġ= Ġincome s Article . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . exp enses Article Id Ġ= Ġexp enses Article . id ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Article Root Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Article Folders Creator ( context , Ġdata ), Ġon Article Folders Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Article Folders Created (): ĠConsumer < Iterable < Article >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Article Folders Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Article Entries Creator ( context , Ġdata ), Ġon Article Entries Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Article Entries Created (): ĠConsumer < Iterable < Article >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ Ġarticles Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtransfer Name Ġ= Ġcontext . resources . getString ( R . string . article _ transfer ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtransfer Article Ġ= Ġfind Article ( articles , Ġtransfer Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdatabase Prefs . transfer Article Id Ġ= Ġtransfer Article . id ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Article Entries Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Template Creator ( context , Ġdata ), Ġon Templates Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Templates Created (): ĠConsumer < Iterable < Template >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Template Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Table ( Sms Pattern Creator ( context , Ġdata ), Ġon Sms Pattern Created ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Sms Pattern Created (): ĠConsumer < Iterable < Sms Pattern >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠConsumer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Finish Of Creator ( Sms Pattern Creator :: class . java ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ" Tables Ġwere Ġcreated ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠTAG Ġ= Ġ" Database Table Creator " ĊĊĠĠĠĠĠĠĠ Ġprivate Ġfun Ġfind Article ( articles : ĠIterable < Article >, Ġname : ĠString ): ĠArticle Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġarticles ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Ġ{ Ġarticle Ġ-> Ġname Ġ== Ġarticle . name Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠNo Article Found Exception ( name ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġprivate Ġfun Ġlog Finish Of Creator ( creator Class : ĠClass <* >) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ" Creator Ġ'${ creator Class . simple Name }' Ġis Ġfinished ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ