use of com.xabber.android.data.database.realm.AccountRealm in project xabber-android by redsolution.
the class AccountManager method onLoad.
@Override
public void onLoad() {
final Collection<SavedStatus> savedStatuses = loadSavedStatuses();
final Collection<AccountItem> accountItems = new ArrayList<>();
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
RealmResults<AccountRealm> accountRealms = realm.where(AccountRealm.class).findAll();
LogManager.i(LOG_TAG, "onLoad got realm accounts: " + accountRealms.size());
for (AccountRealm accountRealm : accountRealms) {
DomainBareJid serverName = null;
try {
serverName = JidCreate.domainBareFrom(accountRealm.getServerName());
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
}
Localpart userName = null;
try {
userName = Localpart.from(accountRealm.getUserName());
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
}
Resourcepart resource = null;
try {
resource = Resourcepart.from(accountRealm.getResource());
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
}
if (serverName == null || userName == null || resource == null) {
LogManager.e(LOG_TAG, "could not create account. username " + userName + ", server name " + serverName + ", resource " + resource);
continue;
}
// fix for db migration
int order = accountRealm.getOrder();
if (order == 0) {
for (AccountItem item : accountItems) {
if (item.getOrder() > order)
order = item.getOrder();
}
order++;
}
AccountItem accountItem = new AccountItem(accountRealm.isCustom(), accountRealm.getHost(), accountRealm.getPort(), serverName, userName, resource, accountRealm.isStorePassword(), accountRealm.getPassword(), accountRealm.getToken(), accountRealm.getColorIndex(), order, accountRealm.isSyncNotAllowed(), accountRealm.getTimestamp(), accountRealm.getPriority(), accountRealm.getStatusMode(), accountRealm.getStatusText(), accountRealm.isEnabled(), accountRealm.isSaslEnabled(), accountRealm.getTlsMode(), accountRealm.isCompression(), accountRealm.getProxyType(), accountRealm.getProxyHost(), accountRealm.getProxyPort(), accountRealm.getProxyUser(), accountRealm.getProxyPassword(), accountRealm.isSyncable(), accountRealm.getKeyPair(), accountRealm.getLastSync(), accountRealm.getArchiveMode());
accountItem.setId(accountRealm.getId());
accountItem.setClearHistoryOnExit(accountRealm.isClearHistoryOnExit());
if (accountRealm.getMamDefaultBehavior() != null) {
accountItem.setMamDefaultBehaviour(accountRealm.getMamDefaultBehavior());
}
if (accountRealm.getLoadHistorySettings() != null) {
accountItem.setLoadHistorySettings(accountRealm.getLoadHistorySettings());
}
accountItem.setSuccessfulConnectionHappened(accountRealm.isSuccessfulConnectionHappened());
accountItems.add(accountItem);
}
realm.close();
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
onLoaded(savedStatuses, accountItems);
}
});
}
use of com.xabber.android.data.database.realm.AccountRealm in project xabber-android by redsolution.
the class RealmManager method copyDataFromSqliteToRealm.
void copyDataFromSqliteToRealm() {
Realm realm = getNewBackgroundRealm();
realm.beginTransaction();
LogManager.i(LOG_TAG, "copying from SQLite to Realm");
long counter = 0;
Cursor cursor = AccountTable.getInstance().list();
while (cursor.moveToNext()) {
AccountRealm accountRealm = AccountTable.createAccountRealm(cursor);
realm.copyToRealm(accountRealm);
counter++;
}
cursor.close();
LogManager.i(LOG_TAG, counter + " accounts copied to Realm");
LogManager.i(LOG_TAG, "onSuccess. removing accounts from SQLite:");
int removedAccounts = AccountTable.getInstance().removeAllAccounts();
LogManager.i(LOG_TAG, removedAccounts + " accounts removed from SQLite");
realm.commitTransaction();
realm.close();
}
use of com.xabber.android.data.database.realm.AccountRealm in project xabber-android by redsolution.
the class AccountTable method createAccountRealm.
public static AccountRealm createAccountRealm(Cursor cursor) {
AccountRealm accountRealm = new AccountRealm();
accountRealm.setCustom(AccountTable.isCustom(cursor));
accountRealm.setHost(AccountTable.getHost(cursor));
accountRealm.setPort(AccountTable.getPort(cursor));
accountRealm.setServerName(AccountTable.getServerName(cursor));
accountRealm.setUserName(AccountTable.getUserName(cursor));
accountRealm.setResource(AccountTable.getResource(cursor));
accountRealm.setStorePassword(AccountTable.isStorePassword(cursor));
accountRealm.setPassword(AccountTable.getPassword(cursor));
accountRealm.setColorIndex(AccountTable.getColorIndex(cursor));
accountRealm.setPriority(AccountTable.getPriority(cursor));
accountRealm.setStatusMode(AccountTable.getStatusMode(cursor));
accountRealm.setStatusText(AccountTable.getStatusText(cursor));
accountRealm.setEnabled(AccountTable.isEnabled(cursor));
accountRealm.setSaslEnabled(AccountTable.isSaslEnabled(cursor));
accountRealm.setTlsMode(AccountTable.getTLSMode(cursor));
accountRealm.setCompression(AccountTable.isCompression(cursor));
accountRealm.setProxyType(AccountTable.getProxyType(cursor));
accountRealm.setProxyHost(AccountTable.getProxyHost(cursor));
accountRealm.setProxyPort(AccountTable.getProxyPort(cursor));
accountRealm.setProxyUser(AccountTable.getProxyUser(cursor));
accountRealm.setProxyPassword(AccountTable.getProxyPassword(cursor));
accountRealm.setSyncable(AccountTable.isSyncable(cursor));
accountRealm.setKeyPair(AccountTable.getKeyPair(cursor));
accountRealm.setLastSync(AccountTable.getLastSync(cursor));
accountRealm.setArchiveMode(AccountTable.getArchiveMode(cursor));
return accountRealm;
}
use of com.xabber.android.data.database.realm.AccountRealm in project xabber-android by redsolution.
the class AccountTable method saveAccountRealm.
private void saveAccountRealm(String id, AccountItem accountItem) {
AccountRealm accountRealm = new AccountRealm(id);
ConnectionSettings connectionSettings = accountItem.getConnectionSettings();
accountRealm.setCustom(connectionSettings.isCustomHostAndPort());
accountRealm.setHost(connectionSettings.getHost());
accountRealm.setPort(connectionSettings.getPort());
accountRealm.setServerName(connectionSettings.getServerName().getDomain().toString());
accountRealm.setUserName(connectionSettings.getUserName().toString());
String password = connectionSettings.getPassword();
if (!accountItem.isStorePassword()) {
password = AccountItem.UNDEFINED_PASSWORD;
}
accountRealm.setPassword(password);
accountRealm.setToken(connectionSettings.getToken());
accountRealm.setOrder(accountItem.getOrder());
accountRealm.setSyncNotAllowed(accountItem.isSyncNotAllowed());
accountRealm.setTimestamp(accountItem.getTimestamp());
accountRealm.setResource(connectionSettings.getResource().toString());
accountRealm.setColorIndex(accountItem.getColorIndex());
accountRealm.setPriority(accountItem.getPriority());
accountRealm.setStatusMode(accountItem.getRawStatusMode());
accountRealm.setStatusText(accountItem.getStatusText());
accountRealm.setEnabled(accountItem.isEnabled());
accountRealm.setSaslEnabled(connectionSettings.isSaslEnabled());
accountRealm.setTlsMode(connectionSettings.getTlsMode());
accountRealm.setCompression(connectionSettings.useCompression());
accountRealm.setProxyType(connectionSettings.getProxyType());
accountRealm.setProxyHost(connectionSettings.getProxyHost());
accountRealm.setProxyPort(connectionSettings.getProxyPort());
accountRealm.setProxyUser(connectionSettings.getProxyUser());
accountRealm.setProxyPassword(connectionSettings.getProxyPassword());
accountRealm.setSyncable(accountItem.isSyncable());
accountRealm.setStorePassword(accountItem.isStorePassword());
accountRealm.setKeyPair(accountItem.getKeyPair());
accountRealm.setLastSync(accountItem.getLastSync());
accountRealm.setArchiveMode(accountItem.getArchiveMode());
accountRealm.setClearHistoryOnExit(accountItem.isClearHistoryOnExit());
accountRealm.setMamDefaultBehavior(accountItem.getMamDefaultBehaviour());
accountRealm.setLoadHistorySettings(accountItem.getLoadHistorySettings());
accountRealm.setSuccessfulConnectionHappened(accountItem.isSuccessfulConnectionHappened());
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
realm.beginTransaction();
realm.copyToRealmOrUpdate(accountRealm);
realm.commitTransaction();
realm.close();
}
use of com.xabber.android.data.database.realm.AccountRealm in project xabber-android by redsolution.
the class AccountTable method remove.
/**
* Delete record from database.
*
* @return <b>True</b> if record was removed.
*/
public void remove(AccountJid account, String id) {
Realm realm = RealmManager.getInstance().getNewBackgroundRealm();
realm.beginTransaction();
AccountRealm accountRealm = realm.where(AccountRealm.class).equalTo(AccountRealm.Fields.ID, id).findFirst();
if (accountRealm != null) {
accountRealm.deleteFromRealm();
}
realm.commitTransaction();
realm.close();
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields._ID + " = ?", new String[] { String.valueOf(id) });
databaseManager.removeAccount(account);
}
Aggregations