/* Ċ Ġ* ĠCopyright Ġ 2 0 1 8 ĠAr th ur ĠI van ets , Ġar th ur . iv an ets . l @ gmail . com Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . arth ur iv an ets . sample . data . data stores . characters Ċ Ċ import Ġandroid . content . Context Ċ import Ġcom . arth ur iv an ets . commons . data . util . Response Ċ import Ġcom . arth ur iv an ets . commons . data . util . result Or Error Ċ import Ġcom . arth ur iv an ets . commons . rx . k tx . apply IO Work Schedulers Ċ import Ġcom . arth ur iv an ets . sample . data . data stores . base . Abstract DataStore Ċ import Ġcom . arth ur iv an ets . sample . data . db . Database Ċ import Ġcom . arth ur iv an ets . sample . data . util . Data Character Ċ import Ġcom . arth ur iv an ets . sample . data . util . Data Com ics Ċ import Ġio . reactivex . Single Ċ Ċ /** Ċ Ġ* Ċ Ġ*/ Ċ internal Ġclass ĠChar acters Database DataStore ( context Ġ: ĠContext ) Ġ: ĠAbstract DataStore ( context ), ĠChar acters DataStore Ġ{ ĊĊĊĠĠĠ Ġoverride Ġfun Ġsave Character ( character Ġ: ĠData Character ) Ġ: ĠSingle < Response < Data Character , ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġsave Character Internal ( character ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġsave Character Internal ( character Ġ: ĠData Character ) Ġ: ĠResponse < Data Character , ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. save ( character . to Database Character ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacter ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġsave Characters ( characters Ġ: ĠList < Data Character >) Ġ: ĠSingle < Response < List < Data Character >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġsave Characters Internal ( characters ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġsave Characters Internal ( characters Ġ: ĠList < Data Character >) Ġ: ĠResponse < List < Data Character >, ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. save ( characters . to Database Characters ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacters ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġupdate Character ( character Ġ: ĠData Character ) Ġ: ĠSingle < Response < Data Character , ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġupdate Character Internal ( character ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġupdate Character Internal ( character Ġ: ĠData Character ) Ġ: ĠResponse < Data Character , ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. update ( character . to Database Character ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacter ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġupdate Characters ( characters Ġ: ĠList < Data Character >) Ġ: ĠSingle < Response < List < Data Character >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġupdate Character Internal ( characters ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġupdate Character Internal ( characters Ġ: ĠList < Data Character >) Ġ: ĠResponse < List < Data Character >, ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. update ( characters . to Database Characters ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacters ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġdelete Character ( character Ġ: ĠData Character ) Ġ: ĠSingle < Response < Data Character , ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġdelete Character Internal ( character ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġdelete Character Internal ( character Ġ: ĠData Character ) Ġ: ĠResponse < Data Character , ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. delete ( character . to Database Character ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacter ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġdelete Characters ( characters Ġ: ĠList < Data Character >) Ġ: ĠSingle < Response < List < Data Character >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġdelete Characters Internal ( characters ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġdelete Characters Internal ( characters Ġ: ĠList < Data Character >) Ġ: ĠResponse < List < Data Character >, ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. delete ( characters . to Database Characters ()) ĊĊĠĠĠĠĠĠĠ Ġreturn @ result Or Error Ġcharacters ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġget Character ( id Ġ: ĠLong ) Ġ: ĠSingle < Response < Data Character , ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġget Character Internal ( id ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġget Character Internal ( id Ġ: ĠLong ) Ġ: ĠResponse < Data Character , ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. getById ( id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ? . to Data Character () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġget Characters ( offset Ġ: ĠInt , Ġlimit Ġ: ĠInt ) Ġ: ĠSingle < Response < List < Data Character >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . from Callable Ġ{ Ġget Characters Internal ( offset , Ġlimit ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply IO Work Schedulers () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġfun Ġget Characters Internal ( offset Ġ: ĠInt , Ġlimit Ġ: ĠInt ) Ġ: ĠResponse < List < Data Character >, ĠThrowable > Ġ= Ġresult Or Error Ġ{ ĊĠĠĠĠĠĠĠ ĠDatabase . getInstance ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. characters Table () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. get ( offset Ġ= Ġoffset , Ġlimit Ġ= Ġlimit ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. from Database To Data Characters () ĊĠĠĠ Ġ} ĊĠĠĠĠĊĠĠĠĠĊĠĠĠ Ġoverride Ġfun Ġsave Character Com ics ( character Id Ġ: ĠLong , Ġcom ics Ġ: ĠList < Data Com ics >) Ġ: ĠSingle < Response < List < Data Com ics >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException (" Character ĠCom ics Ġcannot Ġbe Ġsaved Ġinto Ġthe ĠDatabase .") ĊĠĠĠ Ġ} ĊĠĠĠĠĊĠĠĠĠĊĠĠĠ Ġoverride Ġfun Ġget Character Com ics ( ĊĠĠĠĠĠĠĠ Ġcharacter Id Ġ: ĠLong , ĊĠĠĠĠĠĠĠ Ġoffset Ġ: ĠInt , ĊĠĠĠĠĠĠĠ Ġlimit Ġ: ĠInt ĊĠĠĠ Ġ) Ġ: ĠSingle < Response < List < Data Com ics >, ĠThrowable >> Ġ{ ĊĠĠĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException (" Character ĠCom ics Ġcannot Ġbe Ġfetched Ġfrom Ġthe ĠDatabase .") ĊĠĠĠ Ġ} ĊĠĠĠĠĊĠĠĠĠ Ċ }