package Ġcom . hak any il ma zz . rick and mort y . data . repository Ċ Ċ import Ġandroid . util . Log Ċ import Ġcom . hak any il ma zz . rick and mort y . data . model . Car to on Character Ċ import Ġcom . hak any il ma zz . rick and mort y . data . repository . datasource . Car to on Character Cache DataSource Ċ import Ġcom . hak any il ma zz . rick and mort y . data . repository . datasource . Car to on Character Local DataSource Ċ import Ġcom . hak any il ma zz . rick and mort y . data . repository . datasource . Car to on Character Remote DataSource Ċ import Ġcom . hak any il ma zz . rick and mort y . domain . repository . Car to on Character Repository Ċ Ċ class ĠCar to on Character Repository Impl ( ĊĠĠĠ Ġprivate Ġval Ġcar to on Character Cache DataSource : ĠCar to on Character Cache DataSource , ĊĠĠĠ Ġprivate Ġval Ġcar to on Character Local DataSource : ĠCar to on Character Local DataSource , ĊĠĠĠ Ġprivate Ġval Ġcar to on Character Remote DataSource : ĠCar to on Character Remote DataSource Ċ ) Ġ: ĠCar to on Character Repository Ġ{ ĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Car to on Characters ( page : ĠInt ): ĠList < Car to on Character >? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġget Car to on Characters From Cache ( page ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġupdate Car to on Characters ( page : ĠInt ): ĠList < Car to on Character >? Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew ListOf Car to on Characters Ġ= Ġget Car to on Characters From Api ( page ) ĊĠĠĠĠĠĠĠ Ġcar to on Character Local DataSource . clear All () ĊĠĠĠĠĠĠĠ Ġcar to on Character Local DataSource . save Car to on Characters To Database ( new ListOf Car to on Characters ) ĊĠĠĠĠĠĠĠ Ġcar to on Character Cache DataSource . save Car to on Characters To Cache ( new ListOf Car to on Characters ) ĊĠĠĠĠĠĠĠ Ġreturn Ġnew ListOf Car to on Characters ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Car to on Characters From Api ( page : ĠInt ): ĠList < Car to on Character > Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġcar to on Character List : ĠList < Car to on Character > Ġ= ĠlistOf () ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcar to on Character Remote DataSource . get Car to on Characters From Api ( page ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbody Ġ= Ġresponse . body () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character List Ġ= Ġbody ?. car to on Characters Ġ?: ĠlistOf () ĊĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . e (" ERROR ", Ġexception . message . toString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcar to on Character List ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Car to on Characters From Database ( page : ĠInt ): ĠList < Car to on Character > Ġ{ ĊĠĠĠĠĠĠĠ Ġlateinit Ġvar Ġcar to on Character List : ĠList < Car to on Character > ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character List Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character Local DataSource . get Car to on Characters From Database () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . e (" ERROR ", Ġexception . message . toString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġif Ġ( car to on Character List . isNull OrEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character List Ġ= Ġget Car to on Characters From Api ( page ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character Local DataSource . save Car to on Characters To Database ( car to on Character List ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcar to on Character List ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġget Car to on Characters From Cache ( page : ĠInt ): ĠList < Car to on Character > Ġ{ ĊĠĠĠĠĠĠĠ Ġlateinit Ġvar Ġcar to on Character List : ĠList < Car to on Character > ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character List Ġ= Ġcar to on Character Cache DataSource . get Car to on Characters From Cache () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . e (" ERROR ", Ġexception . message . toString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġif Ġ( car to on Character List . isNull OrEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character List Ġ= Ġget Car to on Characters From Database ( page ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcar to on Character Cache DataSource . save Car to on Characters To Cache ( car to on Character List ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcar to on Character List ĊĠĠĠ Ġ} Ċ }