Added the removedriver signals.

This commit is contained in:
Batuhan Berk Başoğlu 2021-03-08 15:44:04 -05:00
parent 089666ecbc
commit e4281fc45b

View file

@ -1,5 +1,6 @@
package com.example.capstone; package com.example.capstone;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -14,13 +15,18 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.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.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener; import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FieldValue; import com.google.firebase.firestore.FieldValue;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException; import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.Source;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -38,6 +44,7 @@ public class Drivers extends AppCompatActivity{
String Fname, email, phone; String Fname, email, phone;
int numOfDrivers; int numOfDrivers;
int removeP; int removeP;
DatabaseReference reff;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -111,6 +118,29 @@ public class Drivers extends AppCompatActivity{
if(removeP != 0){ if(removeP != 0){
Map<String,Object> user = new HashMap<>(); Map<String,Object> user = new HashMap<>();
DocumentReference documentReference = fstore.collection("users").document(userID); DocumentReference documentReference = fstore.collection("users").document(userID);
documentReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> 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("First Name"+String.valueOf(removeP+1), FieldValue.delete());
documentReference.update("Last 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()); documentReference.update("Email"+String.valueOf(removeP+1), FieldValue.delete());