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