Search in sources :

Example 1 with AbstractXMPPConnection

use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.

the class ConnectionItem method disconnect.

/**
     * Starts disconnection in another thread.
     */
protected void disconnect(final ConnectionThread connectionThread) {
    Thread thread = new Thread("Disconnection thread for " + this) {

        @Override
        public void run() {
            AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
            if (xmppConnection != null)
                try {
                    xmppConnection.disconnect();
                } catch (RuntimeException e) {
                // connectionClose() in smack can fail.
                }
        }
    };
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.setDaemon(true);
    thread.start();
}
Also used : AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 2 with AbstractXMPPConnection

use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.

the class ClientStateManager method sendClientState.

protected static void sendClientState(PlainStreamElement element) {
    AccountManager accountManager = AccountManager.getInstance();
    for (String accountName : accountManager.getAccounts()) {
        AccountItem account = accountManager.getAccount(accountName);
        if (account == null) {
            continue;
        }
        ConnectionThread connectionThread = account.getConnectionThread();
        if (connectionThread == null) {
            continue;
        }
        AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
        if (xmppConnection == null) {
            continue;
        }
        if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
            try {
                xmppConnection.send(element);
            } catch (SmackException.NotConnectedException e) {
            // not connected
            }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) AccountManager(com.xabber.android.data.account.AccountManager) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 3 with AbstractXMPPConnection

use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.

the class VCardManager method saveVCard.

public void saveVCard(final String account, final VCard vCard) {
    ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
    if (connectionThread == null) {
        onVCardSaveFailed(account);
        return;
    }
    final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
    final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(xmppConnection);
    final Thread thread = new Thread("Save vCard for account " + account) {

        @Override
        public void run() {
            boolean isSuccess = true;
            xmppConnection.setPacketReplyTimeout(120000);
            vCardSaveRequests.add(account);
            try {
                vCardManager.saveVCard(vCard);
                String avatarHash = vCard.getAvatarHash();
                if (avatarHash == null) {
                    avatarHash = AvatarManager.EMPTY_HASH;
                }
                PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
            } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException e) {
                LogManager.w(this, "Error saving vCard: " + e.getMessage());
                isSuccess = false;
            }
            vCardSaveRequests.remove(account);
            xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
            final boolean finalIsSuccess = isSuccess;
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (finalIsSuccess) {
                        onVCardSaveSuccess(account);
                    } else {
                        onVCardSaveFailed(account);
                    }
                }
            });
        }
    };
    thread.start();
}
Also used : ConnectionThread(com.xabber.android.data.connection.ConnectionThread) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) NetworkException(com.xabber.android.data.NetworkException) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 4 with AbstractXMPPConnection

use of org.jivesoftware.smack.AbstractXMPPConnection in project xabber-android by redsolution.

the class RosterManager method getRoster.

@Nullable
private Roster getRoster(String account) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return null;
    }
    final ConnectionThread connectionThread = accountItem.getConnectionThread();
    if (connectionThread == null) {
        return null;
    }
    final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
    if (xmppConnection == null) {
        return null;
    }
    return Roster.getInstanceFor(xmppConnection);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) Nullable(android.support.annotation.Nullable)

Aggregations

AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)4 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)3 AccountItem (com.xabber.android.data.account.AccountItem)2 Nullable (android.support.annotation.Nullable)1 NetworkException (com.xabber.android.data.NetworkException)1 AccountManager (com.xabber.android.data.account.AccountManager)1