// Ġ ĠCopyright Ġ( c ) Ġ 2 0 1 8 ĠLo up ĠInc . Ċ // Ġ ĠLicensed Ġunder ĠApache ĠLicense Ġv 2 . 0 Ċ Ċ package Ġapp . lo up . geo location Ċ Ċ import Ġapp . lo up . geo location . data . Location Updates Request Ċ import Ġapp . lo up . geo location . data . Permission Ċ import Ġapp . lo up . geo location . data . Permission Request Ċ import Ġapp . lo up . geo location . location . Location Client Ċ import Ġio . flutter . plugin . common . Event Channel Ċ import Ġio . flutter . plugin . common . MethodCall Ċ import Ġio . flutter . plugin . common . Method Channel Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . launch ĊĊ Ċ class ĠHandler ( private Ġval Ġlocation Client : ĠLocation Client ) Ġ: ĠMethod Channel . MethodCall Handler , ĠEvent Channel . Stream Handler Ġ{ ĊĊĊĠ Ġprivate Ġfun Ġis Location Operation al ( permission : ĠPermission , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ Ġresult . success ( Codec . encode Result ( location Client . is Location Operation al ( permission ))) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrequest Location Permission ( permission : ĠPermission Request , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠ Ġresult . success ( Codec . encode Result ( location Client . request Location Permission ( permission ))) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġenable Location Settings ( result : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠ Ġresult . success ( Codec . encode Result ( location Client . enable Location Services ())) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġlast Known Location ( permission : ĠPermission , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠ Ġresult . success ( Codec . encode Result ( location Client . last Known Location ( permission ))) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġadd Location Updates Request ( request : ĠLocation Updates Request ) Ġ{ ĊĠĠĠ ĠGlobal Scope . launch ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠ Ġlocation Client . add Location Updates Request ( request ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġremove Location Updates Request ( id : ĠInt ) Ġ{ ĊĠĠĠ Ġlocation Client . remove Location Updates Request ( id ) ĊĠ Ġ} ĊĊĊĠ Ġ// ĠMethod Channel . MethodCall Handler ĊĊĠ Ġoverride Ġfun Ġon MethodCall ( call : ĠMethod Call , Ġresult : ĠMethod Channel . Result ) Ġ{ ĊĠĠĠ Ġwhen Ġ( call . method ) Ġ{ ĊĠĠĠĠĠ Ġ" is Location Operation al " Ġ-> Ġis Location Operation al ( Codec . decode Permission ( call . arguments ), Ġresult ) ĊĠĠĠĠĠ Ġ" request Location Permission " Ġ-> Ġrequest Location Permission ( Codec . decode Permission Request ( call . arguments ), Ġresult ) ĊĠĠĠĠĠ Ġ" last Known Location " Ġ-> Ġlast Known Location ( Codec . decode Permission ( call . arguments ), Ġresult ) ĊĠĠĠĠĠ Ġ" add Location Updates Request " Ġ-> Ġadd Location Updates Request ( Codec . decode Location Updates Request ( call . arguments )) ĊĠĠĠĠĠ Ġ" remove Location Updates Request " Ġ-> Ġremove Location Updates Request ( Codec . decode Int ( call . arguments )) ĊĠĠĠĠĠ Ġ" enable Location Services " Ġ-> Ġenable Location Settings ( result ) ĊĠĠĠĠĠ Ġelse Ġ-> Ġresult . not Implemented () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĊĠ Ġ// ĠEvent Channel . Stream Handler ĊĊĠ Ġoverride Ġfun Ġon Listen ( arguments : ĠAny ?, Ġevents : ĠEvent Channel . Event Sink ) Ġ{ ĊĠĠĠ Ġlocation Client . register Location Updates Callback Ġ{ Ġresult Ġ-> ĊĠĠĠĠĠ Ġevents . success ( Codec . encode Result ( result )) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Cancel ( arguments : ĠAny ?) Ġ{ ĊĠĠĠ Ġlocation Client . dere gister Location Updates Callback () ĊĠ Ġ} Ċ } Ċ