package Ġcom . example . watcher . fragments Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . EditText Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . example . watcher . R Ċ import Ġcom . example . watcher . adapters . Recycler Adapter Ċ import Ġcom . example . watcher . helpers . Location Service Ċ import Ġcom . example . watcher . helpers . SMS Ċ import Ġcom . example . watcher . model . Broadcast Ċ import Ġcom . example . watcher . types . Broadcast ListType Ċ import Ġcom . example . watcher . types . Broadcast Type Ċ import Ġcom . google . android . material . floating action button . Floating ActionButton Ċ import Ġkotlinx . android . synt hetic . main . broadcast _ item _ row . view .* ĊĊ Ċ class ĠBroadcast Fragment Ġ: ĠFragment () Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlinear LayoutManager : ĠLinearLayoutManager ĊĠĠĠ Ġprivate Ġvar Ġadapter : ĠRe cycler Adapter < Broadcast Type >? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval Ġmessage View Id Ġ= ĠView . generate View Id () ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠInf late Ġthe Ġlayout Ġfor Ġthis Ġfragment ĊĠĠĠĠĠĠĠ Ġval Ġview : ĠView Ġ= Ġinflater . inflate ( R . layout . fragment _ broadcast , Ġcontainer , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġshow Broad Cast List ( view ) ĊĠĠĠĠĠĠĠ Ġadd Event Listeners ( view ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġview ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Broad Cast List ( view : ĠView ): ĠRecyclerView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbroad Cast s Ġ= ĠgetAll Broadcast List () ĊĠĠĠĠĠĠĠ Ġvar Ġre cyclerView : ĠRecyclerView ? Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġif ( broad Cast s . size Ġ> Ġ 0 Ġ|| Ġadapter Ġ== Ġnull ) Ġre cyclerView Ġ= Ġshow Broadcast Recycler ( view , Ġbroad Cast s ) ĊĊĠĠĠĠĠĠĠ Ġif ( broad Cast s . size Ġ<= Ġ 0 ) Ġview . findViewById < View >( R . id . no _ broadcast ). visibility Ġ= ĠView . VISIBLE ĊĊĠĠĠĠĠĠĠ Ġreturn Ġre cyclerView ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetAll Broadcast List () Ġ= Ġ ĠBroadcast . get Broadcast (" all ", Ġcontext Ġas ĠContext ) ĊĠĠĠ Ġprivate Ġfun Ġshow Broadcast Recycler ( view : ĠView , Ġbroadcast s : ĠBroadcast ListType ): ĠRecyclerView Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġre cyclerView : ĠRecyclerView Ġ= Ġview . findViewById ( R . id . no _ broadcast _ recycler _ view ) ĊĊĊĠĠĠĠĠĠĠ Ġlinear LayoutManager Ġ= ĠLinearLayoutManager ( activity ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= Ġlinear LayoutManager ĊĊĠĠĠĠĠĠĠ Ġadapter Ġ= ĠRe cycler Adapter < Broadcast Type >( broadcast s , ĠR . layout . broadcast _ item _ row ) Ġ{ Ġitem , Ġview Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview . current _ date . text Ġ= Ġitem . createdAt ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview . broadcast _ message . text Ġ= Ġitem . message ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . i (" REC Y CL ER ĠB IND ", Ġ"${ view . toString ()}, Ġ${ item . toString () }") ĊĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ Ġreturn Ġre cyclerView ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġadd New Broadcast ( dialog : ĠAlertDialog ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġem ergency Text Ġ= Ġdialog ?. findViewById < EditText >( message View Id ) ĊĠĠĠĠĠĠĠ Ġval Ġbroadcast Ġ= ĠBroadcast . new Broadcast ( em ergency Text ?. text . toString (), Ġcontext Ġas ĠContext ) ĊĠĠĠĠĠĠĠ ĠLog . i (" Broadcast ", Ġbroadcast . toString ()) ĊĊĠĠĠĠĠĠĠ ĠSMS . send ( broadcast . message , Ġcontext Ġas ĠContext ) ĊĠĠĠĠĠĠĠ Ġadapter ?. update Adapter ( getAll Broadcast List ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Alert ( view : ĠView , Ġlocation : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠAlertDialog . Builder ( context Ġas ĠContext ) ĊĠĠĠĠĠĠĠ Ġvar Ġdialog : ĠAlertDialog ? Ġ= Ġnull ĊĊĠĠĠĠĠĠĠ Ġbuilder . setView ( get E mergency Message View ( location )) ĊĊĠĠĠĠĠĠĠ Ġbuilder . setTitle (" Watcher ĠE mergency ĠMessage ") ĊĠĠĠĠĠĠĠ Ġbuilder . setMessage (" You Ġcan ĠEdit Ġthis Ġmessage . ĠClick Ġsend Ġwhen Ġdone ") ĊĠĠĠĠĠĠĠ Ġbuilder . set Positive Button (" Send ") Ġ{ _, Ġ_ Ġ-> Ġadd New Broadcast ( dialog )} ĊĠĠĠĠĠĠĠ Ġbuilder . set Neutral Button (" Cancel ", Ġnull ) ĊĠĠĠĠĠĠĠ Ġdialog Ġ= Ġbuilder . create () ĊĊĠĠĠĠĠĠĠ Ġdialog . show () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget E mergency Message View ( extra Text : ĠString ): ĠView Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġedit Text Ġ= ĠEditText ( context ) ĊĠĠĠĠĠĠĠ Ġedit Text . id Ġ= Ġmessage View Id ĊĠĠĠĠĠĠĠ Ġedit Text . setText ("${ Location Service . get E mergency Message ()}. ĠCheckout ĠLocation Ġ$ extra Text ") ĊĊĠĠĠĠĠĠĠ Ġreturn Ġedit Text ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget E mergency Message (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ" I Ġneed Ġyour Ġassistance Ġright Ġnow . ĠAttach Ġis Ġmy Ġcurrent Ġlocation . ĠThanks " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Location On Google Map ( lat : ĠString , Ġlong : ĠString ): ĠString Ġ= Ġ" https :// www . google . com / maps / place /$ lat , Ġ$ long " ĊĊĠĠĠ Ġprivate Ġfun Ġnew Broadcast ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ ĠLog . i (" Broadcast ", Ġ" new ĠBroadcast ") ĊĠĠĠĠĠĠĠ ĠLocation Service ( context Ġas ĠContext , Ġactivity Ġas ĠActivity ). getCurrent Location Ġ{ lat , Ġlong Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . i (" returned Ġlocation ", Ġ"$ long , Ġ$ lat ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow Alert ( view , ĠLocation Service . getLocation On Google Map ( lat , Ġlong )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġadd Event Listeners ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew Broadcast Button : ĠFloating ActionButton Ġ= Ġview . findViewById ( R . id . new _ broadcast ) ĊĊĠĠĠĠĠĠĠ Ġnew Broadcast Button . setOnClickListener { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnew Broadcast ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} Ċ } Ċ