Search in sources :

Example 66 with AccountItem

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

the class ConnectionManager method processPacket.

public void processPacket(ConnectionThread connectionThread, Stanza stanza) {
    if (!managedConnections.contains(connectionThread)) {
        return;
    }
    ConnectionItem connectionItem = connectionThread.getConnectionItem();
    if (stanza instanceof IQ && connectionItem instanceof AccountItem) {
        IQ iq = (IQ) stanza;
        String packetId = iq.getStanzaId();
        if (packetId != null && (iq.getType() == Type.result || iq.getType() == Type.error)) {
            String account = ((AccountItem) connectionItem).getAccount();
            RequestHolder requestHolder = requests.remove(account, packetId);
            if (requestHolder != null) {
                if (iq.getType() == Type.result) {
                    requestHolder.getListener().onReceived(account, packetId, iq);
                } else {
                    requestHolder.getListener().onError(account, packetId, iq);
                }
            }
        }
    }
    for (OnPacketListener listener : Application.getInstance().getManagers(OnPacketListener.class)) {
        listener.onPacket(connectionItem, Jid.getBareAddress(stanza.getFrom()), stanza);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) IQ(org.jivesoftware.smack.packet.IQ)

Example 67 with AccountItem

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

the class ChatStateManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    final String resource = Jid.getResource(packet.getFrom());
    if (resource == null)
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (packet instanceof Presence) {
        Presence presence = (Presence) packet;
        if (presence.getType() != Type.unavailable)
            return;
        chatStates.remove(account, bareAddress, resource);
        removeCallback(account, bareAddress, resource);
        supports.remove(account, bareAddress, resource);
    } else if (packet instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : packet.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareAddress, resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account, bareAddress, resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account, bareAddress, resource))
                            return;
                        chatStates.remove(account, bareAddress, resource);
                        removeCallback(account, bareAddress, resource);
                        RosterManager.getInstance().onContactChanged(account, bareAddress);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account, bareAddress, resource, runnable);
            }
            RosterManager.getInstance().onContactChanged(account, bareAddress);
            support = true;
            break;
        }
        Message message = (Message) packet;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat)
            return;
        if (support)
            supports.put(account, bareAddress, resource, true);
        else if (supports.get(account, bareAddress, resource) == null)
            // Disable only if there no information about support.
            supports.put(account, bareAddress, resource, false);
    }
}
Also used : ChatState(org.jivesoftware.smackx.chatstates.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence)

Example 68 with AccountItem

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

the class AvatarManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(packet instanceof Presence) || bareAddress == null) {
        return;
    }
    if (!(connection instanceof AccountItem)) {
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    Presence presence = (Presence) packet;
    if (presence.getType() == Presence.Type.error) {
        return;
    }
    for (ExtensionElement packetExtension : presence.getExtensions()) {
        if (packetExtension instanceof VCardUpdate) {
            VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
            if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
                onPhotoReady(account, bareAddress, vCardUpdate);
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) VCardUpdate(com.xabber.xmpp.avatar.VCardUpdate)

Example 69 with AccountItem

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

the class AccountActionButtonsAdapter method onChange.

@Override
public void onChange() {
    Collections.sort(accounts);
    for (int index = 0; index < accounts.size(); index++) {
        View view = linearLayout.getChildAt(index);
        final CircleImageView circleImageView = (CircleImageView) view.findViewById(R.id.account_avatar);
        final AccountJid account = accounts.get(index);
        circleImageView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
        FloatingActionButton backgroundActionButton = (FloatingActionButton) view.findViewById(R.id.fab);
        final AccountPainter accountPainter = ColorManager.getInstance().getAccountPainter();
        backgroundActionButton.setColorNormal(accountPainter.getAccountMainColor(account));
        backgroundActionButton.setColorPressed(accountPainter.getAccountDarkColor(account));
        backgroundActionButton.setColorRipple(accountPainter.getAccountRippleColor(account));
        AccountJid selectedAccount = AccountManager.getInstance().getSelectedAccount();
        int shadowVisibility;
        if (selectedAccount == null) {
            shadowVisibility = View.GONE;
        } else {
            shadowVisibility = View.VISIBLE;
            if (selectedAccount.equals(account)) {
                shadowVisibility = View.GONE;
            }
        }
        view.findViewById(R.id.account_unselected_shadow).setVisibility(shadowVisibility);
        int offlineShadowVisibility;
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        StatusMode statusMode = null;
        if (accountItem != null) {
            statusMode = accountItem.getDisplayStatusMode();
        }
        if (statusMode != null && (statusMode == StatusMode.connection || statusMode == StatusMode.unavailable)) {
            offlineShadowVisibility = View.VISIBLE;
        } else {
            offlineShadowVisibility = View.GONE;
        }
        view.findViewById(R.id.account_offline_shadow).setVisibility(offlineShadowVisibility);
    }
}
Also used : CircleImageView(de.hdodenhof.circleimageview.CircleImageView) AccountPainter(com.xabber.android.ui.color.AccountPainter) StatusMode(com.xabber.android.data.account.StatusMode) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) FloatingActionButton(com.melnykov.fab.FloatingActionButton) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View)

Example 70 with AccountItem

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

the class ChatFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    EventBus.getDefault().register(this);
    AccountItem accountItem = AccountManager.getInstance().getAccount(this.account);
    if (accountItem != null) {
        LoadHistorySettings loadHistorySettings = accountItem.getLoadHistorySettings();
        if (loadHistorySettings == LoadHistorySettings.all || loadHistorySettings == LoadHistorySettings.current) {
            if (!isRemoteHistoryRequested) {
                MamManager.getInstance().requestLastHistoryByUser(getChat());
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) LoadHistorySettings(com.xabber.android.data.extension.mam.LoadHistorySettings)

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