finished edit profile?

This commit is contained in:
IvanaE 2018-11-13 14:21:45 -05:00
parent bf2b4ae004
commit a517c63e7a
4 changed files with 39 additions and 7 deletions

View file

@ -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,9 +57,30 @@ 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());
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();
}
}
}

View file

@ -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();

View file

@ -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,

View file

@ -96,7 +96,7 @@
<CheckBox
android:id="@+id/checkBox"
android:id="@+id/LicensedInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Licensed"