Skip to content

Commit

Permalink
added address class, may need to change up how address is inputted bu…
Browse files Browse the repository at this point in the history
…t that can be done later
  • Loading branch information
Raymond123 committed Oct 17, 2022
1 parent 86335db commit 3e55473
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
58 changes: 52 additions & 6 deletions app/src/main/java/com/mealer/app/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,65 @@ public class User implements Parcelable {
private String firstName;
private String lastName;
private String email;
// TODO change address
private String address;
private Address address;
private String userType;

private static class Address implements Parcelable{
private final String street;
private final String houseNumber;
private final String city;

public Address(String city, String street, String houseNumber){
this.city = city;
this.street = street;
this.houseNumber = houseNumber;
}

protected Address(Parcel in) {
street = in.readString();
houseNumber = in.readString();
city = in.readString();
}

public static final Creator<Address> CREATOR = new Creator<Address>() {
@Override
public Address createFromParcel(Parcel in) {
return new Address(in);
}

@Override
public Address[] newArray(int size) {
return new Address[size];
}
};

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(@NonNull Parcel parcel, int i) {
parcel.writeString(street);
parcel.writeString(houseNumber);
parcel.writeString(city);
}
}

// user constructor
public User(String firstName, String lastName, String email, String address, String userType){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.address = address;
this.address = newAddress(address);
this.userType = userType;
}

private Address newAddress(String address){
String[] tempAddress = address.replace(",", "").split(" ");
return new Address(tempAddress[0], tempAddress[2], tempAddress[1]);
}

// empty user constructor required for taking firebase snapshot
public User() {

Expand All @@ -48,7 +94,7 @@ protected User(Parcel in) {
firstName = in.readString();
lastName = in.readString();
email = in.readString();
address = in.readString();
address = in.readParcelable(address.getClass().getClassLoader());
userType = in.readString();
}

Expand Down Expand Up @@ -88,7 +134,7 @@ public String getEmail() {
return email;
}

public String getAddress() {
public Address getAddress() {
return address;
}

Expand All @@ -107,7 +153,7 @@ public void writeToParcel(@NonNull Parcel parcel, int i) {
parcel.writeString(firstName);
parcel.writeString(lastName);
parcel.writeString(email);
parcel.writeString(address);
parcel.writeParcelable(address, i);
parcel.writeString(userType);
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<string name="last_name">Last Name</string>
<string name="getting_to_know_you">Getting to know you</string>
<string name="age">Age</string>
<string name="address">Address</string>
<string name="address">Address (city, houseNumber street)</string>
<string name="creditNum">Card Number</string>
<string name="creditExpiry">MMYY</string>
<string name="creditSecurity">XXX</string>
Expand Down

0 comments on commit 3e55473

Please sign in to comment.