Search in sources :

Example 1 with OnAccountSyncableChangedListener

use of com.xabber.android.data.account.listeners.OnAccountSyncableChangedListener in project xabber-android by redsolution.

the class AccountManager method updateAccount.

/**
 * Update user`s account.
 * <p/>
 * It will reconnect to the server if changes was made.
 * <p/>
 * It will remove old account and create new one if full jid was changed.
 *
 * @param account       full source jid
 */
public void updateAccount(AccountJid account, boolean custom, String host, int port, DomainBareJid serverName, Localpart userName, boolean storePassword, String password, String token, Resourcepart resource, int priority, boolean enabled, boolean saslEnabled, TLSMode tlsMode, boolean compression, ProxyType proxyType, String proxyHost, int proxyPort, String proxyUser, String proxyPassword, boolean syncable, ArchiveMode archiveMode, int colorIndex) {
    AccountItem result;
    AccountItem accountItem = getAccount(account);
    if (accountItem == null) {
        return;
    }
    if (accountItem.getConnectionSettings().getServerName().equals(serverName) && accountItem.getConnectionSettings().getUserName().equals(userName) && accountItem.getConnectionSettings().getResource().equals(resource)) {
        result = accountItem;
        result.setColorIndex(colorIndex);
        boolean reconnect = false;
        if (accountItem.getConnectionSettings().isCustomHostAndPort() != custom || !accountItem.getConnectionSettings().getHost().equals(host) || accountItem.getConnectionSettings().getPort() != port || !accountItem.getConnectionSettings().getPassword().equals(password) || accountItem.getConnectionSettings().getTlsMode() != tlsMode || accountItem.getConnectionSettings().isSaslEnabled() != saslEnabled || accountItem.getConnectionSettings().useCompression() != compression || accountItem.getConnectionSettings().getProxyType() != proxyType || !accountItem.getConnectionSettings().getProxyHost().equals(proxyHost) || accountItem.getConnectionSettings().getProxyPort() != proxyPort || !accountItem.getConnectionSettings().getProxyUser().equals(proxyUser) || !accountItem.getConnectionSettings().getProxyPassword().equals(proxyPassword)) {
            result.updateConnectionSettings(custom, host, port, password, saslEnabled, tlsMode, compression, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
            reconnect = true;
        }
        if (result.isSyncable() != syncable) {
            result.setSyncable(syncable);
            for (OnAccountSyncableChangedListener listener : application.getManagers(OnAccountSyncableChangedListener.class)) {
                listener.onAccountSyncableChanged(result);
            }
        }
        result.setStorePassword(storePassword);
        boolean changed = result.isEnabled() != enabled;
        result.setEnabled(enabled);
        if (result.getPriority() != priority) {
            result.setPriority(priority);
            try {
                PresenceManager.getInstance().resendPresence(account);
            } catch (NetworkException e) {
                LogManager.exception(this, e);
            }
        }
        if (result.getArchiveMode() != archiveMode) {
            result.setArchiveMode(archiveMode);
        }
        if (changed && enabled) {
            onAccountEnabled(result);
            if (result.getRawStatusMode().isOnline()) {
                onAccountOnline(result);
            }
        }
        if (changed || reconnect) {
            result.setSuccessfulConnectionHappened(false);
            result.recreateConnection();
        }
        if (changed && !enabled) {
            if (result.getRawStatusMode().isOnline()) {
                onAccountOffline(result);
            }
            onAccountDisabled(result);
        }
        requestToWriteAccount(result);
    } else {
        StatusMode statusMode = accountItem.getRawStatusMode();
        String statusText = accountItem.getStatusText();
        KeyPair keyPair = accountItem.getKeyPair();
        Date lastSync = accountItem.getLastSync();
        removeAccountWithoutCallback(account);
        result = addAccount(custom, host, port, serverName, userName, storePassword, password, token, resource, colorIndex, accountItem.getOrder(), accountItem.isSyncNotAllowed(), accountItem.getTimestamp(), priority, statusMode, statusText, enabled, saslEnabled, tlsMode, compression, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword, syncable, keyPair, lastSync, archiveMode, false);
    }
    onAccountChanged(result.getAccount());
    // disable sync for account if it use not default settings
    ConnectionSettings connectionSettings = result.getConnectionSettings();
    if (connectionSettings.isCustomHostAndPort() || connectionSettings.getProxyType() != ProxyType.none || connectionSettings.getTlsMode() == TLSMode.legacy) {
        result.setSyncNotAllowed(true);
    } else
        result.setSyncNotAllowed(false);
}
Also used : OnAccountSyncableChangedListener(com.xabber.android.data.account.listeners.OnAccountSyncableChangedListener) KeyPair(java.security.KeyPair) NetworkException(com.xabber.android.data.NetworkException) Date(java.util.Date) ConnectionSettings(com.xabber.android.data.connection.ConnectionSettings)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)1 OnAccountSyncableChangedListener (com.xabber.android.data.account.listeners.OnAccountSyncableChangedListener)1 ConnectionSettings (com.xabber.android.data.connection.ConnectionSettings)1 KeyPair (java.security.KeyPair)1 Date (java.util.Date)1