package Ġio . pl ast ique . dev i ations . download Ċ Ċ import Ġio . pl ast ique . api . dev i ations . De viation Service Ċ import Ġio . pl ast ique . api . dev i ations . Download Info Dto Ċ import Ġio . pl ast ique . util . Size Ċ import Ġio . reactivex . Maybe Ċ import Ġio . reactivex . Single Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠDownload Info Repository Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġdownload Info Dao : ĠDownload Info Dao , ĊĠĠĠ Ġprivate Ġval Ġdeviation Service : ĠDe viation Service Ċ ) Ġ{ ĊĠĠĠ Ġfun Ġget Download Info ( dev iation Id : ĠString ): ĠSingle < Download Info > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġget Download Info From Db ( dev iation Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. switch If Empty ( get Download Info From Server ( dev iation Id )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġdownload Info Entity Ġ-> Ġdownload Info Entity . to Download Info () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Download Info From Db ( dev iation Id : ĠString ): ĠMaybe < Download Info Entity > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġdownload Info Dao . get Download Info ( dev iation Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Download Info From Server ( dev iation Id : ĠString ): ĠSingle < Download Info Entity > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġdeviation Service . get Download Info ById ( dev iation Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġpersist ( dev iation Id , Ġit ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġpersist ( dev iation Id : ĠString , Ġdownload Info : ĠDownload Info Dto ): ĠDownload Info Entity Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġentity Ġ= Ġdownload Info . to Download Info Entity ( dev iation Id ) ĊĠĠĠĠĠĠĠ Ġdownload Info Dao . insert OrUpdate ( entity ) ĊĠĠĠĠĠĠĠ Ġreturn Ġentity ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠDownload Info Dto . to Download Info Entity ( dev iation Id : ĠString ): ĠDownload Info Entity Ġ= ĠDownload Info Entity ( ĊĠĠĠ Ġdeviation Id Ġ= Ġdeviation Id , ĊĠĠĠ Ġdownload Url Ġ= Ġurl , ĊĠĠĠ Ġsize Ġ= ĠSize ( width , Ġheight ), ĊĠĠĠ ĠfileSize Ġ= ĠfileSize ) Ċ Ċ private Ġfun ĠDownload Info Entity . to Download Info (): ĠDownload Info Ġ= ĊĠĠĠ ĠDownload Info ( download Url Ġ= Ġdownload Url , Ġsize Ġ= Ġsize , ĠfileSize Ġ= ĠfileSize ) Ċ