package Ġcom . r vi anna ol ive ira . mar vel app . data Ċ Ċ import Ġcom . r vi anna ol ive ira . mar vel app . data . api . I Api Data Ċ import Ġcom . r vi anna ol ive ira . mar vel app . data . repository . I Repository Data Ċ import Ġcom . r vi anna ol ive ira . mar vel app . data . repository . Key Database Ċ import Ġcom . r vi anna ol ive ira . mar vel app . model . Favorite Ċ import Ġcom . r vi anna ol ive ira . mar vel app . model . Mar vel Character Ċ import Ġcom . r vi anna ol ive ira . mar vel app . model . Mar vel Com ic Ċ import Ġio . reactivex . Single Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . functions . Bi Function Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ Ċ /** Ċ Ġ* ĠCri ado Ġpor Ġro d rig o Ġon Ġ 0 9 / 0 4 / 1 7 . Ċ Ġ*/ Ċ class ĠData Manager ( private Ġval Ġapi Data : ĠI Api Data , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġrepository Data : ĠI Repository Data ) Ġ: ĠI DataManager Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġget Mar vel Characters ( offset : ĠInt ): ĠSingle < List < Mar vel Character >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcharacters Ġ= Ġapi Data . get Mar vel Characters ( offset ) ĊĠĠĠĠĠĠĠ Ġval Ġfavor ites Ġ= Ġrepository Data . get Characters F avorites (). first Or Error () ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . zip ( characters , Ġfavor ites , ĠBi Function < List < Mar vel Character >, ĠList < Favorite >, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠList < Mar vel Character >>( this :: combine Character )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Mar vel Characters Begin Letter ( letter : ĠString ): ĠSingle < List < Mar vel Character >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcharacters Ġ= Ġapi Data . get Mar vel Characters Begin Letter ( letter ) ĊĠĠĠĠĠĠĠ Ġval Ġfavor ites Ġ= Ġrepository Data . get Characters F avorites (). first Or Error () ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . zip ( characters , Ġfavor ites , ĠBi Function < List < Mar vel Character >, ĠList < Favorite >, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠList < Mar vel Character >>( this :: combine Character )) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Mar vel Com ics ( offset : ĠInt ): ĠSingle < List < Mar vel Com ic >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ics Ġ= Ġapi Data . get Mar vel Com ics ( offset ) ĊĠĠĠĠĠĠĠ Ġval Ġfavor ites Ġ= Ġrepository Data . get Com ics F avorites (). first Or Error () ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . zip ( com ics , Ġfavor ites , ĠBi Function < List < Mar vel Com ic >, ĠList < Favorite >, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠList < Mar vel Com ic >>( this :: combine Com ic )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Mar vel Com ics Begin Letter ( letter : ĠString ): ĠSingle < List < Mar vel Com ic >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ics Ġ= Ġapi Data . get Mar vel Com ics Begin Letter ( letter ) ĊĠĠĠĠĠĠĠ Ġval Ġfavor ites Ġ= Ġrepository Data . get Com ics F avorites (). first Or Error () ĊĠĠĠĠĠĠĠ Ġreturn ĠSingle . zip ( com ics , Ġfavor ites , ĠBi Function < List < Mar vel Com ic >, ĠList < Favorite >, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠList < Mar vel Com ic >>( this :: combine Com ic )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġload Detail Mar vel Character ( id : ĠInt ?): ĠSingle < Mar vel Character > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġapi Data . get Detail Character ( id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġload Detail Com ic Character ( id : ĠInt ?): ĠSingle < Mar vel Com ic > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġapi Data . get Detail Com ic ( id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetAll F avorites (): ĠSingle < Favorite > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfavorite Ġ= ĠF avorite () ĊĊĠĠĠĠĠĠĠ Ġreturn Ġrepository Data . getAll F avorites () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. first Or Error () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . new Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġlist Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlist . forEach Ġ{ Ġitem Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( Key Database . Favorite Group . CHAR ACT ERS Ġ== Ġitem . group Type ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite . characters . add ( item ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite . com ics . add ( item ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfavorite ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġinsert Favorite ( favorite : ĠF avorite ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository Data . insert Favorite ( favorite ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġdelete Favorite ( favorite : ĠF avorite , Ġremove Character : ĠBoolean ): ĠSingle < Unit > Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( remove Character ) Ġapi Data . remove Favorite Character Cache ( favorite . id Mar vel ) Ġelse Ġapi Data . remove Favorite Com ic Cache ( favorite . id Mar vel ) ĊĠĠĠĠĠĠĠ Ġreturn Ġrepository Data . delete Favorite ( favorite ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcombine Character ( characters : ĠList < Mar vel Character >, Ġfavor ites : ĠList < Favorite >): ĠList < Mar vel Character > Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( favorites . isEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġcharacters ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġmap Favorite Ġ= ĠHashMap < Int ?, ĠF avorite >() ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( favorite Ġin Ġfavor ites ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Favorite . put ( favorite . id Mar vel , Ġfavorite ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġfor Ġ( character Ġin Ġcharacters ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter . favorite Ġ= Ġmap Favorite [ character . id ] ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġcharacters ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcombine Com ic ( com ics : ĠList < Mar vel Com ic >, Ġfavor ites : ĠList < Favorite >): ĠList < Mar vel Com ic > Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( favorites . isEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġcom ics ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġmap Favorite Ġ= ĠHashMap < Int ?, ĠF avorite >() ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( favorite Ġin Ġfavor ites ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Favorite . put ( favorite . id Mar vel , Ġfavorite ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġfor Ġ( com ic Ġin Ġcom ics ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcom ic . favorite Ġ= Ġmap Favorite [ com ic . id ] ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcom ics ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ interface ĠI DataManager Ġ{ ĊĠĠĠ Ġfun Ġget Mar vel Characters ( offset : ĠInt ): ĠSingle < List < Mar vel Character >> ĊĠĠĠ Ġfun Ġget Mar vel Characters Begin Letter ( letter : ĠString ): ĠSingle < List < Mar vel Character >> ĊĠĠĠ Ġfun Ġinsert Favorite ( favorite : ĠF avorite ) ĊĠĠĠ Ġfun Ġdelete Favorite ( favorite : ĠF avorite , Ġremove Character : ĠBoolean Ġ= Ġfalse ): ĠSingle < Unit > ĊĠĠĠ Ġfun ĠgetAll F avorites (): ĠSingle < Favorite > ĊĠĠĠ Ġfun Ġload Detail Mar vel Character ( id : ĠInt ?): ĠSingle < Mar vel Character > ĊĠĠĠ Ġfun Ġload Detail Com ic Character ( id : ĠInt ?): ĠSingle < Mar vel Com ic > ĊĠĠĠ Ġfun Ġget Mar vel Com ics ( offset : ĠInt ): ĠSingle < List < Mar vel Com ic >> ĊĠĠĠ Ġfun Ġget Mar vel Com ics Begin Letter ( letter : ĠString ): ĠSingle < List < Mar vel Com ic >> Ċ } Ċ