Search in sources :

Example 1 with XMPPUserRealm

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;
}
Also used : ArrayList(java.util.ArrayList) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm)

Example 2 with XMPPUserRealm

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);
}
Also used : RealmList(io.realm.RealmList) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm)

Aggregations

EmailRealm (com.xabber.android.data.database.realm.EmailRealm)2 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)2 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)2 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)1 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)1 Realm (io.realm.Realm)1 RealmList (io.realm.RealmList)1 ArrayList (java.util.ArrayList)1