Search in sources :

Example 51 with AccountItem

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

the class XabberAccountManager method createSyncList.

/**
 * @param remoteList is list of settings from cloud
 * @return list of settings for displaying in sync-dialog
 */
public List<XMPPAccountSettings> createSyncList(List<XMPPAccountSettings> remoteList) {
    List<XMPPAccountSettings> resultList = new ArrayList<>();
    // add remote accounts to list
    for (XMPPAccountSettings remoteItem : remoteList) {
        XMPPAccountSettings.SyncStatus status = XMPPAccountSettings.SyncStatus.remote;
        // if account already exist
        AccountJid accountJid = getExistingAccount(remoteItem.getJid());
        if (accountJid != null) {
            AccountItem localItem = AccountManager.getInstance().getAccount(accountJid);
            if (localItem != null) {
                if (remoteItem.getTimestamp() == localItem.getTimestamp())
                    status = XMPPAccountSettings.SyncStatus.localEqualsRemote;
                else if (remoteItem.getTimestamp() > localItem.getTimestamp())
                    status = XMPPAccountSettings.SyncStatus.remoteNewer;
                else {
                    status = XMPPAccountSettings.SyncStatus.localNewer;
                    remoteItem.setTimestamp(localItem.getTimestamp());
                }
                remoteItem.setSyncNotAllowed(localItem.isSyncNotAllowed());
            }
            remoteItem.setStatus(status);
            remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
            resultList.add(remoteItem);
        } else if (!remoteItem.isDeleted()) {
            remoteItem.setStatus(status);
            remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
            resultList.add(remoteItem);
        }
    }
    // add local accounts to list
    Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
    for (AccountItem localAccount : localAccounts) {
        String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
        boolean exist = false;
        for (XMPPAccountSettings remoteItem : remoteList) {
            if (localJid.equals(remoteItem.getJid())) {
                exist = true;
            }
        }
        if (!exist) {
            XMPPAccountSettings localItem = new XMPPAccountSettings(localJid, false, localAccount.getTimestamp());
            localItem.setOrder(remoteList.size() + localAccount.getOrder());
            localItem.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
            localItem.setStatus(XMPPAccountSettings.SyncStatus.local);
            localItem.setSynchronization(isAccountSynchronize(localItem.getJid()));
            localItem.setSyncNotAllowed(localAccount.isSyncNotAllowed());
            resultList.add(localItem);
        }
    }
    return resultList;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList)

Example 52 with AccountItem

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

the class XabberAccountManager method createSettingsList.

/**
 * @return list of settings from local account for patch to server
 */
public List<XMPPAccountSettings> createSettingsList() {
    List<XMPPAccountSettings> resultList = new ArrayList<>();
    Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
    for (AccountItem localAccount : localAccounts) {
        String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
        if (SettingsManager.isSyncAllAccounts() || isAccountSynchronize(localJid)) {
            XMPPAccountSettings item = new XMPPAccountSettings(localJid, true, localAccount.getTimestamp());
            item.setOrder(localAccount.getOrder());
            item.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
            item.setTimestamp(localAccount.getTimestamp());
            resultList.add(item);
        }
    }
    return resultList;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ArrayList(java.util.ArrayList)

Example 53 with AccountItem

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

the class PushManager method onEndpointRegistered.

public void onEndpointRegistered(String jid, String pushServiceJid, String node) {
    LogManager.d(LOG_TAG, "Received endpoint-registered push. Send push enable iq.");
    AccountJid accountJid = null;
    Collection<AccountJid> accounts = AccountManager.getInstance().getEnabledAccounts();
    for (AccountJid account : accounts) {
        if ((account.getFullJid().asBareJid() + getAndroidId()).equals(jid)) {
            accountJid = account;
            break;
        }
    }
    if (accountJid != null) {
        AccountItem account = AccountManager.getInstance().getAccount(accountJid);
        if (account != null) {
            // save node to account
            AccountManager.getInstance().setPushNode(account, node, pushServiceJid);
            // update push nodes
            updateEnabledPushNodes();
            // enable push on XMPP-server
            sendEnablePushIQ(account, pushServiceJid, node);
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid)

Example 54 with AccountItem

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

the class NotificationManager method updatePersistentNotification.

private void updatePersistentNotification() {
    if (XabberService.getInstance() == null)
        return;
    // we do not want to show persistent notification if there are no enabled accounts
    XabberService.getInstance().changeForeground();
    if (!XabberService.getInstance().needForeground())
        return;
    Collection<AccountJid> accountList = AccountManager.getInstance().getEnabledAccounts();
    if (accountList.isEmpty()) {
        return;
    }
    int waiting = 0;
    int connecting = 0;
    int connected = 0;
    for (AccountJid account : accountList) {
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        if (accountItem == null) {
            continue;
        }
        ConnectionState state = accountItem.getState();
        LogManager.i(this, "updatePersistentNotification account " + account + " state " + state);
        switch(state) {
            case offline:
                break;
            case waiting:
                waiting++;
                break;
            case connecting:
            case registration:
            case authentication:
                connecting++;
                break;
            case connected:
                connected++;
                break;
        }
    }
    final Intent persistentIntent;
    persistentIntent = ContactListActivity.createPersistentIntent(application);
    if (SyncManager.getInstance().isSyncMode()) {
        persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
        persistentNotificationBuilder.setSmallIcon(R.drawable.ic_sync);
        persistentNotificationBuilder.setContentText(application.getString(R.string.connection_state_sync));
    } else {
        if (connected > 0) {
            persistentNotificationBuilder.setColor(persistentNotificationColor);
            persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_online);
        } else {
            persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
            persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_offline);
        }
        persistentNotificationBuilder.setContentText(getConnectionState(waiting, connecting, connected, accountList.size()));
    }
    persistentNotificationBuilder.setContentIntent(PendingIntent.getActivity(application, 0, persistentIntent, PendingIntent.FLAG_UPDATE_CURRENT));
    notify(PERSISTENT_NOTIFICATION_ID, persistentNotificationBuilder.build());
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ConnectionState(com.xabber.android.data.connection.ConnectionState)

Example 55 with AccountItem

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

the class ReceiptManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final Jid from = packet.getFrom();
    if (from == null) {
        return;
    }
    if (!(packet instanceof Message)) {
        return;
    }
    final Message message = (Message) packet;
    if (message.getType() == Message.Type.error) {
        Application.getInstance().runInBackgroundUserRequest(new Runnable() {

            @Override
            public void run() {
                markAsError(account, message);
            }
        });
    } else {
        // TODO setDefaultAutoReceiptMode should be used
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof DeliveryReceiptRequest) {
                String id = AbstractChat.getStanzaId(message);
                if (id == null) {
                    continue;
                }
                Message receipt = new Message(from);
                receipt.addExtension(new DeliveryReceipt(id));
                // the key problem is Thread - smack does not keep it in auto reply
                receipt.setThread(message.getThread());
                receipt.setType(Message.Type.chat);
                try {
                    StanzaSender.sendStanza(account, receipt);
                } catch (NetworkException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) DeliveryReceiptRequest(org.jivesoftware.smackx.receipts.DeliveryReceiptRequest) AccountJid(com.xabber.android.data.entity.AccountJid) DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4