package Ġcom . news . android . him an shu . new spin . data . source . local Ċ Ċ import Ġcom . news . android . him an shu . new spin . data . News Ċ import Ġcom . news . android . him an shu . new spin . data . source . Local Data NotFoundException Ċ import Ġcom . news . android . him an shu . new spin . data . source . News DataSource Ċ import Ġcom . news . android . him an shu . new spin . data . source . Result Ċ import Ġcom . news . android . him an shu . new spin . util . App Executors Ċ import Ġkotlinx . coroutines . experimental . with Context Ċ Ċ class ĠNews Local DataSource Ġprivate Ġconstructor ( val Ġapp Executors : ĠApp Executors , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnews Dao : ĠNews Dao ) Ġ: ĠNews DataSource Ġ{ ĊĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget News ById ( id : ĠString ): ĠResult < News > Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnews Ġ= Ġnews Dao . get News ById ( id ) ĊĠĠĠĠĠĠĠ Ġif Ġ( news Ġ!= Ġnull ) ĠResult . Success ( news ) Ġelse ĠResult . Error ( Local Data NotFoundException ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget New sBy Category ( category : ĠString ): ĠResult < ArrayList < News >> Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnews Ġ= ĠArrayList ( news Dao . getNew sBy Category ( category )) ĊĠĠĠĠĠĠĠ Ġif Ġ( news . isNotEmpty ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResult . Success ( news ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResult . Error ( Local Data NotFoundException ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġsave News ( news : ĠNews ) Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġnews Dao . insert News ( news ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġupdate Bookmark Status ( news : ĠNews ) Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġnews Dao . update Bookmark ( news . id , Ġnews . is Book marked ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġdelete News ( category : ĠString , is Book marked : ĠBoolean ) Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġnews Dao . delete News ( category , is Book marked ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġdelete All News () Ġ= Ġwith Context ( app Executors . io Context ){ ĊĠĠĠĠĠĠĠ Ġnews Dao . delete All News () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġsuspend Ġfun Ġget Book marked News (): ĠResult < ArrayList < News >> Ġ= Ġwith Context ( app Executors . io Context ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnews Ġ= ĠArrayList ( news Dao . get Book marked News ( true )) ĊĠĠĠĠĠĠĠ Ġif Ġ( news . isNotEmpty ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResult . Success ( news ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResult . Error ( Local Data NotFoundException ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġvar ĠINSTANCE : ĠNews Local DataSource ? Ġ= Ġnull ĊĊĠĠĠĠĠĠĠ Ġ@ Jvm Static ĊĠĠĠĠĠĠĠ Ġfun ĠgetInstance ( app Executors : ĠApp Executors , Ġnews Dao : ĠNews Dao ): ĠNews Local DataSource Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( INSTANCE Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsynchronized ( News Local DataSource :: java Class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠINSTANCE Ġ= ĠNews Local DataSource ( app Executors , Ġnews Dao ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠINSTANCE !! ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }