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] 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); });