Search in sources :

Example 1 with XabberAccountRealm

use of com.xabber.android.data.database.realm.XabberAccountRealm in project xabber-android by redsolution.

the class XabberAccountManager method deleteXabberAccountFromRealm.

public boolean deleteXabberAccountFromRealm() {
    final boolean[] success = new boolean[1];
    Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
    final RealmResults<XabberAccountRealm> results = realm.where(XabberAccountRealm.class).findAll();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            success[0] = results.deleteAllFromRealm();
        }
    });
    realm.close();
    return success[0];
}
Also used : XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) 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)

Example 2 with XabberAccountRealm

use of com.xabber.android.data.database.realm.XabberAccountRealm in project xabber-android by redsolution.

the class XabberAccountManager method loadXabberAccountFromRealm.

@Nullable
public XabberAccount loadXabberAccountFromRealm() {
    XabberAccount xabberAccount = null;
    Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
    RealmResults<XabberAccountRealm> xabberAccounts = realm.where(XabberAccountRealm.class).findAll();
    for (XabberAccountRealm xabberAccountRealm : xabberAccounts) {
        xabberAccount = xabberAccountRealmToPOJO(xabberAccountRealm);
    }
    realm.close();
    return xabberAccount;
}
Also used : XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) 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) Nullable(android.support.annotation.Nullable)

Example 3 with XabberAccountRealm

use of com.xabber.android.data.database.realm.XabberAccountRealm 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)3 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)3 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)3 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)3 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)3 Realm (io.realm.Realm)3 Nullable (android.support.annotation.Nullable)1 RealmList (io.realm.RealmList)1