Search in sources :

Example 1 with AccountRealm

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);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Localpart(org.jxmpp.jid.parts.Localpart) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) Realm(io.realm.Realm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 2 with AccountRealm

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();
}
Also used : AccountRealm(com.xabber.android.data.database.realm.AccountRealm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) Cursor(android.database.Cursor) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) PatreonRealm(com.xabber.android.data.database.realm.PatreonRealm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) DynamicRealm(io.realm.DynamicRealm) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) PatreonGoalRealm(com.xabber.android.data.database.realm.PatreonGoalRealm) ChatDataRealm(com.xabber.android.data.database.realm.ChatDataRealm) NotificationStateRealm(com.xabber.android.data.database.realm.NotificationStateRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm)

Example 3 with AccountRealm

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;
}
Also used : AccountRealm(com.xabber.android.data.database.realm.AccountRealm)

Example 4 with 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();
}
Also used : AccountRealm(com.xabber.android.data.database.realm.AccountRealm) Realm(io.realm.Realm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Example 5 with AccountRealm

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);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) AccountRealm(com.xabber.android.data.database.realm.AccountRealm) Realm(io.realm.Realm) AccountRealm(com.xabber.android.data.database.realm.AccountRealm)

Aggregations

AccountRealm (com.xabber.android.data.database.realm.AccountRealm)5 Realm (io.realm.Realm)4 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 ConnectionSettings (com.xabber.android.data.connection.ConnectionSettings)1 ChatDataRealm (com.xabber.android.data.database.realm.ChatDataRealm)1 EmailRealm (com.xabber.android.data.database.realm.EmailRealm)1 NotificationStateRealm (com.xabber.android.data.database.realm.NotificationStateRealm)1 PatreonGoalRealm (com.xabber.android.data.database.realm.PatreonGoalRealm)1 PatreonRealm (com.xabber.android.data.database.realm.PatreonRealm)1 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)1 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)1 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)1 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)1 DynamicRealm (io.realm.DynamicRealm)1 ArrayList (java.util.ArrayList)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1 Localpart (org.jxmpp.jid.parts.Localpart)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1