From 995142d1173fd3cc9ea6ce9be02aa4bc6f826e98 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Tue, 13 Nov 2018 14:21:45 -0500 Subject: [PATCH] finished edit profile? --- .../olympus/olympusservices/EditProfile.java | 40 +++++++++++++++++-- .../olympus/olympusservices/SignUp.java | 2 +- .../olympus/olympusservices/SignUpPart2.java | 2 +- .../main/res/layout/activity_edit_profile.xml | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java index 1175604..8804922 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; @@ -18,14 +19,24 @@ public class EditProfile extends AppCompatActivity { Bundle bundle = getIntent().getExtras(); username = bundle.getString("username"); dbHelper = new DBHelper(this); - UserType user; - user = dbHelper.findUserByUsername(username); + ServiceProvider user; + user = (ServiceProvider)dbHelper.findUserByUsername(username); TextView firstname = findViewById(R.id.FirstNameInput); TextView lastname = findViewById(R.id.LastNameInput); TextView password = findViewById(R.id.PasswordInput); + TextView companyname = findViewById(R.id.CompanyNameInput); + TextView address = findViewById(R.id.AddressInput); + TextView phonenumber = findViewById(R.id.PhoneNumberInput); + CheckBox licensed = findViewById(R.id.LicensedInput); + + firstname.setText(user.getFirstname()); lastname.setText(user.getLastname()); password.setText(user.getPassword()); + companyname.setText(user.getCompanyname()); + address.setText(user.getAddress()); + phonenumber.setText(user.getPhonenumber()); + licensed.setChecked(user.isLicensed()); } @@ -46,8 +57,29 @@ public class EditProfile extends AppCompatActivity { TextView firstname = findViewById(R.id.FirstNameInput); TextView lastname = findViewById(R.id.LastNameInput); TextView password = findViewById(R.id.PasswordInput); - dbHelper.updateUserInfo(username, password.getText().toString(), firstname.getText().toString(), lastname.getText().toString()); - Toast.makeText(this, "Profile has been updated", Toast.LENGTH_LONG).show(); + TextView companyname = findViewById(R.id.CompanyNameInput); + TextView address = findViewById(R.id.AddressInput); + TextView phonenumber = findViewById(R.id.PhoneNumberInput); + CheckBox licensed = findViewById(R.id.LicensedInput); + + if(password.getText().toString().length()>5 && firstname.getText().toString().length()>0 + && lastname.getText().toString().length()>0 && companyname.getText().toString().length()>0 + && address.getText().toString().length()>0 && phonenumber.getText().toString().length()>0 + && password.getText().toString().matches("[a-zA-Z0-9]*") + && firstname.getText().toString().matches("[a-zA-Z]*") + && lastname.getText().toString().matches("[a-zA-Z]*") + && companyname.getText().toString().matches("^[a-zA-Z0-9_ ]*$") + && address.getText().toString().matches("^[a-zA-Z0-9_ ]*$") + && phonenumber.getText().toString().matches("^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$") + ) { + + dbHelper.updateUserInfo(username, password.getText().toString(), firstname.getText().toString(), lastname.getText().toString(), + address.getText().toString(), phonenumber.getText().toString(), companyname.getText().toString(), licensed.isChecked()); + Toast.makeText(this, "Profile has been updated", Toast.LENGTH_LONG).show(); + } + else{ + Toast.makeText(this, "Fields cannot be empty and must be formatted correctly", Toast.LENGTH_LONG).show(); + } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java index 9eda906..4210de0 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java @@ -75,7 +75,7 @@ public class SignUp extends AppCompatActivity { intent2.putExtra("lastname", lastname); intent2.putExtra("username", username); intent2.putExtra("password", password); - startActivity(intent); + startActivity(intent2); finish(); }else{ Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show(); diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUpPart2.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUpPart2.java index 9d8b4ba..d3b4672 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUpPart2.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUpPart2.java @@ -34,7 +34,7 @@ public class SignUpPart2 extends AppCompatActivity { boolean licensed = ((CheckBox) findViewById(R.id.LicensedInput)).isChecked(); if(companyname.length()>0 && address.length()>0 && phonenumber.length()>0 - && companyname.matches("[a-zA-Z0-9]*") && address.matches("[a-zA-Z]*") + && companyname.matches("^[a-zA-Z0-9_ ]*$") && address.matches("^[a-zA-Z0-9_ ]*$") && phonenumber.matches("^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$")) { ServiceProvider serviceProvider = new ServiceProvider(username, password, firstname, lastname, diff --git a/OlympusServices/app/src/main/res/layout/activity_edit_profile.xml b/OlympusServices/app/src/main/res/layout/activity_edit_profile.xml index 0806dfd..e9a8800 100644 --- a/OlympusServices/app/src/main/res/layout/activity_edit_profile.xml +++ b/OlympusServices/app/src/main/res/layout/activity_edit_profile.xml @@ -96,7 +96,7 @@