diff --git a/UI/app/src/main/java/com/example/capstone/Drivers.java b/UI/app/src/main/java/com/example/capstone/Drivers.java index cf593c6ea..c5d09703a 100644 --- a/UI/app/src/main/java/com/example/capstone/Drivers.java +++ b/UI/app/src/main/java/com/example/capstone/Drivers.java @@ -1,5 +1,6 @@ package com.example.capstone; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; @@ -14,13 +15,18 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.EventListener; import com.google.firebase.firestore.FieldValue; import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.Source; import java.util.ArrayList; import java.util.HashMap; @@ -38,6 +44,7 @@ public class Drivers extends AppCompatActivity{ String Fname, email, phone; int numOfDrivers; int removeP; + DatabaseReference reff; @Override protected void onCreate(Bundle savedInstanceState) { @@ -111,6 +118,29 @@ public class Drivers extends AppCompatActivity{ if(removeP != 0){ Map user = new HashMap<>(); DocumentReference documentReference = fstore.collection("users").document(userID); + documentReference.get().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + DocumentSnapshot document = task.getResult(); + if (document != null) { + String f = document.getString("First Name"+String.valueOf(removeP+1)); + String l = document.getString("Last Name"+String.valueOf(removeP+1)); + String e = document.getString("Email"+String.valueOf(removeP+1)); + String p = document.getString("Phone Number"+String.valueOf(removeP+1)); + reff = FirebaseDatabase.getInstance().getReference().child("signal"); + reff.child("3").child("E-Mail").setValue(f); + reff.child("3").child("First Name").setValue(l); + reff.child("3").child("Last Name").setValue(e); + reff.child("3").child("Phone").setValue(p); + } else { + Log.d("LOGGER", "No such document"); + } + } else { + Log.d("LOGGER", "get failed with ", task.getException()); + } + } + }); documentReference.update("First Name"+String.valueOf(removeP+1), FieldValue.delete()); documentReference.update("Last Name"+String.valueOf(removeP+1), FieldValue.delete()); documentReference.update("Email"+String.valueOf(removeP+1), FieldValue.delete());