From 365613be700e4edc181c2af70f08dcd5f1021d72 Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 11 Feb 2021 00:51:01 -0500 Subject: [PATCH 1/7] feature/Basic inspection form UI --- .idea/.name | 1 + .idea/vcs.xml | 6 + app/src/main/AndroidManifest.xml | 1 + .../InspectionForm.java | 128 ++++++++++++++++++ .../home/HomeFragment.java | 10 ++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 148 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..c6e7f40 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +StormWaterUtilityAndroid \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5d437cc..1f7f4e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ + diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java new file mode 100644 index 0000000..d39429e --- /dev/null +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -0,0 +1,128 @@ +package com.sf.stormwaterutilityandroid; + +import android.os.Bundle; +import android.widget.Button; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import me.riddhimanadib.formmaster.FormBuilder; +import me.riddhimanadib.formmaster.model.BaseFormElement; +import me.riddhimanadib.formmaster.model.FormElementPickerDate; +import me.riddhimanadib.formmaster.model.FormElementPickerMulti; +import me.riddhimanadib.formmaster.model.FormElementPickerSingle; +import me.riddhimanadib.formmaster.model.FormElementSwitch; +import me.riddhimanadib.formmaster.model.FormElementTextEmail; +import me.riddhimanadib.formmaster.model.FormElementTextMultiLine; +import me.riddhimanadib.formmaster.model.FormElementTextPhone; +import me.riddhimanadib.formmaster.model.FormElementTextSingleLine; +import me.riddhimanadib.formmaster.model.FormHeader; + +public class InspectionForm extends AppCompatActivity { + private FormBuilder formBuilder; + private RecyclerView recyclerView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sample_fordm); + recyclerView = findViewById(R.id.recyclerView2); + setupForm(); + } + + + private void setupForm() { + formBuilder = new FormBuilder(this, recyclerView); + + + + FormElementTextSingleLine projectTextField = FormElementTextSingleLine.createInstance().setTitle("Project/Contact:").setHint("Enter text here"); + FormElementTextSingleLine addressTextField = FormElementTextSingleLine.createInstance().setTitle("Address/Lot#(s):").setHint("Enter text here"); + FormElementTextSingleLine inspectorTextField = FormElementTextSingleLine.createInstance().setTitle("Inspector:").setHint("Enter name here"); + FormElementPickerDate dataInspectedDatePicker = FormElementPickerDate.createInstance().setTitle("Date Inspected:").setDateFormat("MMM dd, yyyy"); + + + List typeOptions = new ArrayList<>(Arrays.asList( + "Routine Evaluation", + "Re-Inspection", + "Complaint Investigation", + "Entire Development", + "Individual Building Lot(s)" + )); + FormElementPickerSingle inspectionTypePickerSingle = FormElementPickerSingle.createInstance().setTitle("Inspection type:").setOptions(typeOptions).setPickerTitle("Pick inspection type"); + + FormElementSwitch projectRepPresentSwitch = FormElementSwitch.createInstance().setTitle("Project Representative Present?").setSwitchTexts("Yes", "No"); + + FormHeader stakeholdersHeader = FormHeader.createInstance("THE FOLLOWING INDIVIDUALS BECAME AWARE OF ANY ISSUES THOUGH DISCUSSION AND REVIEW OF FINDINGS ON THE DAY OF INSPECTION:"); + FormElementTextSingleLine projectManagerTextField = FormElementTextSingleLine.createInstance().setTitle("Project Manager:").setHint("Enter name here"); + FormElementTextSingleLine siteManagerTextField = FormElementTextSingleLine.createInstance().setTitle("Site Manager:").setHint("Enter name here"); + FormElementTextSingleLine projectOwnerTextField = FormElementTextSingleLine.createInstance().setTitle("Project Owner").setHint("Enter name here"); + + + FormHeader correctiveActionsHeader = FormHeader.createInstance("CORRECTIVE ACTIONS REQUIRED\n***REDER TO APPROVED STORM WATER POLLUTION PREVENTION PLAN (SWP3) FOR SPECIFICATIONS AND DETAILS ON ITEMS BELOW***"); + List correctiveActionsOptions= new ArrayList<>(Arrays.asList( + "Post a laminated copy of completed 327IAC15-5 \"Rule 5\" NOI with permit number at a location visible to the public", + "Remove accumulated sediment from streets sidewalks and gutters (do not flush with water)", + "Install/maintain stable temporary construction entrances(s)", "Entire Development", + "Individual Building Lot(s)", + "Address silt fence issues which includes one or more of the following: Repair, install properly, Replace, Add (areas prone to sheet-flow erosion)", + "Install erosions and sediment control for individual building lot(s) as specified in the approved SWP3", + "Install check dam(s) according to specifications", + "Utilize appropriate construction sequence as specified in the approved SWP3", + "Remove sediment from one or more of the following: sediment traps, behind check dams, around storm drain inlets or/and other", + "Inform Contractors, subcontractors, material vendors, and others or erosion and sediment control requirements", + "Provide copy and self-monitoring inspection records to MS Coordinator within 48 hours", + "Acquire copy of Storm Water Pollution Prevention Plan and retain on project site for reference" + )); + FormElementPickerMulti correctiveActionsPickerMulti = FormElementPickerMulti.createInstance().setTitle("Corrective Actions").setOptions(correctiveActionsOptions).setPickerTitle("Pick corrective action"); + + FormElementTextMultiLine otherCorrectiveAction1TextField = FormElementTextMultiLine.createInstance().setTitle("Other 1:").setHint("Enter text here"); + FormElementTextMultiLine otherCorrectiveAction2TextField = FormElementTextMultiLine.createInstance().setTitle("Other 2:").setHint("Enter text here"); + FormElementTextMultiLine otherCorrectiveAction3TextField = FormElementTextMultiLine.createInstance().setTitle("Other 3:").setHint("Enter text here"); + + + FormHeader enforcementActionHeader = FormHeader.createInstance("ENFORCEMENT ACTIONS"); + List enforcementActionOptions = new ArrayList<>(Arrays.asList( + "Notice of Violation Issued", + "Stop Work Order Issued", + "Fine(s) Issued", + "Other" + )); + FormElementPickerSingle enforcementActionPickerSingle = FormElementPickerSingle.createInstance().setTitle("Inspection type:").setOptions(enforcementActionOptions).setPickerTitle("Pick inspection type"); + + FormElementTextMultiLine evidenceTextField = FormElementTextMultiLine.createInstance().setTitle("Evidence of off-site sediment/pollutants.\nHere is a description of type and location:").setHint("Enter text here"); + + List formItems = new ArrayList<>(); + + formItems.add(projectTextField); + formItems.add(addressTextField); + formItems.add(inspectorTextField); + formItems.add(dataInspectedDatePicker); + + formItems.add(inspectionTypePickerSingle); + formItems.add(projectRepPresentSwitch); + + formItems.add(stakeholdersHeader); + formItems.add(projectManagerTextField); + formItems.add(siteManagerTextField); + formItems.add(projectOwnerTextField); + + formItems.add(correctiveActionsHeader); + formItems.add(correctiveActionsPickerMulti); + formItems.add(otherCorrectiveAction1TextField); + formItems.add(otherCorrectiveAction2TextField); + formItems.add(otherCorrectiveAction3TextField); + + formItems.add(enforcementActionHeader); + formItems.add(enforcementActionPickerSingle); + + formItems.add(evidenceTextField); + + formBuilder.addFormElements(formItems); + + } +} diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/home/HomeFragment.java b/app/src/main/java/com/sf/stormwaterutilityandroid/home/HomeFragment.java index 7809a22..75b11d9 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/home/HomeFragment.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/home/HomeFragment.java @@ -10,6 +10,7 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import com.sf.stormwaterutilityandroid.InspectionForm; import com.sf.stormwaterutilityandroid.R; import com.sf.stormwaterutilityandroid.SampleFordm; @@ -31,6 +32,15 @@ public void onClick(View view) { } }); + b1 = root.findViewById(R.id.button2); + b1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(getContext(), InspectionForm.class)); + } + }); + + //CHeck To5a.03 project for dealing saved instance state /* if (savedInstanceState != null) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 85a4fdb..381a669 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,4 +46,6 @@ Registered Successfully! An email has been sent to verify your email; this must be done before logging in. Sign in + + \ No newline at end of file From 4172104d7214222225be38b84eb11abfcb5feca7 Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 11 Feb 2021 16:24:02 -0500 Subject: [PATCH 2/7] feature/added submit button listener --- .../stormwaterutilityandroid/InspectionForm.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java index d39429e..0098a52 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -1,6 +1,7 @@ package com.sf.stormwaterutilityandroid; import android.os.Bundle; +import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity; @@ -31,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample_fordm); recyclerView = findViewById(R.id.recyclerView2); + setupForm(); } @@ -38,8 +40,6 @@ protected void onCreate(Bundle savedInstanceState) { private void setupForm() { formBuilder = new FormBuilder(this, recyclerView); - - FormElementTextSingleLine projectTextField = FormElementTextSingleLine.createInstance().setTitle("Project/Contact:").setHint("Enter text here"); FormElementTextSingleLine addressTextField = FormElementTextSingleLine.createInstance().setTitle("Address/Lot#(s):").setHint("Enter text here"); FormElementTextSingleLine inspectorTextField = FormElementTextSingleLine.createInstance().setTitle("Inspector:").setHint("Enter name here"); @@ -96,6 +96,15 @@ private void setupForm() { FormElementTextMultiLine evidenceTextField = FormElementTextMultiLine.createInstance().setTitle("Evidence of off-site sediment/pollutants.\nHere is a description of type and location:").setHint("Enter text here"); + Button submitButton = new Button(getApplicationContext()); + submitButton.setText("Submit"); + submitButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + } + }); + List formItems = new ArrayList<>(); formItems.add(projectTextField); @@ -122,7 +131,8 @@ private void setupForm() { formItems.add(evidenceTextField); - formBuilder.addFormElements(formItems); + formBuilder.addFormElements(formItems); + recyclerView.addView(submitButton); } } From 042f8d49b2b873f8a2dad67a0930a996d8f2057c Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Wed, 3 Mar 2021 15:59:14 -0500 Subject: [PATCH 3/7] feature/created constructionFormData class and populated it in actionListener --- .../InspectionForm.java | 160 +++++++++++++----- 1 file changed, 113 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java index d4b0d62..975ca71 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import me.riddhimanadib.formmaster.FormBuilder; @@ -17,9 +18,7 @@ import me.riddhimanadib.formmaster.model.FormElementPickerMulti; import me.riddhimanadib.formmaster.model.FormElementPickerSingle; import me.riddhimanadib.formmaster.model.FormElementSwitch; -import me.riddhimanadib.formmaster.model.FormElementTextEmail; import me.riddhimanadib.formmaster.model.FormElementTextMultiLine; -import me.riddhimanadib.formmaster.model.FormElementTextPhone; import me.riddhimanadib.formmaster.model.FormElementTextSingleLine; import me.riddhimanadib.formmaster.model.FormHeader; @@ -105,49 +104,6 @@ private void setupForm() { FormElementTextMultiLine evidenceTextField = FormElementTextMultiLine.createInstance().setTitle("Evidence of off-site sediment/pollutants.\nHere is a description of type and location:").setHint("Enter text here"); - submitButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - System.out.println("HELLO"); - String projectContact = projectTextField.getValue(); - String address = addressTextField.getValue(); - String inspector = inspectorTextField.getValue(); - String dateInspected = dateInspectedDatePicker.getValue(); - - boolean projectRepPresent = getSwitchBool(projectRepPresentSwitch.getValue()); - - String projectManager = projectManagerTextField.getValue(); - String siteManager = siteManagerTextField.getValue(); - String projectOwner = projectOwnerTextField.getValue(); - - boolean correctiveAction1 = getSwitchBool(correctiveAction1Switch.getValue()); - boolean correctiveAction2 = getSwitchBool(correctiveAction2Switch.getValue()); - boolean correctiveAction3 = getSwitchBool(correctiveAction3Switch.getValue()); - boolean correctiveAction4 = getSwitchBool(correctiveAction4Switch.getValue()); - - List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); - - boolean correctiveAction6 = getSwitchBool(correctiveAction6Switch.getValue()); - boolean correctiveAction7 = getSwitchBool(correctiveAction6Switch.getValue()); - boolean correctiveAction8 = getSwitchBool(correctiveAction8Switch.getValue()); - boolean correctiveAction9 = getSwitchBool(correctiveAction9Switch.getValue()); - - String correctiveAction10 = correctiveAction10Multi.getValue(); - - String otherCorrectiveAction1 = otherCorrectiveAction1TextField.getValue(); - String otherCorrectiveAction2 = otherCorrectiveAction2TextField.getValue(); - String otherCorrectiveAction3 = otherCorrectiveAction3TextField.getValue(); - - List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); - - String evidence = evidenceTextField.getValue(); - - - } - }); - - - List formItems = new ArrayList<>(); formItems.add(projectTextField); @@ -192,13 +148,123 @@ public void onClick(View view) { formItems.add(evidenceTextField); - + // populate formBuilder with items formBuilder.addFormElements(formItems); + // onSubmit + submitButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String contact = projectTextField.getValue(); + String location = addressTextField.getValue(); + String inspector = inspectorTextField.getValue(); + String date = dateInspectedDatePicker.getValue(); + + ArrayList answersList = new ArrayList<>(20); + + boolean projectRepPresent = getSwitchBool(projectRepPresentSwitch.getValue()); + answersList.add(projectRepPresent + ""); + + String projectManager = projectManagerTextField.getValue(); + String siteManager = siteManagerTextField.getValue(); + String projectOwner = projectOwnerTextField.getValue(); + answersList.add(projectManager); + answersList.add(siteManager); + answersList.add(projectOwner); + + boolean correctiveAction1 = getSwitchBool(correctiveAction1Switch.getValue()); + boolean correctiveAction2 = getSwitchBool(correctiveAction2Switch.getValue()); + boolean correctiveAction3 = getSwitchBool(correctiveAction3Switch.getValue()); + boolean correctiveAction4 = getSwitchBool(correctiveAction4Switch.getValue()); + answersList.add(correctiveAction1 + ""); + answersList.add(correctiveAction2 + ""); + answersList.add(correctiveAction3 + ""); + answersList.add(correctiveAction4 + ""); + + List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); + answersList.addAll(correctiveAction5); + + boolean correctiveAction6 = getSwitchBool(correctiveAction6Switch.getValue()); + boolean correctiveAction7 = getSwitchBool(correctiveAction6Switch.getValue()); + boolean correctiveAction8 = getSwitchBool(correctiveAction8Switch.getValue()); + boolean correctiveAction9 = getSwitchBool(correctiveAction9Switch.getValue()); + answersList.add(correctiveAction6 + ""); + answersList.add(correctiveAction7 + ""); + answersList.add(correctiveAction8 + ""); + answersList.add(correctiveAction9 + ""); + + String correctiveAction10 = correctiveAction10Multi.getValue(); + answersList.add(correctiveAction10); + + String otherCorrectiveAction1 = otherCorrectiveAction1TextField.getValue(); + String otherCorrectiveAction2 = otherCorrectiveAction2TextField.getValue(); + String otherCorrectiveAction3 = otherCorrectiveAction3TextField.getValue(); + answersList.add(otherCorrectiveAction1); + answersList.add(otherCorrectiveAction2); + answersList.add(otherCorrectiveAction3); + + + List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); + answersList.addAll(enforcementAction); + + String[] imgLink = new String[]{evidenceTextField.getValue()}; + + + String[] answers = answersList.toArray(new String[0]); + // System.out.println(Arrays.toString(answers)); + ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answers, imgLink); + System.out.println(constructionFormData); + } + }); + + + + } - public boolean getSwitchBool(String value) { + private boolean getSwitchBool(String value) { if (value.equals("yes")) return true; return false; } + + private class ConstructionFormData { + String contact = ""; + String date = ""; + String inspector = ""; + String location = ""; + String[] answers; + + // SortTimeStamp set in constructor + Date SortTimeStamp; + + String[] imgLink; + + public ConstructionFormData(String contact, String date, String inspector, + String location, String[] answers, String[] imgLink) { + this.contact = contact; + this.date = date; + this.inspector = inspector; + this.location = location; + this.answers = answers; + + this.SortTimeStamp = new Date(System.currentTimeMillis()); + + this.answers = answers; + } + + + + @Override + public String toString() { + return "ConstructionFormData{" + + "contact=" + contact + '\n' + + ", date=" + date + '\n' + + ", inspector=" + inspector + '\n' + + ", location=" + location + '\n' + + ", answers=" + Arrays.toString(answers) + "\n" + + ", SortTimeStamp=" + SortTimeStamp + "\n" + + ", imgLink=" + Arrays.toString(imgLink) + "\n" + + '}'; + } + } } From 9c2ca342bfad444cc7e10593ae4d1b96f08be75d Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:44:24 -0500 Subject: [PATCH 4/7] feature/added FireStore functionality feature/update form to take in title/Strings of switches rather booleans (as strings) --- app/build.gradle | 1 + app/google-services.json | 39 +++++ .../InspectionForm.java | 150 +++++++++++------- build.gradle | 1 + 4 files changed, 132 insertions(+), 59 deletions(-) create mode 100644 app/google-services.json diff --git a/app/build.gradle b/app/build.gradle index 19093dd..eea8c58 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.application' + id 'com.google.gms.google-services' } android { diff --git a/app/google-services.json b/app/google-services.json new file mode 100644 index 0000000..50b3497 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,39 @@ +{ + "project_info": { + "project_number": "715047227500", + "project_id": "auth-test-978bd", + "storage_bucket": "auth-test-978bd.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:715047227500:android:6d404969351cf9a715c849", + "android_client_info": { + "package_name": "com.sf.stormwaterutilityandroid" + } + }, + "oauth_client": [ + { + "client_id": "715047227500-l993hj8oukroedqgtmuecookfmhjp1co.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDdVIxvfzkh1W0PCJ985hizZLthG6MrjJc" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "715047227500-l993hj8oukroedqgtmuecookfmhjp1co.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java index 975ca71..a9f8580 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -4,13 +4,20 @@ import android.view.View; import android.widget.Button; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.FirebaseFirestore; + import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import me.riddhimanadib.formmaster.FormBuilder; import me.riddhimanadib.formmaster.model.BaseFormElement; @@ -162,8 +169,8 @@ public void onClick(View view) { ArrayList answersList = new ArrayList<>(20); - boolean projectRepPresent = getSwitchBool(projectRepPresentSwitch.getValue()); - answersList.add(projectRepPresent + ""); + String projectRepPresent = getSwitchString(projectRepPresentSwitch); + answersList.add(projectRepPresent); String projectManager = projectManagerTextField.getValue(); String siteManager = siteManagerTextField.getValue(); @@ -172,26 +179,26 @@ public void onClick(View view) { answersList.add(siteManager); answersList.add(projectOwner); - boolean correctiveAction1 = getSwitchBool(correctiveAction1Switch.getValue()); - boolean correctiveAction2 = getSwitchBool(correctiveAction2Switch.getValue()); - boolean correctiveAction3 = getSwitchBool(correctiveAction3Switch.getValue()); - boolean correctiveAction4 = getSwitchBool(correctiveAction4Switch.getValue()); - answersList.add(correctiveAction1 + ""); - answersList.add(correctiveAction2 + ""); - answersList.add(correctiveAction3 + ""); - answersList.add(correctiveAction4 + ""); + String correctiveAction1 = getSwitchString(correctiveAction1Switch); + String correctiveAction2 = getSwitchString(correctiveAction2Switch); + String correctiveAction3 = getSwitchString(correctiveAction3Switch); + String correctiveAction4 = getSwitchString(correctiveAction4Switch); + answersList.add(correctiveAction1); + answersList.add(correctiveAction2); + answersList.add(correctiveAction3); + answersList.add(correctiveAction4); List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); answersList.addAll(correctiveAction5); - boolean correctiveAction6 = getSwitchBool(correctiveAction6Switch.getValue()); - boolean correctiveAction7 = getSwitchBool(correctiveAction6Switch.getValue()); - boolean correctiveAction8 = getSwitchBool(correctiveAction8Switch.getValue()); - boolean correctiveAction9 = getSwitchBool(correctiveAction9Switch.getValue()); - answersList.add(correctiveAction6 + ""); - answersList.add(correctiveAction7 + ""); - answersList.add(correctiveAction8 + ""); - answersList.add(correctiveAction9 + ""); + String correctiveAction6 = getSwitchString(correctiveAction6Switch); + String correctiveAction7 = getSwitchString(correctiveAction6Switch); + String correctiveAction8 = getSwitchString(correctiveAction8Switch); + String correctiveAction9 = getSwitchString(correctiveAction9Switch); + answersList.add(correctiveAction6); + answersList.add(correctiveAction7); + answersList.add(correctiveAction8); + answersList.add(correctiveAction9); String correctiveAction10 = correctiveAction10Multi.getValue(); answersList.add(correctiveAction10); @@ -207,64 +214,89 @@ public void onClick(View view) { List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); answersList.addAll(enforcementAction); - String[] imgLink = new String[]{evidenceTextField.getValue()}; + String imgLink = new String(evidenceTextField.getValue()); String[] answers = answersList.toArray(new String[0]); - // System.out.println(Arrays.toString(answers)); - ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answers, imgLink); - System.out.println(constructionFormData); + ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink); + + FirebaseFirestore db = FirebaseFirestore.getInstance(); + db.collection("ConstructionSiteForm") + .add(constructionFormData.getMap()) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(DocumentReference documentReference) { + System.out.println("ibra SUCCESSFUL - FIRESTORE"); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + System.out.println("ibra SUCCESSFUL - ERROR/FAILED: " + e); + } + }); + + // System.out.println(constructionFormData); } }); - - } - private boolean getSwitchBool(String value) { - if (value.equals("yes")) return true; - return false; + private String getSwitchString(FormElementSwitch switchElement) { + System.out.println(switchElement.getValue()); + if (switchElement.getValue().equals("Yes")) return switchElement.getTitle(); + return ""; } private class ConstructionFormData { - String contact = ""; - String date = ""; - String inspector = ""; - String location = ""; - String[] answers; - +// String contact = ""; +// String date = ""; +// String inspector = ""; +// String location = ""; +// String[] answers; // SortTimeStamp set in constructor - Date SortTimeStamp; +// Date SortTimeStamp; +// +// String[] imgLink; - String[] imgLink; + Map data = new HashMap<>(); public ConstructionFormData(String contact, String date, String inspector, - String location, String[] answers, String[] imgLink) { - this.contact = contact; - this.date = date; - this.inspector = inspector; - this.location = location; - this.answers = answers; - - this.SortTimeStamp = new Date(System.currentTimeMillis()); - - this.answers = answers; + String location, List answers, String imgLink) { + data.put("contact", contact); + data.put("date", date); + data.put("inspector", inspector); + data.put("location", location); + data.put("answers", answers); + data.put("imgLink", imgLink); + +// this.contact = contact; +// this.date = date; +// this.inspector = inspector; +// this.location = location; +// this.answers = answers; +// +// this.SortTimeStamp = new Date(System.currentTimeMillis()); +// +// this.answers = answers; } - - - @Override - public String toString() { - return "ConstructionFormData{" + - "contact=" + contact + '\n' + - ", date=" + date + '\n' + - ", inspector=" + inspector + '\n' + - ", location=" + location + '\n' + - ", answers=" + Arrays.toString(answers) + "\n" + - ", SortTimeStamp=" + SortTimeStamp + "\n" + - ", imgLink=" + Arrays.toString(imgLink) + "\n" + - '}'; + public Map getMap() { + return data; } + +// @Override +// public String toString() { +// return "ConstructionFormData{" + +// "contact=" + contact + '\n' + +// ", date=" + date + '\n' + +// ", inspector=" + inspector + '\n' + +// ", location=" + location + '\n' + +// ", answers=" + Arrays.toString(answers) + "\n" + +// ", SortTimeStamp=" + SortTimeStamp + "\n" + +// ", imgLink=" + Arrays.toString(imgLink) + "\n" + +// '}'; +// } } } diff --git a/build.gradle b/build.gradle index 4d24be2..6a4ea19 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ buildscript { } dependencies { classpath "com.android.tools.build:gradle:4.1.1" + classpath 'com.google.gms:google-services:4.3.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 5af5a1cbb00127166a16ed9a21b07b34b21f7335 Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:43:06 -0500 Subject: [PATCH 5/7] refactor/made ConstructionFormData.java into a public class refactor/answer switches (in List answers) give "true"/"false" in firebase refactor/clean up all comments and unused code --- .../ConstructionFormData.java | 40 ++++++ .../InspectionForm.java | 120 ++++++------------ 2 files changed, 76 insertions(+), 84 deletions(-) create mode 100644 app/src/main/java/com/sf/stormwaterutilityandroid/ConstructionFormData.java diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/ConstructionFormData.java b/app/src/main/java/com/sf/stormwaterutilityandroid/ConstructionFormData.java new file mode 100644 index 0000000..a66ec46 --- /dev/null +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/ConstructionFormData.java @@ -0,0 +1,40 @@ +package com.sf.stormwaterutilityandroid; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ConstructionFormData { + private Map data; + // String contact + // String date + // String inspector + // String location + + // (they are lists because firebase doesn't serialize arrays) + // List answers + // List imgLink + + public ConstructionFormData(String contact, String date, String inspector, + String location, List answers, List imgLink) { + data = new HashMap<>(); + data.put("contact", contact); + data.put("date", date); + data.put("inspector", inspector); + data.put("location", location); + data.put("answers", answers); + data.put("imgLink", imgLink); + } + + public Map getMap() { + return data; + } + + @Override + public String toString() { + return "ConstructionFormData{" + + "data=" + data + + '}'; + } + +} diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java index a9f8580..f8a16f1 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -15,9 +15,7 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import me.riddhimanadib.formmaster.FormBuilder; import me.riddhimanadib.formmaster.model.BaseFormElement; @@ -45,6 +43,23 @@ protected void onCreate(Bundle savedInstanceState) { setupForm(); } + private void uploadToFirestore(ConstructionFormData constructionFormData) { + FirebaseFirestore db = FirebaseFirestore.getInstance(); + db.collection("ConstructionSiteForm") + .add(constructionFormData.getMap()) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(DocumentReference documentReference) { + System.out.println("SUCCESSFUL - FIRESTORE"); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + System.out.println("FAILED - FIRESTORE: " + e); + } + }); + } private void setupForm() { formBuilder = new FormBuilder(this, recyclerView); @@ -162,6 +177,8 @@ private void setupForm() { submitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + + // data retrieval from forms String contact = projectTextField.getValue(); String location = addressTextField.getValue(); String inspector = inspectorTextField.getValue(); @@ -169,7 +186,7 @@ public void onClick(View view) { ArrayList answersList = new ArrayList<>(20); - String projectRepPresent = getSwitchString(projectRepPresentSwitch); + String projectRepPresent = getSwitchBool(projectRepPresentSwitch); answersList.add(projectRepPresent); String projectManager = projectManagerTextField.getValue(); @@ -179,10 +196,10 @@ public void onClick(View view) { answersList.add(siteManager); answersList.add(projectOwner); - String correctiveAction1 = getSwitchString(correctiveAction1Switch); - String correctiveAction2 = getSwitchString(correctiveAction2Switch); - String correctiveAction3 = getSwitchString(correctiveAction3Switch); - String correctiveAction4 = getSwitchString(correctiveAction4Switch); + String correctiveAction1 = getSwitchBool(correctiveAction1Switch); + String correctiveAction2 = getSwitchBool(correctiveAction2Switch); + String correctiveAction3 = getSwitchBool(correctiveAction3Switch); + String correctiveAction4 = getSwitchBool(correctiveAction4Switch); answersList.add(correctiveAction1); answersList.add(correctiveAction2); answersList.add(correctiveAction3); @@ -191,10 +208,10 @@ public void onClick(View view) { List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); answersList.addAll(correctiveAction5); - String correctiveAction6 = getSwitchString(correctiveAction6Switch); - String correctiveAction7 = getSwitchString(correctiveAction6Switch); - String correctiveAction8 = getSwitchString(correctiveAction8Switch); - String correctiveAction9 = getSwitchString(correctiveAction9Switch); + String correctiveAction6 = getSwitchBool(correctiveAction6Switch); + String correctiveAction7 = getSwitchBool(correctiveAction6Switch); + String correctiveAction8 = getSwitchBool(correctiveAction8Switch); + String correctiveAction9 = getSwitchBool(correctiveAction9Switch); answersList.add(correctiveAction6); answersList.add(correctiveAction7); answersList.add(correctiveAction8); @@ -214,89 +231,24 @@ public void onClick(View view) { List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); answersList.addAll(enforcementAction); - String imgLink = new String(evidenceTextField.getValue()); - + List imgLink = new ArrayList<>(); + imgLink.add(evidenceTextField.getValue()); String[] answers = answersList.toArray(new String[0]); ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink); - FirebaseFirestore db = FirebaseFirestore.getInstance(); - db.collection("ConstructionSiteForm") - .add(constructionFormData.getMap()) - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(DocumentReference documentReference) { - System.out.println("ibra SUCCESSFUL - FIRESTORE"); - } - }) - .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception e) { - System.out.println("ibra SUCCESSFUL - ERROR/FAILED: " + e); - } - }); - - // System.out.println(constructionFormData); + + // submit data to firestore + uploadToFirestore(constructionFormData); } }); } - private String getSwitchString(FormElementSwitch switchElement) { - System.out.println(switchElement.getValue()); - if (switchElement.getValue().equals("Yes")) return switchElement.getTitle(); - return ""; + private String getSwitchBool(FormElementSwitch switchElement) { + if (switchElement.getValue().equals("Yes")) return "true"; + return "false"; } - private class ConstructionFormData { -// String contact = ""; -// String date = ""; -// String inspector = ""; -// String location = ""; -// String[] answers; - // SortTimeStamp set in constructor -// Date SortTimeStamp; -// -// String[] imgLink; - - Map data = new HashMap<>(); - - public ConstructionFormData(String contact, String date, String inspector, - String location, List answers, String imgLink) { - data.put("contact", contact); - data.put("date", date); - data.put("inspector", inspector); - data.put("location", location); - data.put("answers", answers); - data.put("imgLink", imgLink); - -// this.contact = contact; -// this.date = date; -// this.inspector = inspector; -// this.location = location; -// this.answers = answers; -// -// this.SortTimeStamp = new Date(System.currentTimeMillis()); -// -// this.answers = answers; - } - - public Map getMap() { - return data; - } - -// @Override -// public String toString() { -// return "ConstructionFormData{" + -// "contact=" + contact + '\n' + -// ", date=" + date + '\n' + -// ", inspector=" + inspector + '\n' + -// ", location=" + location + '\n' + -// ", answers=" + Arrays.toString(answers) + "\n" + -// ", SortTimeStamp=" + SortTimeStamp + "\n" + -// ", imgLink=" + Arrays.toString(imgLink) + "\n" + -// '}'; -// } - } } From 31317320c2405cf01ad3d887fb50d3da66d2e706 Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:45:43 -0500 Subject: [PATCH 6/7] refactor/made ConstructionFormData.java into a public class refactor/answer switches (in List answers) give "true"/"false" in firebase refactor/clean up all comments and unused code --- .../InspectionForm.java | 152 ++++++++---------- 1 file changed, 66 insertions(+), 86 deletions(-) diff --git a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java index f8a16f1..9efb51c 100644 --- a/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java +++ b/app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java @@ -1,16 +1,11 @@ package com.sf.stormwaterutilityandroid; import android.os.Bundle; -import android.view.View; import android.widget.Button; -import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; -import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; import java.util.ArrayList; @@ -28,7 +23,6 @@ import me.riddhimanadib.formmaster.model.FormHeader; public class InspectionForm extends AppCompatActivity { - private FormBuilder formBuilder; private RecyclerView recyclerView; private Button submitButton; @@ -47,22 +41,12 @@ private void uploadToFirestore(ConstructionFormData constructionFormData) { FirebaseFirestore db = FirebaseFirestore.getInstance(); db.collection("ConstructionSiteForm") .add(constructionFormData.getMap()) - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(DocumentReference documentReference) { - System.out.println("SUCCESSFUL - FIRESTORE"); - } - }) - .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception e) { - System.out.println("FAILED - FIRESTORE: " + e); - } - }); + .addOnSuccessListener(documentReference -> System.out.println("SUCCESSFUL - FIRESTORE")) + .addOnFailureListener(e -> System.out.println("FAILED - FIRESTORE: " + e)); } private void setupForm() { - formBuilder = new FormBuilder(this, recyclerView); + FormBuilder formBuilder = new FormBuilder(this, recyclerView); FormElementTextSingleLine projectTextField = FormElementTextSingleLine.createInstance().setTitle("Project/Contact:").setHint("Enter text here"); FormElementTextSingleLine addressTextField = FormElementTextSingleLine.createInstance().setTitle("Address/Lot#(s):").setHint("Enter text here"); @@ -174,73 +158,69 @@ private void setupForm() { formBuilder.addFormElements(formItems); // onSubmit - submitButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - // data retrieval from forms - String contact = projectTextField.getValue(); - String location = addressTextField.getValue(); - String inspector = inspectorTextField.getValue(); - String date = dateInspectedDatePicker.getValue(); - - ArrayList answersList = new ArrayList<>(20); - - String projectRepPresent = getSwitchBool(projectRepPresentSwitch); - answersList.add(projectRepPresent); - - String projectManager = projectManagerTextField.getValue(); - String siteManager = siteManagerTextField.getValue(); - String projectOwner = projectOwnerTextField.getValue(); - answersList.add(projectManager); - answersList.add(siteManager); - answersList.add(projectOwner); - - String correctiveAction1 = getSwitchBool(correctiveAction1Switch); - String correctiveAction2 = getSwitchBool(correctiveAction2Switch); - String correctiveAction3 = getSwitchBool(correctiveAction3Switch); - String correctiveAction4 = getSwitchBool(correctiveAction4Switch); - answersList.add(correctiveAction1); - answersList.add(correctiveAction2); - answersList.add(correctiveAction3); - answersList.add(correctiveAction4); - - List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); - answersList.addAll(correctiveAction5); - - String correctiveAction6 = getSwitchBool(correctiveAction6Switch); - String correctiveAction7 = getSwitchBool(correctiveAction6Switch); - String correctiveAction8 = getSwitchBool(correctiveAction8Switch); - String correctiveAction9 = getSwitchBool(correctiveAction9Switch); - answersList.add(correctiveAction6); - answersList.add(correctiveAction7); - answersList.add(correctiveAction8); - answersList.add(correctiveAction9); - - String correctiveAction10 = correctiveAction10Multi.getValue(); - answersList.add(correctiveAction10); - - String otherCorrectiveAction1 = otherCorrectiveAction1TextField.getValue(); - String otherCorrectiveAction2 = otherCorrectiveAction2TextField.getValue(); - String otherCorrectiveAction3 = otherCorrectiveAction3TextField.getValue(); - answersList.add(otherCorrectiveAction1); - answersList.add(otherCorrectiveAction2); - answersList.add(otherCorrectiveAction3); - - - List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); - answersList.addAll(enforcementAction); - - List imgLink = new ArrayList<>(); - imgLink.add(evidenceTextField.getValue()); - - String[] answers = answersList.toArray(new String[0]); - ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink); - - - // submit data to firestore - uploadToFirestore(constructionFormData); - } + submitButton.setOnClickListener(view -> { + + // data retrieval from forms + String contact = projectTextField.getValue(); + String location = addressTextField.getValue(); + String inspector = inspectorTextField.getValue(); + String date = dateInspectedDatePicker.getValue(); + + ArrayList answersList = new ArrayList<>(20); + + String projectRepPresent = getSwitchBool(projectRepPresentSwitch); + answersList.add(projectRepPresent); + + String projectManager = projectManagerTextField.getValue(); + String siteManager = siteManagerTextField.getValue(); + String projectOwner = projectOwnerTextField.getValue(); + answersList.add(projectManager); + answersList.add(siteManager); + answersList.add(projectOwner); + + String correctiveAction1 = getSwitchBool(correctiveAction1Switch); + String correctiveAction2 = getSwitchBool(correctiveAction2Switch); + String correctiveAction3 = getSwitchBool(correctiveAction3Switch); + String correctiveAction4 = getSwitchBool(correctiveAction4Switch); + answersList.add(correctiveAction1); + answersList.add(correctiveAction2); + answersList.add(correctiveAction3); + answersList.add(correctiveAction4); + + List correctiveAction5 = correctiveAction5Multi.getOptionsSelected(); + answersList.addAll(correctiveAction5); + + String correctiveAction6 = getSwitchBool(correctiveAction6Switch); + String correctiveAction7 = getSwitchBool(correctiveAction6Switch); + String correctiveAction8 = getSwitchBool(correctiveAction8Switch); + String correctiveAction9 = getSwitchBool(correctiveAction9Switch); + answersList.add(correctiveAction6); + answersList.add(correctiveAction7); + answersList.add(correctiveAction8); + answersList.add(correctiveAction9); + + String correctiveAction10 = correctiveAction10Multi.getValue(); + answersList.add(correctiveAction10); + + String otherCorrectiveAction1 = otherCorrectiveAction1TextField.getValue(); + String otherCorrectiveAction2 = otherCorrectiveAction2TextField.getValue(); + String otherCorrectiveAction3 = otherCorrectiveAction3TextField.getValue(); + answersList.add(otherCorrectiveAction1); + answersList.add(otherCorrectiveAction2); + answersList.add(otherCorrectiveAction3); + + + List enforcementAction = enforcementActionPickerSingle.getOptionsSelected(); + answersList.addAll(enforcementAction); + + List imgLink = new ArrayList<>(); + imgLink.add(evidenceTextField.getValue()); + + ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink); + + + // submit data to firestore + uploadToFirestore(constructionFormData); }); From 31a995bd4c9e3b0b6c2a7b5bdaf5ab2668ae3dc8 Mon Sep 17 00:00:00 2001 From: IbrahimSaeedPurdue <54752803+IbrahimSaeedPurdue@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:54:20 -0500 Subject: [PATCH 7/7] refactor/removed google-services.json (my own firebase testing database) --- app/google-services.json | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 app/google-services.json diff --git a/app/google-services.json b/app/google-services.json deleted file mode 100644 index 50b3497..0000000 --- a/app/google-services.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "project_info": { - "project_number": "715047227500", - "project_id": "auth-test-978bd", - "storage_bucket": "auth-test-978bd.appspot.com" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:715047227500:android:6d404969351cf9a715c849", - "android_client_info": { - "package_name": "com.sf.stormwaterutilityandroid" - } - }, - "oauth_client": [ - { - "client_id": "715047227500-l993hj8oukroedqgtmuecookfmhjp1co.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyDdVIxvfzkh1W0PCJ985hizZLthG6MrjJc" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "715047227500-l993hj8oukroedqgtmuecookfmhjp1co.apps.googleusercontent.com", - "client_type": 3 - } - ] - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file