package Ġcom . example . die goal vis . food finder Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . List Fragment Ċ import Ġcom . die goal vis . android . news app . api . ApiClient Ċ import Ġcom . example . die goal vis . food finder . fragments . My Map Fragment Ċ import Ġcom . example . die goal vis . food finder . fragments . Restaurant List Fragment Ċ import Ġcom . example . die goal vis . food finder . utils . add Ċ import Ġcom . example . die goal vis . food finder . utils . apply UIS chedulers Ċ import Ġcom . example . die goal vis . food finder . utils . hide Ċ import Ġcom . example . die goal vis . food finder . utils . replace Ċ import Ġcom . example . die goal vis . food finder . utils . show Ċ import Ġcom . github . pw itt chen . react iven etwork . library . rx 2 . Reactive Network Ċ import Ġcom . google . android . material . bottomnavigation . Bottom Navigation View Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ import Ġio . reactivex . Observable Ċ import Ġkotlinx . android . synt hetic . main . activity _ main .* Ċ import Ġkotlinx . android . synt hetic . main . fragment _ list _ restaurant .* Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity (), ĠRest aurant List Fragment . On Search Listener Ġ{ ĊĊĠ Ġprivate Ġval Ġmap Fragment Ġ= ĠMy Map Fragment . newInstance () ĊĠ Ġprivate Ġval Ġlist Fragment Ġ= ĠRest aurant List Fragment . newInstance () ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĠĠĠ Ġnavigation . setOn Navigation ItemSelected Listener ( m On Navigation ItemSelected Listener ) ĊĊĠĠĠ Ġlist Fragment . on Search Listener Ġ= Ġthis ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Search () Ġ{ ĊĠĠĠ Ġsupport FragmentManager . hide ( list Fragment ) ĊĠĠĠ Ġsupport FragmentManager . show ( map Fragment ) ĊĠĠĠ Ġnavigation . selected ItemId Ġ= ĠR . id . navigation _ map ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠ Ġsuper . on Resume () ĊĠĠĠ Ġ// Ġinitial Ġview ĊĠĠĠ Ġsupport FragmentManager . add ( R . id . container , Ġmap Fragment , ĠMy Map Fragment . TAG ) ĊĠĠĠ Ġsupport FragmentManager . add ( R . id . container , Ġlist Fragment , ĠRest aurant List Fragment . TAG ) ĊĠĠĠ Ġsupport FragmentManager . hide ( map Fragment ) ĊĊĠĠĠ Ġset Access Internet Observer () ĊĠ Ġ} ĊĊĠ Ġ@ Suppress Lint (" Check Result ") ĊĠ Ġprivate Ġfun Ġset Access Internet Observer () Ġ{ ĊĠĠĠ Ġval Ġconnection State Ġ= ĠSn ackbar . make ( container , Ġ" No ĠInternet Ġconnection .", ĠSn ackbar . LENGTH _ IN DEFIN ITE ). setAction (" CLOSE ") Ġ{ Ġ} ĊĠĠĠ ĠObservable . interval ( 1 , Ġ 1 0 , ĠTimeUnit . SECONDS ) ĊĠĠĠĠĠ Ġ. flatMap Ġ{ ĠReactive Network . observe Internet Connectivity () Ġ} ĊĠĠĠĠĠ Ġ. apply UIS chedulers () ĊĠĠĠĠĠ Ġ. subscribe ({ Ġis Connected Ġ-> ĊĠĠĠĠĠĠĠ Ġif Ġ( isConnected ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġconnection State . dismiss () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġif Ġ(! connection State . is Shown ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġconnection State . show () ĊĠĠĠĠĠĠĠĠĠ Ġprogress . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠĠĠ ĠToast . makeText ( this , Ġ" Error Ġwhen Ġtrying Ġto Ġget Ġconnection Ġstatus ", ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġm On Navigation ItemSelected Listener Ġ= ĠBottom Navigation View . On Navigation ItemSelected Listener Ġ{ Ġitem Ġ-> ĊĠĠĠ Ġwhen Ġ( item . itemId ) Ġ{ ĊĠĠĠĠĠ ĠR . id . navigation _ list Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . show ( list Fragment ) ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . hide ( map Fragment ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠR . id . navigation _ map Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . hide ( list Fragment ) ĊĠĠĠĠĠĠĠ Ġsupport FragmentManager . show ( map Fragment ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġtrue ĊĠ Ġ} Ċ }