package Ġorg . s ugar andro se . app . data . remote Ċ Ċ import Ġandroid . content . Context Ċ import Ġio . reactivex . Single Ċ import Ġorg . s ugar andro se . app . data . model . remote . Category Ċ import Ġorg . s ugar andro se . app . data . model . remote . More Ċ import Ġorg . s ugar andro se . app . data . model . remote . Post Ċ import Ġorg . s ugar andro se . app . data . model . remote . Ro ses Ċ import Ġorg . s ugar andro se . app . util . exceptions . Network Unavailable Exception Ċ import Ġorg . s ugar andro se . app . util . extensions . is Network Available Ċ import Ġretrofit 2 . adapter . rx java 2 . Result Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠFl orian ĠSch uster Ċ Ġ* Ġfl orian . sch uster @ ta ilo red - apps . com Ċ Ġ*/ Ċ Ċ class ĠApi Network Availability Wrapper ( private Ġval Ġapi : ĠS ugar And R ose Api , Ġprivate Ġval Ġcontext : ĠContext ) Ġ: ĠS ugar And R ose Api Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġget Posts From Deep Link ( query : ĠString ): ĠSingle < List < Post >> Ġ= Ġload With Network Un availability Detection ( api . get Posts From Deep Link ( query )) ĊĠĠĠ Ġoverride Ġfun Ġget Post ( id : ĠLong ): ĠSingle < Post > Ġ= Ġload With Network Un availability Detection ( api . getPost ( id )) ĊĠĠĠ Ġoverride Ġfun Ġget Posts ( page : ĠInt , Ġper Page : ĠInt ): ĠSingle < Result < List < Post >>> Ġ= Ġload With Network Un availability Detection ( api . get Posts ( page , Ġper Page )) ĊĠĠĠ Ġoverride Ġfun Ġget Posts For Query ( query : ĠString , Ġpage : ĠInt , Ġper Page : ĠInt ): ĠSingle < Result < List < Post >>> Ġ= Ġload With Network Un availability Detection ( api . get Posts For Query ( query , Ġpage , Ġper Page )) ĊĠĠĠ Ġoverride Ġfun Ġget Categories (): ĠSingle < List < Category >> Ġ= Ġload With Network Un availability Detection ( api . getC ategories ()) ĊĠĠĠ Ġoverride Ġfun Ġget Posts For Category ( id : ĠInt , Ġpage : ĠInt , Ġper Page : ĠInt ): ĠSingle < Result < List < Post >>> Ġ= Ġload With Network Un availability Detection ( api . get Posts For Category ( id , Ġpage , Ġper Page )) ĊĠĠĠ Ġoverride Ġfun Ġget Ro ses (): ĠSingle < Ro ses > Ġ= Ġload With Network Un availability Detection ( api . get Ro ses ()) ĊĠĠĠ Ġoverride Ġfun Ġget More ( id : ĠLong ): ĠSingle < More > Ġ= Ġload With Network Un availability Detection ( api . get More ( id )) ĊĊĠĠĠ Ġprivate Ġfun Ġ< T > Ġload With Network Un availability Detection ( loading Single : ĠSingle < T >): ĠSingle < T > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( context . is Network Available ) Ġloading Single Ġelse ĠSingle . error ( Network Unavailable Exception ()) Ċ } Ċ