use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.
the class ChatMessageAdapter method setUpAvatar.
private void setUpAvatar(MessageItem messageItem, IncomingMessage message) {
if (SettingsManager.chatsShowAvatars()) {
final AccountJid account = messageItem.getAccount();
final UserJid user = messageItem.getUser();
final Resourcepart resource = messageItem.getResource();
message.avatar.setVisibility(View.VISIBLE);
message.avatarBackground.setVisibility(View.VISIBLE);
if ((isMUC && MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
message.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (isMUC) {
if (resource.equals(Resourcepart.EMPTY)) {
message.avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
} else {
try {
message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(UserJid.from(JidCreate.domainFullFrom(user.getJid().asDomainBareJid(), resource))));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
} else {
message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
}
}
} else {
message.avatar.setVisibility(View.GONE);
message.avatarBackground.setVisibility(View.GONE);
}
}
use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.
the class IncomingMessageVH method setUpAvatar.
private void setUpAvatar(Context context, GroupchatUser groupchatUser, MessageItem messageItem, boolean isMUC, String userName, boolean needTail) {
boolean needAvatar = isMUC ? SettingsManager.chatsShowAvatarsMUC() : SettingsManager.chatsShowAvatars();
// for new groupchats (0GGG)
if (groupchatUser != null && SettingsManager.chatsShowAvatarsMUC())
needAvatar = true;
if (!needAvatar) {
avatar.setVisibility(View.GONE);
avatarBackground.setVisibility(View.GONE);
return;
}
if (!needTail) {
avatar.setVisibility(View.INVISIBLE);
avatarBackground.setVisibility(View.INVISIBLE);
return;
}
avatar.setVisibility(View.VISIBLE);
avatarBackground.setVisibility(View.VISIBLE);
// groupchat avatar
if (groupchatUser != null) {
Drawable placeholder;
try {
UserJid userJid = UserJid.from(messageItem.getUser().getJid().toString() + "/" + groupchatUser.getNickname());
placeholder = AvatarManager.getInstance().getOccupantAvatar(userJid, groupchatUser.getNickname());
} catch (UserJid.UserJidCreateException e) {
placeholder = AvatarManager.getInstance().generateDefaultAvatar(groupchatUser.getNickname(), groupchatUser.getNickname());
}
Glide.with(context).load(groupchatUser.getAvatar()).centerCrop().placeholder(placeholder).error(placeholder).into(avatar);
return;
}
final UserJid user = messageItem.getUser();
final AccountJid account = messageItem.getAccount();
final Resourcepart resource = messageItem.getResource();
if (!isMUC)
avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatarForContactList(user, userName));
else {
if ((MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (resource.equals(Resourcepart.EMPTY)) {
avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatarForContactList(user));
} else {
String nick = resource.toString();
UserJid userJid = null;
try {
userJid = UserJid.from(user.getJid().toString() + "/" + resource.toString());
avatar.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
avatar.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
}
}
}
}
}
use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.
the class OccupantListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(R.layout.item_occupant, parent, false);
} else {
view = convertView;
}
final Occupant occupant = (Occupant) getItem(position);
final ImageView avatarView = (ImageView) view.findViewById(R.id.ivAvatar);
avatarView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
try {
intent = ContactActivity.createIntent(activity, account, UserJid.from(JidCreate.domainFullFrom(room.asDomainBareJid(), occupant.getNickname())));
activity.startActivity(intent);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
});
final ImageView affilationView = (ImageView) view.findViewById(R.id.affilation);
final TextView nameView = (TextView) view.findViewById(R.id.name);
final TextView statusTextView = (TextView) view.findViewById(R.id.status);
final ImageView statusModeView = (ImageView) view.findViewById(R.id.ivStatus);
// avatar
Resourcepart nickname = occupant.getNickname();
if (nickname != null && MUCManager.getInstance().getNickname(account, room).equals(nickname)) {
avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
String nick = occupant.getJid().getResourceOrEmpty().toString();
UserJid userJid = null;
try {
userJid = UserJid.from(occupant.getJid());
avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
avatarView.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
}
}
affilationView.setImageLevel(occupant.getAffiliation().ordinal());
nameView.setText(occupant.getNickname());
String status;
if (occupant.getRole() == MUCRole.moderator)
status = activity.getString(R.string.muc_role_moderator);
else if (occupant.getRole() == MUCRole.participant)
status = activity.getString(R.string.muc_role_participant);
else
status = activity.getString(R.string.muc_role_visitor);
String statusText = occupant.getStatusText();
if (statusText != null && !statusText.isEmpty())
status = status + " • " + statusText;
statusTextView.setText(status);
statusModeView.setImageLevel(occupant.getStatusMode().getStatusLevel());
return view;
}
use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.
the class ChatStateManager method onDisconnect.
@Override
public void onDisconnect(ConnectionItem connection) {
if (!(connection instanceof AccountItem))
return;
AccountJid account = ((AccountItem) connection).getAccount();
chatStates.clear(account.toString());
for (Map<Resourcepart, Runnable> map : stateCleaners.getNested(account.toString()).values()) {
for (Runnable runnable : map.values()) {
handler.removeCallbacks(runnable);
}
}
stateCleaners.clear(account.toString());
supports.clear(account.toString());
sent.clear(account.toString());
for (PendingIntent pendingIntent : pauseIntents.getNested(account.toString()).values()) {
alarmManager.cancel(pendingIntent);
}
pauseIntents.clear(account.toString());
}
use of org.jxmpp.jid.parts.Resourcepart in project xabber-android by redsolution.
the class ChatStateManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
final Resourcepart resource = stanza.getFrom().getResourceOrNull();
if (resource == null) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final UserJid bareUserJid;
try {
bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() != Type.unavailable) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
supports.remove(account.toString(), bareUserJid.toString(), resource);
} else if (stanza instanceof Message) {
boolean support = false;
for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareUserJid.getBareJid(), resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
RosterManager.onChatStateChanged(account, bareUserJid);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
}
RosterManager.onChatStateChanged(account, bareUserJid);
support = true;
break;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
return;
}
if (support) {
supports.put(account.toString(), bareUserJid.toString(), resource, true);
} else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
// Disable only if there no information about support.
supports.put(account.toString(), bareUserJid.toString(), resource, false);
}
}
}
Aggregations