Estou tentando criar um classe onde nela vou conecta no Firestore do Firebase, e depois vou pegar esta classe e instanciar ela onde for necessário, eu fiz estar essa parte do código porém não sei mais o que fazer.
Classe que conecta no 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;
}
Classe que instancio a minha conexao e adiciono um registro no 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);
}
});