예제 #1
0
 private void addAccount(AccountItem accountItem) {
   accountItems.put(accountItem.getAccount(), accountItem);
   if (accountItem.isEnabled()) enabledAccounts.add(accountItem.getAccount());
   for (OnAccountAddedListener listener : application.getManagers(OnAccountAddedListener.class))
     listener.onAccountAdded(accountItem);
   if (accountItem.isEnabled()) {
     onAccountEnabled(accountItem);
     if (accountItem.getRawStatusMode().isOnline()) onAccountOnline(accountItem);
   }
   onAccountChanged(accountItem.getAccount());
 }
예제 #2
0
 /**
  * Save status in presets.
  *
  * @param statusMode
  * @param statusText
  */
 private void addSavedStatus(final StatusMode statusMode, final String statusText) {
   SavedStatus savedStatus = new SavedStatus(statusMode, statusText);
   if (savedStatuses.contains(savedStatus)) return;
   savedStatuses.add(savedStatus);
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               StatusTable.getInstance().write(statusMode, statusText);
             }
           });
 }
예제 #3
0
 /**
  * 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
  * @param host
  * @param port
  * @param serverName
  * @param userName
  * @param storePassword
  * @param password
  * @param resource
  * @param priority
  * @param enabled
  * @param saslEnabled
  * @param tlsMode
  * @param compression
  * @param syncable
  * @param archiveMode
  */
 public void updateAccount(
     String account,
     boolean custom,
     String host,
     int port,
     String serverName,
     String userName,
     boolean storePassword,
     String password,
     String 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) {
   AccountItem result;
   AccountItem accountItem = getAccount(account);
   if (accountItem.getConnectionSettings().getServerName().equals(serverName)
       && accountItem.getConnectionSettings().getUserName().equals(userName)
       && accountItem.getConnectionSettings().getResource().equals(resource)) {
     result = accountItem;
     boolean reconnect = false;
     if (accountItem.getConnectionSettings().isCustom() != 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) {
       }
     }
     if (result.getArchiveMode() != archiveMode) {
       reconnect =
           (result.getArchiveMode() == ArchiveMode.server) != (archiveMode == ArchiveMode.server);
       result.setArchiveMode(archiveMode);
       for (OnAccountArchiveModeChangedListener listener :
           application.getManagers(OnAccountArchiveModeChangedListener.class))
         listener.onAccountArchiveModeChanged(result);
     }
     if (changed && enabled) {
       enabledAccounts.add(account);
       onAccountEnabled(result);
       if (result.getRawStatusMode().isOnline()) onAccountOnline(result);
     }
     if (changed || reconnect) {
       result.updateConnection(true);
       result.forceReconnect();
     }
     if (changed && !enabled) {
       enabledAccounts.remove(account);
       if (result.getRawStatusMode().isOnline()) onAccountOffline(result);
       onAccountDisabled(result);
     }
     requestToWriteAccount(result);
   } else {
     int colorIndex = accountItem.getColorIndex();
     StatusMode statusMode = accountItem.getRawStatusMode();
     String statusText = accountItem.getStatusText();
     AccountProtocol protocol = accountItem.getConnectionSettings().getProtocol();
     KeyPair keyPair = accountItem.getKeyPair();
     Date lastSync = accountItem.getLastSync();
     removeAccountWithoutCallback(account);
     result =
         addAccount(
             protocol,
             custom,
             host,
             port,
             serverName,
             userName,
             storePassword,
             password,
             resource,
             colorIndex,
             priority,
             statusMode,
             statusText,
             enabled,
             saslEnabled,
             tlsMode,
             compression,
             proxyType,
             proxyHost,
             proxyPort,
             proxyUser,
             proxyPassword,
             syncable,
             keyPair,
             lastSync,
             archiveMode);
   }
   onAccountChanged(result.getAccount());
 }
예제 #4
0
  @Override
  public void onLoad() {
    final Collection<SavedStatus> savedStatuses = new ArrayList<SavedStatus>();
    final Collection<AccountItem> accountItems = new ArrayList<AccountItem>();
    Cursor cursor = StatusTable.getInstance().list();
    try {
      if (cursor.moveToFirst()) {
        do {
          savedStatuses.add(
              new SavedStatus(
                  StatusTable.getStatusMode(cursor), StatusTable.getStatusText(cursor)));
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    cursor = AccountTable.getInstance().list();
    try {
      if (cursor.moveToFirst()) {
        do {
          AccountItem accountItem =
              new AccountItem(
                  AccountTable.getProtocol(cursor),
                  AccountTable.isCustom(cursor),
                  AccountTable.getHost(cursor),
                  AccountTable.getPort(cursor),
                  AccountTable.getServerName(cursor),
                  AccountTable.getUserName(cursor),
                  AccountTable.getResource(cursor),
                  AccountTable.isStorePassword(cursor),
                  AccountTable.getPassword(cursor),
                  AccountTable.getColorIndex(cursor),
                  AccountTable.getPriority(cursor),
                  AccountTable.getStatusMode(cursor),
                  AccountTable.getStatusText(cursor),
                  AccountTable.isEnabled(cursor),
                  AccountTable.isSaslEnabled(cursor),
                  AccountTable.getTLSMode(cursor),
                  AccountTable.isCompression(cursor),
                  AccountTable.getProxyType(cursor),
                  AccountTable.getProxyHost(cursor),
                  AccountTable.getProxyPort(cursor),
                  AccountTable.getProxyUser(cursor),
                  AccountTable.getProxyPassword(cursor),
                  AccountTable.isSyncable(cursor),
                  AccountTable.getKeyPair(cursor),
                  AccountTable.getLastSync(cursor),
                  AccountTable.getArchiveMode(cursor));
          accountItem.setId(AccountTable.getId(cursor));
          accountItems.add(accountItem);
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    Application.getInstance()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                onLoaded(savedStatuses, accountItems);
              }
            });
  }
예제 #5
0
 public void onAccountChanged(String account) {
   Collection<String> accounts = new ArrayList<String>(1);
   accounts.add(account);
   onAccountsChanged(accounts);
 }