Search in sources :

Example 1 with Occupant

use of com.xabber.android.data.extension.muc.Occupant 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;
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 2 with Occupant

use of com.xabber.android.data.extension.muc.Occupant in project xabber-android by redsolution.

the class PresenceManager method getStatusText.

public String getStatusText(AccountJid account, UserJid bareAddress) {
    final Occupant occupant = getOccupant(account, bareAddress);
    if (occupant != null) {
        return occupant.getStatusText();
    }
    final Presence presence = RosterManager.getInstance().getPresence(account, bareAddress);
    if (presence == null) {
        return null;
    } else {
        return presence.getStatus();
    }
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) Presence(org.jivesoftware.smack.packet.Presence)

Example 3 with Occupant

use of com.xabber.android.data.extension.muc.Occupant in project xabber-android by redsolution.

the class PresenceManager method getStatusText.

public String getStatusText(String account, String bareAddress) {
    final Occupant occupant = getOccupant(account, bareAddress);
    if (occupant != null) {
        return occupant.getStatusText();
    }
    final Presence presence = RosterManager.getInstance().getPresence(account, bareAddress);
    if (presence == null) {
        return null;
    } else {
        return presence.getStatus();
    }
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) Presence(org.jivesoftware.smack.packet.Presence)

Example 4 with Occupant

use of com.xabber.android.data.extension.muc.Occupant in project xabber-android by redsolution.

the class PresenceManager method getOccupant.

/**
 * if contact is private MUC chat
 */
@Nullable
private Occupant getOccupant(AccountJid account, UserJid user) {
    EntityBareJid userEntityBareJid = user.getJid().asEntityBareJidIfPossible();
    if (userEntityBareJid == null) {
        return null;
    }
    Resourcepart resourcepart = user.getJid().getResourceOrNull();
    if (resourcepart == null) {
        return null;
    }
    if (MUCManager.getInstance().hasRoom(account, userEntityBareJid)) {
        final Collection<Occupant> occupants = MUCManager.getInstance().getOccupants(account, userEntityBareJid);
        for (Occupant occupant : occupants) {
            if (occupant.getNickname().equals(resourcepart)) {
                return occupant;
            }
        }
    }
    return null;
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Nullable(androidx.annotation.Nullable)

Aggregations

Occupant (com.xabber.android.data.extension.muc.Occupant)4 Presence (org.jivesoftware.smack.packet.Presence)2 Resourcepart (org.jxmpp.jid.parts.Resourcepart)2 Intent (android.content.Intent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 UserJid (com.xabber.android.data.entity.UserJid)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1