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];
}
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;
}
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);
}
Aggregations