package Ġmil . ng a . gi at . mage . observation . view Ċ Ċ import Ġandroid . content . Clip Data Ċ import Ġandroid . content . Clipboard Manager Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . View Ċ import Ġandroidx . activity . compose . setContent Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġcom . google . android . gms . maps . model . LatLng Ċ import Ġcom . google . android . material . bottom sheet . Bottom Sheet Dialog Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ import Ġdagger . h ilt . android . Android EntryPoint Ċ import Ġkotlinx . android . synt hetic . main . view _ more _ bottom _ sheet . view .* Ċ import Ġmil . ng a . gi at . mage . R Ċ import Ġmil . ng a . gi at . mage . form . Form State Ċ import Ġmil . ng a . gi at . mage . form . Form ViewModel Ċ import Ġmil . ng a . gi at . mage . form . edit . dialog . Form Re order Dialog Ċ import Ġmil . ng a . gi at . mage . observation . Attachment Viewer Activity Ċ import Ġmil . ng a . gi at . mage . observation . edit . Observation Edit Activity Ċ import Ġmil . ng a . gi at . mage . people . People Activity Ċ import Ġmil . ng a . gi at . mage . sdk . datastore . observation . Attachment Ċ import Ġmil . ng a . gi at . mage . sdk . datastore . user . Permission Ċ import Ġmil . ng a . gi at . mage . sdk . datastore . user . User Ċ import Ġmil . ng a . gi at . mage . sdk . datastore . user . User Helper Ċ Ċ @ Android EntryPoint Ċ class ĠOb servation View Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġval ĠLOG _ NAME Ġ= ĠOb servation View Activity :: class . java . name ĊĊĠĠĠ Ġconst Ġval ĠOB SERV ATION _ ID Ġ= Ġ" OB SERV ATION _ ID " ĊĠĠĠ Ġconst Ġval ĠINITIAL _ LOCATION Ġ= Ġ" INITIAL _ LOCATION " ĊĠĠĠ Ġconst Ġval ĠINITIAL _ ZO OM Ġ= Ġ" INITIAL _ ZO OM " ĊĠ Ġ} ĊĊĠ Ġprivate Ġvar ĠcurrentUser : ĠUser ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġhas Event Update Permission Ġ= Ġfalse ĊĊĠ Ġprivate Ġvar Ġdefault Map Zoom : ĠFloat ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġdefault Map Center : ĠLat Lng ? Ġ= Ġnull ĊĊĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠForm ViewModel ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĊĠĠĠ ĠviewModel Ġ= ĠViewModel Provider ( this ). get ( Form ViewModel :: class . java ) ĊĊĠĠĠ Ġdefault Map Zoom Ġ= Ġintent . get Float Extra ( INITIAL _ ZO OM , Ġ 0 . 0 f ) ĊĠĠĠ Ġdefault Map Center Ġ= Ġintent . get Parcelable Extra ( INITIAL _ LOCATION ) Ġ?: ĠLat Lng ( 0 . 0 , Ġ 0 . 0 ) ĊĊĠĠĠ Ġrequire ( intent ?. getLong Extra ( OB SERV ATION _ ID , Ġ- 1 L ) Ġ!= Ġ- 1 L ) Ġ{ Ġ" OB SERV ATION _ ID Ġis Ġrequired Ġto Ġlaunch ĠOb servation View Activity " Ġ} ĊĠĠĠ Ġval Ġobservation Id Ġ= Ġintent . getLong Extra ( OB SERV ATION _ ID , Ġ- 1 L ) ĊĠĠĠ ĠviewModel . set Observation ( observation Id , Ġobserve Changes Ġ= Ġtrue , Ġdefault Map Zoom , Ġdefault Map Center ) ĊĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠcurrentUser Ġ= ĠUser Helper . getInstance ( this ). read CurrentUser () ĊĠĠĠĠĠ Ġhas Event Update Permission Ġ= ĠcurrentUser ?. role ?. permissions ?. permissions ?. contains ( Permission . UPDATE _ EVENT ) Ġ?: Ġfalse ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ ĠLog . e ( LOG _ NAME , Ġ" Cannot Ġread Ġcurrent Ġuser ") ĊĠĠĠ Ġ} ĊĠĠĠĠĊĠĠĠ Ġset Content Ġ{ ĠĊĠĠĠĠĠ ĠOb servation View Screen ( ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠviewModel , ĊĠĠĠĠĠĠĠ ĠonClose Ġ= Ġ{ Ġfinish () Ġ}, ĊĠĠĠĠĠĠĠ Ġon Action Ġ= Ġ{ Ġon Action ( it ) Ġ}, ĊĠĠĠĠĠĠĠ Ġon Location Click Ġ= Ġ{ Ġon Location Click ( it ) Ġ}, ĊĠĠĠĠĠĠĠ Ġon Attachment Click Ġ= Ġ{ Ġon Attachment Click ( it ) Ġ} ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Action ( action : ĠOb servation Action ) Ġ{ ĊĠĠĠ Ġwhen Ġ( action ) Ġ{ ĊĠĠĠĠĠ Ġis ĠOb servation Action . Edit Ġ-> Ġon Edit Observation () ĊĠĠĠĠĠ Ġis ĠOb servation Action . Important Ġ-> Ġon Flag Observation ( action ) ĊĠĠĠĠĠ Ġis ĠOb servation Action . Favorite Ġ-> Ġon Favorite Observation () ĊĠĠĠĠĠ Ġis ĠOb servation Action . Favorite By Ġ-> Ġon F avor ited By () ĊĠĠĠĠĠ Ġis ĠOb servation Action . Directions Ġ-> Ġon Directions () ĊĠĠĠĠĠ Ġis ĠOb servation Action . More Ġ-> Ġon More () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Edit Observation () Ġ{ ĊĠĠĠ Ġif Ġ(! User Helper . getInstance ( application Context ). is CurrentUser Part Of Current Event ) Ġ{ ĊĠĠĠĠĠ ĠAlertDialog . Builder ( this ) ĊĠĠĠĠĠĠĠ Ġ. setTitle (" Not Ġa Ġmember Ġof Ġthis Ġevent ") ĊĠĠĠĠĠĠĠ Ġ. setMessage (" You Ġare Ġan Ġadministrator Ġand Ġnot Ġa Ġmember Ġof Ġthe Ġcurrent Ġevent . Ġ ĠYou Ġcan Ġnot Ġedit Ġthis Ġobservation .") ĊĠĠĠĠĠĠĠ Ġ. set Positive Button ( android . R . string . ok ) Ġ{ Ġ_, Ġ_ Ġ-> Ġ}. show () ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( this , ĠOb servation Edit Activity :: class . java ) ĊĠĠĠ Ġintent . putExtra ( Observation Edit Activity . OB SERV ATION _ ID , ĠviewModel . observation . value ?. id ) ĊĠĠĠ Ġintent . putExtra ( Observation Edit Activity . INITIAL _ LOCATION , Ġdefault Map Center ) ĊĠĠĠ Ġintent . putExtra ( Observation Edit Activity . INITIAL _ ZO OM , Ġdefault Map Zoom ) ĊĊĠĠĠ ĠstartActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Flag Observation ( action : ĠOb servation Action . Important ) Ġ{ ĊĠĠĠ Ġif Ġ( action . type Ġ== ĠOb servation Action . Important . Type . FLAG ) Ġ{ ĊĠĠĠĠĠ ĠviewModel . flag Observation ( action . description ) ĊĠĠĠ Ġ} Ġelse Ġif Ġ( action . type Ġ== ĠOb servation Action . Important . Type . REMOVE ) Ġ{ ĊĠĠĠĠĠ ĠviewModel . un flag Observation () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon F avor ited By () Ġ{ ĊĠĠĠ Ġval Ġuser Ids Ġ= ĠviewModel . observation . value ?. favorites ?. map Ġ{ Ġit . userId Ġ} Ġ?: ĠlistOf () ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( this , ĠPeople Activity :: class . java ) ĊĠĠĠ Ġintent . putString ArrayList Extra ( People Activity . USER _ REMOTE _ IDS , ĠArrayList ( user Ids )) ĊĠĠĠ ĠstartActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Favorite Observation () Ġ{ ĊĠĠĠ ĠviewModel . toggle Favorite () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Directions () Ġ{ ĊĠĠĠ Ġval Ġobservation Ġ= ĠviewModel . observation . value ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( Intent . ACTION _ VIEW , Ġobservation ?. google Maps Uri ) ĊĠĠĠ ĠstartActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Location Click ( location : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġclipboard Ġ= Ġget System Service ( CLIP BOARD _ SERVICE ) Ġas ĠClip board Manager ĊĠĠĠ Ġval Ġclip Ġ= ĠClip Data . new Plain Text (" Observation ĠLocation ", Ġlocation ) ĊĠĠĠ Ġif Ġ( clipboard Ġ== Ġnull Ġ|| Ġclip Ġ== Ġnull ) Ġreturn ĊĠĠĠ Ġclipboard . set Primary Clip ( clip ) ĊĊĠĠĠ ĠSn ackbar . make ( findViewById ( android . R . id . content ), ĠR . string . location _ text _ copy _ message , ĠSn ackbar . LENGTH _ SHORT ). show () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Attachment Click ( attachment : ĠAttachment ) Ġ{ ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( application Context , ĠAttachment Viewer Activity :: class . java ) ĊĠĠĠ Ġintent . putExtra ( Attachment Viewer Activity . ATTACHMENT _ ID , Ġattachment . id ) ĊĠĠĠ Ġintent . putExtra ( Attachment Viewer Activity . EDIT ABLE , Ġfalse ) ĊĠĠĠ ĠstartActivity ( intent ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon More () Ġ{ ĊĠĠĠ Ġval Ġdialog Ġ= ĠBottom Sheet Dialog ( this ) ĊĠĠĠ Ġval Ġview Ġ= Ġlayout Inflater . inflate ( R . layout . view _ more _ bottom _ sheet , Ġnull ) ĊĊĠĠĠ Ġval Ġform Count Ġ= ĠviewModel . observation State . value ?. forms ?. value ?. size Ġ?: Ġ 0 ĊĠĠĠ Ġview . reorder . visibility Ġ= Ġif Ġ( form Count Ġ> Ġ 1 ) ĠView . VISIBLE Ġelse ĠView . GONE ĊĊĠĠĠ Ġview . delete . setOnClickListener Ġ{ ĊĠĠĠĠĠ ĠonDelete Observation () ĊĠĠĠĠĠ Ġdialog . dismiss () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġview . edit . setOnClickListener Ġ{ ĊĠĠĠĠĠ Ġon Edit Observation () ĊĠĠĠĠĠ Ġdialog . dismiss () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġview . reorder . setOnClickListener Ġ{ ĊĠĠĠĠĠ Ġdialog . dismiss () ĊĠĠĠĠĠ Ġval Ġreorder Dialog Ġ= ĠForm Re order Dialog . newInstance () ĊĠĠĠĠĠ Ġreorder Dialog . listener Ġ= Ġobject Ġ: ĠForm Re order Dialog . Form Re order Dialog Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Re order ( forms : ĠList < Form State >) Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠviewModel . reorder Forms ( forms ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġreorder Dialog . show ( support FragmentManager , Ġ" DIALOG _ FORM _ RE ORDER ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġdialog . set ContentView ( view ) ĊĠĠĠ Ġdialog . show () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠonDelete Observation () Ġ{ ĊĠĠĠ ĠAlertDialog . Builder ( this ) ĊĠĠĠĠĠ Ġ. setTitle (" Delete ĠOb servation ") ĊĠĠĠĠĠ Ġ. setMessage (" Are Ġyou Ġsure Ġyou Ġwant Ġto Ġremove Ġthis Ġobservation ?") ĊĠĠĠĠĠ Ġ. set Positive Button (" Delete ") Ġ{ Ġ_, Ġ_ Ġ-> ĊĠĠĠĠĠĠĠ ĠviewModel . delete Observation () ĊĠĠĠĠĠĠĠ Ġfinish () ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. set Negative Button ( android . R . string . cancel , Ġnull ) ĊĠĠĠĠĠ Ġ. show () ĊĠ Ġ} Ċ }