Added update function to the UI.
This commit is contained in:
parent
e4281fc45b
commit
9968eb24a6
123 changed files with 734 additions and 8721 deletions
|
@ -15,6 +15,7 @@
|
|||
<activity android:name=".Apps"></activity>
|
||||
<activity android:name=".Email" />
|
||||
<activity android:name=".add" />
|
||||
<activity android:name=".update" />
|
||||
<activity android:name=".About" />
|
||||
<activity android:name=".Support" />
|
||||
<activity android:name=".Password" />
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -7,6 +7,19 @@
|
|||
android:background="@drawable/background"
|
||||
tools:context=".Drivers">
|
||||
|
||||
<Button
|
||||
android:id="@+id/updatedriver"
|
||||
android:layout_width="292dp"
|
||||
android:layout_height="51dp"
|
||||
android:layout_marginStart="60dp"
|
||||
android:layout_marginBottom="28dp"
|
||||
android:background="@drawable/mybutton"
|
||||
android:text="Update Main Driver"
|
||||
android:textColor="#1D3790"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<include
|
||||
layout="@layout/toolbar"/>
|
||||
|
||||
|
@ -39,7 +52,7 @@
|
|||
android:layout_width="130dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:layout_marginBottom="92dp"
|
||||
android:background="@drawable/mybutton"
|
||||
android:text="Add Driver"
|
||||
android:textColor="#1D3790"
|
||||
|
@ -52,7 +65,7 @@
|
|||
android:layout_width="130dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:layout_marginBottom="92dp"
|
||||
android:background="@drawable/mybutton"
|
||||
android:text="Remove Driver"
|
||||
android:textColor="#1D3790"
|
||||
|
|
102
UI/app/src/main/res/layout/activity_update.xml
Normal file
102
UI/app/src/main/res/layout/activity_update.xml
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".add"
|
||||
android:background="@drawable/background"
|
||||
>
|
||||
|
||||
<include
|
||||
layout="@layout/toolbar"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/updatedrivertitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginBottom="630dp"
|
||||
android:gravity="center"
|
||||
android:text="Update Main Driver"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="30dp"
|
||||
app:fontFamily="normal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/fname2"
|
||||
android:layout_width="315dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/loginedittext"
|
||||
android:hint="First Name"
|
||||
android:paddingLeft="10dp"
|
||||
android:textColorHint="#ffffff"
|
||||
tools:layout_editor_absoluteX="25dp"
|
||||
tools:layout_editor_absoluteY="145dp"
|
||||
android:layout_marginBottom="540dp"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/lname2"
|
||||
android:layout_width="315dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/loginedittext"
|
||||
android:hint="Last Name"
|
||||
android:paddingLeft="10dp"
|
||||
android:textColorHint="#ffffff"
|
||||
tools:layout_editor_absoluteX="25dp"
|
||||
tools:layout_editor_absoluteY="208dp"
|
||||
android:layout_marginBottom="470dp"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/phone2"
|
||||
android:layout_width="315dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/loginedittext"
|
||||
android:hint="Phone Number"
|
||||
android:paddingLeft="10dp"
|
||||
android:textColorHint="#ffffff"
|
||||
tools:layout_editor_absoluteX="25dp"
|
||||
tools:layout_editor_absoluteY="267dp"
|
||||
android:layout_marginBottom="400dp"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/adddriver2"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:background="@drawable/mybutton"
|
||||
android:text="Update Driver"
|
||||
android:textColor="#1D3790"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel2"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:background="@drawable/mybutton"
|
||||
android:text="Cancel"
|
||||
android:textColor="#1D3790"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Add a link
Reference in a new issue