1
I’m trying to create a class where I’ll connect in the Firestore of Firebase, and then I’ll take this class and instantiate it where necessary, I made this part of the code but I don’t know what else to do.
Class connecting in firebase
public class Cloudfirestore {
FirebaseFirestore connection;
public CloudFirestore(FirebaseFirestore connection) {
this.connection = connection;
}
public FirebaseFirestore getConnection() {
return connection;
}
public void setConnection(FirebaseFirestore connection) {
this.connection = connection;
}
Class that prompts my connection and adds a record in firebase.
Cloudfirestore cloudFirestore = new Cloudfirestore();
Map<String, Object> report = new HashMap<>();
report.put("name", this.editTextName);
report.put("dateWorked", this.editDateWorked);
report.put("timeInput", this.editTimeInput);
report.put("timeExit", this.editTimeExit);
report.put("goodParts", this.editNumberGoodParts);
report.put("badParts", this.editNumberBadParts);
report.put("workedPlace", this.editTextWorkedPlace);
report.put("mails", this.editTextMails);
if (report != null) {
cloudFirestore.setConnection().collection("reports")
.add(report)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error adding document", e);
}
});