Added update function to the UI.
This commit is contained in:
parent
e4281fc45b
commit
9968eb24a6
123 changed files with 734 additions and 8721 deletions
|
@ -11,8 +11,6 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
|
@ -26,7 +24,6 @@ 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;
|
||||
|
@ -40,7 +37,7 @@ public class Drivers extends AppCompatActivity{
|
|||
private eAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager mLayoutManager;
|
||||
ArrayList<driveritem> mExampleList = new ArrayList<>();
|
||||
private Button add, remove;
|
||||
private Button add, remove, update;
|
||||
String Fname, email, phone;
|
||||
int numOfDrivers;
|
||||
int removeP;
|
||||
|
@ -54,6 +51,7 @@ public class Drivers extends AppCompatActivity{
|
|||
fstore = FirebaseFirestore.getInstance();
|
||||
add = findViewById(R.id.adddriver);
|
||||
remove = findViewById(R.id.removedriver);
|
||||
update = findViewById(R.id.updatedriver);
|
||||
|
||||
userID = fAuth.getCurrentUser().getUid();
|
||||
|
||||
|
@ -108,6 +106,13 @@ public class Drivers extends AppCompatActivity{
|
|||
}
|
||||
});
|
||||
|
||||
update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateDriver();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void addDriver(){
|
||||
|
@ -129,10 +134,10 @@ public class Drivers extends AppCompatActivity{
|
|||
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("First Name").setValue(f);
|
||||
reff.child("3").child("Last Name").setValue(l);
|
||||
reff.child("3").child("Phone").setValue(p);
|
||||
reff.child("3").child("E-Mail").setValue(e);
|
||||
} else {
|
||||
Log.d("LOGGER", "No such document");
|
||||
}
|
||||
|
@ -154,6 +159,10 @@ public class Drivers extends AppCompatActivity{
|
|||
}
|
||||
}
|
||||
|
||||
public void updateDriver(){
|
||||
startActivity(new Intent(getApplicationContext(), com.example.capstone.update.class));
|
||||
}
|
||||
|
||||
public void logout(View view){
|
||||
fAuth.signOut();
|
||||
startActivity(new Intent(getApplicationContext(), Login.class));
|
||||
|
|
156
UI/app/src/main/java/com/example/capstone/update.java
Normal file
156
UI/app/src/main/java/com/example/capstone/update.java
Normal file
|
@ -0,0 +1,156 @@
|
|||
package com.example.capstone;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
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.FirebaseFirestore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class update extends AppCompatActivity {
|
||||
private EditText firstname, lastname, phone, email;
|
||||
private Button save, cancel;
|
||||
FirebaseAuth fAuth;
|
||||
private boolean check;
|
||||
FirebaseFirestore fstore;
|
||||
String userID;
|
||||
int numOfDrivers;
|
||||
private String fn, ln, ph;
|
||||
DatabaseReference reff;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_update );
|
||||
|
||||
firstname = (EditText) findViewById(R.id.fname2);
|
||||
lastname = (EditText) findViewById(R.id.lname2);
|
||||
phone = (EditText) findViewById(R.id.phone2);
|
||||
save = (Button) findViewById(R.id.adddriver2);
|
||||
cancel = (Button) findViewById(R.id.cancel2);
|
||||
|
||||
fAuth = FirebaseAuth.getInstance();
|
||||
fstore = FirebaseFirestore.getInstance();
|
||||
|
||||
userID = fAuth.getCurrentUser().getUid();
|
||||
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
fn = firstname.getText().toString().trim();
|
||||
ln = lastname.getText().toString().trim();
|
||||
ph = phone.getText().toString().trim();
|
||||
|
||||
if(TextUtils.isEmpty(fn)){
|
||||
firstname.setError("First name is Required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(ln)){
|
||||
lastname.setError("Last name is Required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(ph)){
|
||||
phone.setError("Phone number is Required.");
|
||||
return;
|
||||
}
|
||||
|
||||
check = onlyDigits(ph, ph.length());
|
||||
if(!check){
|
||||
phone.setError("Invalid phone number");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ph.length() < 10){
|
||||
phone.setError("Invalid phone number");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DocumentReference documentReference = fstore.collection("users").document(userID);
|
||||
Map<String,Object> user = new HashMap<>();
|
||||
documentReference.update("First Name",fn);
|
||||
documentReference.update("Last Name",ln);
|
||||
documentReference.update("Phone Number",ph);
|
||||
documentReference.update(user).addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
}
|
||||
});
|
||||
reff = FirebaseDatabase.getInstance().getReference().child("signal");
|
||||
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 e = document.getString("Email");
|
||||
reff.child("4").child("E-Mail").setValue(e);
|
||||
} else {
|
||||
Log.d("LOGGER", "No such document");
|
||||
}
|
||||
} else {
|
||||
Log.d("LOGGER", "get failed with ", task.getException());
|
||||
}
|
||||
}
|
||||
});
|
||||
reff.child("4").child("First Name").setValue(fn);
|
||||
reff.child("4").child("Last Name").setValue(ln);
|
||||
reff.child("4").child("Phone").setValue(ph);
|
||||
openDriver();
|
||||
}
|
||||
});
|
||||
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getApplicationContext(), Drivers.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void openDriver() {
|
||||
Intent intent = new Intent(this, Drivers.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public static boolean onlyDigits(String str, int n) {
|
||||
for(int i = 0; i < n; i++) {
|
||||
if(str.charAt(i) >= '0'
|
||||
&& str.charAt(i) <= '9') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void logout(View view){
|
||||
fAuth.signOut();
|
||||
startActivity(new Intent(getApplicationContext(), Login.class));
|
||||
finish();
|
||||
}
|
||||
|
||||
public void back(View view){
|
||||
startActivity(new Intent(getApplicationContext(), Drivers.class));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue