Skip to content

Commit

Permalink
feature/added FireStore functionality
Browse files Browse the repository at this point in the history
feature/update form to take in title/Strings of switches rather booleans (as strings)
  • Loading branch information
IbrahimSaeedPurdue authored and IbrahimSaeedPurdue committed Mar 4, 2021
1 parent 042f8d4 commit 9c2ca34
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 59 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}

android {
Expand Down
39 changes: 39 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -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"
}
150 changes: 91 additions & 59 deletions app/src/main/java/com/sf/stormwaterutilityandroid/InspectionForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,8 +169,8 @@ public void onClick(View view) {

ArrayList<String> 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();
Expand All @@ -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<String> 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);
Expand All @@ -207,64 +214,89 @@ public void onClick(View view) {
List<String> 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<DocumentReference>() {
@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<String, Object> 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<String> 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<String, Object> 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" +
// '}';
// }
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c2ca34

Please sign in to comment.