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] 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" + + '}'; + } + } }