Commit 598a61f7 authored by Thilakasiri M.D.T.S's avatar Thilakasiri M.D.T.S

Merge branch 'master' into 'IT18203004'

Master to merge IT18203004

See merge request !6
parents 09a5ed21 4fd4466f
package com.example.vehicleparkingsystem;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.example.vehicleparkingsystem.Models.BaseURL;
import com.example.vehicleparkingsystem.SQLite.Sqlitedb;
import org.json.JSONArray;
import org.json.JSONException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class ParkingSlots extends AppCompatActivity {
LinearLayout L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12;
Button button;
String l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12;
ArrayList<Map<String, String>> SavedData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parking_slots);
L1 = findViewById(R.id.l1);
L2 = findViewById(R.id.l2);
L3 = findViewById(R.id.l3);
L4 = findViewById(R.id.l4);
L5 = findViewById(R.id.l5);
L6 = findViewById(R.id.l6);
L7 = findViewById(R.id.l7);
L8 = findViewById(R.id.l8);
L9 = findViewById(R.id.l9);
L10 = findViewById(R.id.l10);
L11 = findViewById(R.id.l11);
L12 = findViewById(R.id.l12);
button = findViewById(R.id.availability);
L1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L1","1", L1);
}
});
L2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L2","1", L2);
}
});
L3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L3","1", L3);
}
});
L4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L4","1", L4);
}
});
L5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L5","10", L5);
}
});
L6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L6","1", L6);
}
});
L7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L7","1", L7);
}
});
L8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L8","1", L8);
}
});
L9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L9","1", L9);
}
});
L10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L10","1", L10);
}
});
L11.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L11","1", L11);
}
});
L12.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmAlert("L12","1", L12);
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SlotsIdentify().execute();
}
});
}
private class SlotsIdentify extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
// SavedData = Sqlitedb.Search(ParkingSlots.this,"SELECT * FROM ParkingSlots",3);
// System.out.println(SavedData);
//
// if(!SavedData.isEmpty()){
// l1 = SavedData.get(0).get("2");
// l2 = SavedData.get(0).get("2");
// l3 = SavedData.get(0).get("2");
// l4 = SavedData.get(0).get("2");
// l5 = SavedData.get(0).get("2");
// l6 = SavedData.get(0).get("2");
// l7 = SavedData.get(0).get("2");
// l8 = SavedData.get(0).get("2");
// l9 = SavedData.get(0).get("2");
// l10 = SavedData.get(0).get("2");
// l11 = SavedData.get(0).get("2");
// l12 = SavedData.get(0).get("2");
//
//
// if(Objects.equals(l1, "1")){
// L1.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l2, "1")){
// L2.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l3, "1")){
// L3.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l4, "1")){
// L4.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l5, "1")){
// L5.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l6, "1")){
// L6.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l7, "1")){
// L7.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l8, "1")){
// L8.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l9, "1")){
// L9.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l10, "1")){
// L10.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l11, "1")){
// L11.setBackgroundColor(Color.RED);
// }else if(Objects.equals(l12, "1")){
// L12.setBackgroundColor(Color.RED);
// }
// }
}
@Override
protected void onPostExecute(String s) {
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected String doInBackground(String... strings) {
try {
String Url = BaseURL.get_url() + "slot_availability";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(Url)
.get()
.build();
try (Response response = client.newCall(request).execute()) {
ResponseBody body = response.body();
JSONArray json = new JSONArray(body.string());
System.out.println(json);
for (int i = 0; i < json.length(); i++) {
l1 = json.getJSONObject(0).getString("1");
l2 = json.getJSONObject(0).getString("2");
l3 = json.getJSONObject(0).getString("3");
l4 = json.getJSONObject(0).getString("4");
l5 = json.getJSONObject(0).getString("5");
l6 = json.getJSONObject(0).getString("6");
l7 = json.getJSONObject(0).getString("7");
l8 = json.getJSONObject(0).getString("8");
l9 = json.getJSONObject(0).getString("9");
l10 = json.getJSONObject(0).getString("10");
l11 = json.getJSONObject(0).getString("11");
l12 = json.getJSONObject(0).getString("12");
}
if(Objects.equals(l1, "1")){
L1.setBackgroundColor(Color.RED);
}if(Objects.equals(l2, "1")){
L2.setBackgroundColor(Color.RED);
}if(Objects.equals(l3, "1")){
L3.setBackgroundColor(Color.RED);
}if(Objects.equals(l4, "1")){
L4.setBackgroundColor(Color.RED);
}if(Objects.equals(l5, "1")){
L5.setBackgroundColor(Color.RED);
}if(Objects.equals(l6, "1")){
L6.setBackgroundColor(Color.RED);
}if(Objects.equals(l7, "1")){
L7.setBackgroundColor(Color.RED);
}if(Objects.equals(l8, "1")){
L8.setBackgroundColor(Color.RED);
}if(Objects.equals(l9, "1")){
L9.setBackgroundColor(Color.RED);
}if(Objects.equals(l10, "1")){
L10.setBackgroundColor(Color.RED);
}if(Objects.equals(l11, "1")){
L11.setBackgroundColor(Color.RED);
}if(Objects.equals(l12, "1")){
L12.setBackgroundColor(Color.RED);
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return null;
} finally {
}
}
}
private void confirmAlert(String slot, String status, LinearLayout layout) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(ParkingSlots.this);
builder1.setMessage("Do you want to reserve this parking slot?");
builder1.setCancelable(true);
builder1.setPositiveButton(
"Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Sqlitedb.InsertData(ParkingSlots.this, "ParkingSlots",
"slot,status",
"'" + slot + "','" + status + "'");
layout.setBackgroundColor(Color.RED);
}
});
builder1.setNegativeButton(
"No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
}
\ No newline at end of file
package com.example.vehicleparkingsystem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.vehicleparkingsystem.Models.Users;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Register extends AppCompatActivity {
EditText editText1;
EditText editText2;
EditText editText3;
EditText editText4;
EditText editText5;
EditText editText6;
Button reg;
TextView textView;
FirebaseDatabase rootNode;
DatabaseReference reference;
FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
editText1=(EditText)findViewById(R.id.Uname);
editText2=(EditText)findViewById(R.id.Remail);
editText3=(EditText)findViewById(R.id.Age);
editText4=(EditText)findViewById(R.id.contct);
editText5=(EditText)findViewById(R.id.password);
editText6=(EditText)findViewById(R.id.vehicle);
reg=(Button)findViewById(R.id.register);
textView=(TextView)findViewById(R.id.gotologin);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
}
});
firebaseAuth=FirebaseAuth.getInstance();
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reference = FirebaseDatabase.getInstance().getReference("User");
// reference = rootNode.getReference("Users");
final String namee = editText1.getText().toString();
final String emaill = editText2.getText().toString();
final String age = editText3.getText().toString();
final String phonee = editText4.getText().toString();
final String pass = editText5.getText().toString();
final String vehicle = editText6.getText().toString();
if (!validateUserName() | !validateEmail() | !validateAge() | !validatePhone() | !validatePassword()) {
Toast.makeText(Register.this, "Sign up failed", Toast.LENGTH_SHORT).show();
}
else{
firebaseAuth.createUserWithEmailAndPassword(emaill, pass)
.addOnCompleteListener(Register.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userid = user.getUid();
Users members = new Users(namee,emaill,age,phonee,vehicle,pass);
reference.child(userid).setValue(members);
System.out.println(members);
Toast.makeText(Register.this, "Sign up successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, Dashboard.class);
startActivity(intent);
} else {
Toast.makeText(Register.this, "Sign up failed", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
public boolean validateUserName() {
String value = editText1.getText().toString();
String noWhiteSpace = "\\A\\w{4,20}\\z";
if (value.isEmpty()) {
editText1.setError("Field cannot be empty");
return false;
} else if (value.length() >= 15) {
editText1.setError("Username too long. limit to 15 characters");
return false;
} else if (!value.matches(noWhiteSpace)) {
editText1.setError("White Spaces are not allowed");
return false;
} else {
editText1.setError(null);
return true;
}
}
public boolean validateEmail() {
String value = editText2.getText().toString();
String emailPattern = "[a-zA-Z0-9._-]+@[a-z].+[a-z]+\\.+[a-z]+"; //Regex Expression
if (value.isEmpty()) {
editText2.setError("Field cannot be empty");
return false;
} else if (!value.matches(emailPattern)) {
editText2.setError("Invalid email address");
return false;
} else {
editText2.setError(null);
return true;
}
}
public boolean validateAge() {
String value = editText3.getText().toString();
if (value.isEmpty()) {
editText3.setError("Field cannot be empty");
return false;
} else {
editText3.setError(null);
return true;
}
}
public boolean validatePhone() {
String value = editText4.getText().toString();
if (value.isEmpty()) {
editText4.setError("Field cannot be empty");
return false;
} else {
editText4.setError(null);
return true;
}
}
public boolean validatePassword() {
String value = editText5.getText().toString();
String password = "^" +
//"(?=.*[0-9])" + //at least 1 digit
//"(?=.*[a-z])" + //at least 1 lower case letter
//"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])" + //any letter
"(?=.*[@#$%^&+=])" + //at least 1 special character
"(?=\\S+$)" + //no white spaces
".{2,}" + //at least 2 characters
"$";
if (value.isEmpty()) {
editText5.setError("Field cannot be empty");
return false;
} else if (!value.matches(password)) {
editText5.setError("Password must have at least 1 special character, 2 numbers and letters");
return false;
} else {
editText5.setError(null);
return true;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment