use of com.xabber.android.data.database.realm.XMPPUserRealm in project xabber-android by redsolution.
the class XabberAccountManager method xabberAccountRealmToPOJO.
public static XabberAccount xabberAccountRealmToPOJO(XabberAccountRealm accountRealm) {
if (accountRealm == null)
return null;
XabberAccount xabberAccount = null;
List<XMPPUser> xmppUsers = new ArrayList<>();
for (XMPPUserRealm xmppUserRealm : accountRealm.getXmppUsers()) {
XMPPUser xmppUser = new XMPPUser(Integer.parseInt(xmppUserRealm.getId()), xmppUserRealm.getUsername(), xmppUserRealm.getHost(), xmppUserRealm.getRegistration_date());
xmppUsers.add(xmppUser);
}
List<EmailDTO> emails = new ArrayList<>();
for (EmailRealm emailRealm : accountRealm.getEmails()) {
EmailDTO email = new EmailDTO(Integer.parseInt(emailRealm.getId()), emailRealm.getEmail(), emailRealm.isVerified(), emailRealm.isPrimary());
emails.add(email);
}
List<SocialBindingDTO> socials = new ArrayList<>();
for (SocialBindingRealm socialRealm : accountRealm.getSocialBindings()) {
SocialBindingDTO social = new SocialBindingDTO(Integer.parseInt(socialRealm.getId()), socialRealm.getProvider(), socialRealm.getUid(), socialRealm.getFirstName(), socialRealm.getLastName());
socials.add(social);
}
xabberAccount = new XabberAccount(Integer.parseInt(accountRealm.getId()), accountRealm.getAccountStatus(), accountRealm.getUsername(), accountRealm.getFirstName(), accountRealm.getLastName(), accountRealm.getRegisterDate(), accountRealm.getLanguage(), xmppUsers, emails, socials, accountRealm.getToken(), accountRealm.isNeedToVerifyPhone(), accountRealm.getPhone());
return xabberAccount;
}
use of com.xabber.android.data.database.realm.XMPPUserRealm in project xabber-android by redsolution.
the class XabberAccountManager method saveOrUpdateXabberAccountToRealm.
public Single<XabberAccount> saveOrUpdateXabberAccountToRealm(XabberAccountDTO xabberAccount, String token) {
XabberAccount account;
XabberAccountRealm xabberAccountRealm = new XabberAccountRealm(String.valueOf(xabberAccount.getId()));
xabberAccountRealm.setToken(token);
xabberAccountRealm.setAccountStatus(xabberAccount.getAccountStatus());
xabberAccountRealm.setUsername(xabberAccount.getUsername());
xabberAccountRealm.setFirstName(xabberAccount.getFirstName());
xabberAccountRealm.setLastName(xabberAccount.getLastName());
xabberAccountRealm.setLanguage(xabberAccount.getLanguage());
xabberAccountRealm.setRegisterDate(xabberAccount.getRegistrationDate());
xabberAccountRealm.setNeedToVerifyPhone(xabberAccount.isNeedToVerifyPhone());
xabberAccountRealm.setPhone(xabberAccount.getPhone());
RealmList<XMPPUserRealm> realmUsers = new RealmList<>();
for (XMPPUserDTO user : xabberAccount.getXmppUsers()) {
XMPPUserRealm realmUser = new XMPPUserRealm(String.valueOf(user.getId()));
realmUser.setUsername(user.getUsername());
realmUser.setHost(user.getHost());
realmUser.setRegistration_date(user.getRegistrationDate());
realmUsers.add(realmUser);
}
xabberAccountRealm.setXmppUsers(realmUsers);
RealmList<EmailRealm> realmEmails = new RealmList<>();
for (EmailDTO email : xabberAccount.getEmails()) {
EmailRealm realmEmail = new EmailRealm(String.valueOf(email.getId()));
realmEmail.setEmail(email.getEmail());
realmEmail.setPrimary(email.isPrimary());
realmEmail.setVerified(email.isVerified());
realmEmails.add(realmEmail);
}
xabberAccountRealm.setEmails(realmEmails);
RealmList<SocialBindingRealm> realmSocials = new RealmList<>();
for (SocialBindingDTO social : xabberAccount.getSocialBindings()) {
SocialBindingRealm realmSocial = new SocialBindingRealm(String.valueOf(social.getId()));
realmSocial.setProvider(social.getProvider());
realmSocial.setUid(social.getUid());
realmSocial.setFirstName(social.getFirstName());
realmSocial.setLastName(social.getLastName());
realmSocials.add(realmSocial);
}
xabberAccountRealm.setSocialBindings(realmSocials);
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
realm.beginTransaction();
XabberAccountRealm accountRealm = realm.copyToRealmOrUpdate(xabberAccountRealm);
account = xabberAccountRealmToPOJO(accountRealm);
realm.commitTransaction();
realm.close();
this.account = account;
return Single.just(account);
}
Aggregations