package Ġcom . example . inst ab us . stations Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Context Ċ import Ġandroid . net . Connectivity Manager Ċ import Ġandroidx . annotation . Worker Thread Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġcom . example . inst ab us . models . Station Ċ import Ġcom . squareup . mos hi . M oshi Ċ import Ġcom . squareup . mos hi . kotlin . reflect . Kotlin Json Adapter Factory Ċ import Ġkotlinx . coroutines . Coroutine Scope Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . launch Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . converter . mos hi . M oshi Converter Factory Ċ import Ġcom . example . inst ab us . WEB _ SERVICE _ URL Ċ Ċ class ĠStation Repository Ġ( val Ġapp : ĠApplication ) Ġ{ ĊĠĠĠ Ġval Ġstation data Ġ= ĠMutable LiveData < List < Station >>() ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ ĠCor outine Scope ( Dispatch ers . IO ). launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcall web service () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġcall web service (){ ĊĠĠĠĠĠĠĠ Ġval Ġm oshi = M oshi . Builder (). add ( Kotlin Json Adapter Factory ()). build () ĊĠĠĠĠĠĠĠ Ġval Ġretrofit Ġ= ĠRet rofit . Builder (). baseUrl ( WEB _ SERVICE _ URL ). add Converter Factory ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠM oshi Converter Factory . create ( mos hi )). build () ĊĠĠĠĠĠĠĠ Ġval Ġservice Ġ= Ġretrofit . create ( St ations Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġval Ġservice Data Ġ= service . get Station Data (). body () ĊĠĠĠĠĠĠĠ Ġstation data . post Value ( service Data ?. near St ations ?. stations ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠ Ġprivate Ġfun Ġnetwork Available (): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconnectivity Manager Ġ= Ġapp . getSystem Service ( Context . CONNECT IVITY _ SERVICE ) Ġas ĠConnect ivity Manager ĊĠĠĠĠĠĠĠ Ġval Ġnetwork Info Ġ= Ġconnectivity Manager . active Network Info ĊĠĠĠĠĠĠĠ Ġreturn Ġnetwork Info ?. isConnected Or Connecting ?: false ĊĠĠĠ Ġ} Ċ } Ċ