package de.thedevstack.conversationsplus.ui.listeners; import android.content.Context; import android.view.View; import de.thedevstack.conversationsplus.ui.adapter.PresencesArrayAdapter; import de.thedevstack.conversationsplus.ui.dialogs.AbstractAlertDialog; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Contact; /** * This listener shows the dialog with the resources of a contact. * The resources are shown with the color of their current online mode. * This listener implements OnClickListener and OnLongClickListener. */ public class ShowResourcesListDialogListener extends AbstractAlertDialog implements View.OnClickListener, View.OnLongClickListener { private Contact contact; public ShowResourcesListDialogListener(Context context, Contact contact) { super(context, getTitle(context, contact)); this.contact = contact; this.init(); } private static final String getTitle(Context context, Contact contact) { if (null != contact && null != contact.getJid() && null != contact.getJid().toBareJid()) { int presenceCount = null != contact.getPresences() ? contact.getPresences().size() : 0; return context.getString(R.string.dlg_resources_title, contact.getJid().toBareJid().toString(), presenceCount); } return null != contact ? contact.toString() : ""; } protected void init() { this.builder.setAdapter(new PresencesArrayAdapter(getContext(), this.contact.getPresences()), null); } @Override public void onClick(View v) { this.show(); } @Override public boolean onLongClick(View view) { this.show(); return true; } }