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);
}
}
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);
}
}
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);
}
}
}
}
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);
}
}
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());
}
}
}
}
Aggregations