Skip to content

Commit

Permalink
refactor/made ConstructionFormData.java into a public class
Browse files Browse the repository at this point in the history
refactor/answer switches (in List<String> answers) give "true"/"false" in firebase
refactor/clean up all comments and unused code
  • Loading branch information
IbrahimSaeedPurdue authored and IbrahimSaeedPurdue committed Mar 4, 2021
1 parent 5af5a1c commit 3131732
Showing 1 changed file with 66 additions and 86 deletions.
152 changes: 66 additions & 86 deletions app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,7 +23,6 @@
import me.riddhimanadib.formmaster.model.FormHeader;

public class InspectionForm extends AppCompatActivity {
private FormBuilder formBuilder;
private RecyclerView recyclerView;
private Button submitButton;

Expand All @@ -47,22 +41,12 @@ private void uploadToFirestore(ConstructionFormData constructionFormData) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("ConstructionSiteForm")
.add(constructionFormData.getMap())
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@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");
Expand Down Expand Up @@ -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<String> 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<String> 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<String> enforcementAction = enforcementActionPickerSingle.getOptionsSelected();
answersList.addAll(enforcementAction);

List<String> 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<String> 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<String> 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<String> enforcementAction = enforcementActionPickerSingle.getOptionsSelected();
answersList.addAll(enforcementAction);

List<String> imgLink = new ArrayList<>();
imgLink.add(evidenceTextField.getValue());

ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink);


// submit data to firestore
uploadToFirestore(constructionFormData);
});


Expand Down

0 comments on commit 3131732

Please sign in to comment.