/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 6 Ġsky do ves Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . sky do ves . water days . ui . activities . main Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . app . Alarm Manager Ċ import Ġandroid . app . Pending Intent Ċ import Ġandroid . content . Component Name Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . Intent Filter Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . n fc . N def Message Ċ import Ġandroid . n fc . N fc Adapter Ċ import Ġandroid . os . Bundle Ċ import Ġcom . sky do ves . water days . R Ċ import Ġcom . sky do ves . water days . compose . Base Activity Ċ import Ġcom . sky do ves . water days . compose . qual ifiers . Require Presenter Ċ import Ġcom . sky do ves . water days . consts . Intent Extras Ċ import Ġcom . sky do ves . water days . events . rx . Rx Update Main Event Ċ import Ġcom . sky do ves . water days . present ers . Main Presenter Ċ import Ġcom . sky do ves . water days . services . re ceiv ers . Alarm Boot Receiver Ċ import Ġcom . sky do ves . water days . services . re ceiv ers . Local Weather Receiver Ċ import Ġcom . sky do ves . water days . ui . adapters . Sections Pager Adapter Ċ import Ġcom . sky do ves . water days . utils . Navigation Utils Ċ import Ġcom . sky do ves . water days . view Types . MainActivity View Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġkotlinx . android . synt hetic . main . activity _ main .* Ċ import Ġjava . util . G regorian Calendar Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġsky do ves Ġon Ġ 2 0 1 6 - 1 0 - 1 5 . Ċ Ġ* ĠUpdated Ġby Ġsky do ves Ġon Ġ 2 0 1 7 - 0 8 - 1 7 . Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 1 7 Ġsky do ves Ġrights Ġreserved . Ċ Ġ*/ Ċ Ċ @ Require Presenter ( Main Presenter :: class ) Ċ class ĠMainActivity Ġ: ĠBase Activity < Main Presenter , ĠMainActivity View >(), ĠMainActivity View Ġ{ ĊĊĠ Ġprivate Ġvar Ġn Adapter : ĠN fc Adapter ? Ġ= Ġnull ĊĠ Ġprivate Ġlateinit Ġvar Ġm Sections Pager Adapter : ĠSe ctions Pager Adapter ĊĊĠ Ġ@ Suppress Lint (" Check Result ") ĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠ Ġinit Base View ( this ) ĊĊĠĠĠ Ġn Adapter Ġ= ĠN fc Adapter . getDefault Adapter ( this ) ĊĠĠĠ Ġget N FC Data ( intent ) ĊĊĠĠĠ Ġ// Ġauto Ġweather Ġalarm ĊĠĠĠ Ġweather Alarm () ĊĊĠĠĠ Ġ// Ġset Ġboot Ġreceiver ĊĠĠĠ Ġval Ġreceiver Ġ= ĠComponent Name ( this , ĠAlarm Boot Receiver :: class . java ) ĊĠĠĠ Ġval Ġpm Ġ= Ġpackage Manager ĊĠĠĠ Ġpm . set Component Enabled Setting ( receiver , ĠPackage Manager . COMPONENT _ ENABLED _ STATE _ ENABLED , ĠPackage Manager . D ONT _ KILL _ APP ) ĊĊĠĠĠ ĠRx Update Main Event . getInstance (). observable ĊĠĠĠĠĠĠĠ Ġ. compose ( bind To Lifecycle < Boolean >()) ĊĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠ Ġ. subscribe Ġ{ Ġflag Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ(! flag ) Ġshow Badge ( 1 ) ĊĠĠĠĠĠĠĠĠĠ Ġm Sections Pager Adapter . notify DataSet Changed () ĊĠĠĠĠĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġinitialize UI () Ġ{ ĊĠĠĠ Ġm Sections Pager Adapter Ġ= ĠSe ctions Pager Adapter ( support FragmentManager ) ĊĠĠĠ Ġmain activity _ view pager . adapter Ġ= Ġm Sections Pager Adapter ĊĠĠĠ Ġmain activity _ view pager . off screen Page Limit Ġ= Ġ 5 ĊĠĠĠ ĠNavigation Utils . set Components ( base Context , Ġmain activity _ view pager , Ġmain activity _ nav i ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġshow Ġbadge Ġwith Ġdelay ĊĠĠ Ġ* Ġ@ param Ġposition ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun Ġshow Badge ( position : ĠInt ) Ġ{ ĊĠĠĠ Ġmain activity _ nav i . post Delayed ({ ĊĠĠĠĠĠ Ġval Ġmodel Ġ= Ġmain activity _ nav i . models [ position ] ĊĠĠĠĠĠ Ġmain activity _ nav i . post Delayed ({ Ġmodel . show Badge () Ġ}, Ġ 1 0 0 ) ĊĠĠĠ Ġ}, Ġ 2 0 0 ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget N FC Data ( intent : ĠIntent ) Ġ{ ĊĠĠĠ Ġif Ġ( N fc Adapter . ACTION _ N DEF _ DIS COVER ED Ġ== Ġget Intent (). action ) Ġ{ ĊĠĠĠĠĠ Ġval Ġraw Msgs Ġ= Ġintent . get Parcelable Array Extra ( N fc Adapter . EXTRA _ N DEF _ MESSAGES ) ĊĠĠĠĠĠ Ġif Ġ( raw Msgs Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessages Ġ= ĠarrayOf Null s < N def Message >( raw Msgs . size ) ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġraw Msgs . indices ) ĊĠĠĠĠĠĠĠĠĠ Ġmessages [ i ] Ġ= Ġraw Msgs [ i ] Ġas ĠN def Message ĊĠĠĠĠĠĠĠ Ġval Ġpayload Ġ= Ġmessages [ 0 ] !!. get Records ()[ 0 ]. payload ĊĊĠĠĠĠĠĠĠ Ġpresenter . add Record ( String ( payload )) ĊĠĠĠĠĠĠĠ Ġm Sections Pager Adapter !!. notify DataSet Changed () ĊĠĠĠĠĠĠĠ Ġshow Badge ( 1 ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠ Ġsuper . on Resume () ĊĠĠĠ Ġval Ġfilter Ġ= ĠIntent Filter ( N fc Adapter . ACTION _ N DEF _ DIS COVER ED ) ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġfilter . add DataType (" water days _ n fc /* ") ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġe . printStackTrace () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġi Ġ= ĠIntent ( this , Ġjava Class ) ĊĠĠĠ Ġi . flags Ġ= ĠIntent . FLAG _ ACTIVITY _ SINGLE _ TOP ĊĠĠĠ Ġval Ġp Intent Ġ= ĠPending Intent . getActivity ( this , Ġ 0 , Ġi , Ġ 0 ) ĊĊĠĠĠ Ġval Ġfilters Ġ= ĠarrayOf ( filter ) ĊĠĠĠ Ġn Adapter !!. enable Foreground Dispatch ( this , Ġp Intent , Ġfilters , Ġnull ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon New Intent ( intent : ĠIntent ) Ġ{ ĊĠĠĠ Ġsuper . on New Intent ( intent ) ĊĠĠĠ Ġset Intent ( intent ) ĊĠĠĠ Ġget N FC Data ( get Intent ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġweather Alarm () Ġ{ ĊĠĠĠ Ġif Ġ(! presenter . weather Alarm ) Ġ{ ĊĠĠĠĠĠ Ġval Ġm Calendar Ġ= ĠG regorian Calendar () ĊĠĠĠĠĠ Ġval Ġalarm Manager Ġ= Ġget System Service ( Context . ALARM _ SERVICE ) Ġas ĠAlarm Manager ĊĠĠĠĠĠ Ġalarm Manager . set In exact Repe ating ( Alarm Manager . RTC _ WAKE UP , Ġm Calendar . time In Millis , Ġ( 1 2 0 0 Ġ* Ġ 1 0 0 0 ). to Long (), Ġpending Intent ( Intent Extras . ALARM _ PENDING _ REQUEST _ CODE )) ĊĠĠĠĠĠ Ġpresenter . weather Alarm Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġpending Intent ( request Code : ĠInt ): ĠPending Intent Ġ{ ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( this , ĠLocal Weather Receiver :: class . java ) ĊĠĠĠ Ġintent . putExtra ( Intent Extras . ALARM _ PENDING _ REQUEST , Ġrequest Code ) ĊĠĠĠ Ġreturn ĠPending Intent . get Broadcast ( this , Ġrequest Code , Ġintent , Ġ 0 ) ĊĠ Ġ} Ċ } Ċ