@IgnoreExtraProperties
public class Profile {
private String displayName;
private String statusMessage;
private DatabaseReference contacts;
private String thumbUrl;
private String imageUrl;
private String userId;
private String pushId;
private String theme;
public Profile() {
// Default constructor required for calls to DataSnapshot.getValue(Profile.class)
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String profileName) {
this.displayName = profileName;
}
public String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public DatabaseReference getContacts() {
return contacts;
}
public void setContacts(DatabaseReference contacts) {
this.contacts = contacts;
}
public String getThumbUrl() {
return thumbUrl;
}
public void setThumbUrl(String thumbURL) {
this.thumbUrl = thumbURL;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getPushId() {
return pushId;
}
public void setPushId(String pushId) {
this.pushId = pushId;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
@Exclude
public HashMap<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
if (displayName != null) {
result.put(Config.KEY_DISPLAY_NAME, displayName);
}
if (statusMessage != null) {
result.put(Config.KEY_STATUS_MESSAGE, statusMessage);
}
if (thumbUrl != null) {
result.put(Config.KEY_THUMB_URL, thumbUrl);
}
if (imageUrl != null) {
result.put(Config.KEY_IMAGE_URL, imageUrl);
}
if (pushId != null) {
result.put(Config.KEY_PUSH_ID, pushId);
}
if (theme != null) {
result.put(Config.KEY_THEME, theme);
}
return result;
}
}
public static void getProfile(final String userId, final ProfileListener.onLoad onLoad) {
//create a profile reference
//use the single event listener to retrieve data
final DatabaseReference profileReference = FirebaseDatabase.getInstance().getReference().child(Config.REF_PROFILES).child(userId);
profileReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot profileSnapshot) {
// new Testable.Spec(userId).describe("change event").expect(profileSnapshot.getValue()).run();
if (profileSnapshot.exists()) {
Profile profile = profileSnapshot.getValue(Profile.class);
profile.setUserId(profileSnapshot.getKey());
// profile.setDisplayName(userContact.getDisplayName());
onLoad.load(profile);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}