ConferenceDetailsActivity.java

  1package eu.siacs.conversations.ui;
  2
  3import android.app.AlertDialog;
  4import android.app.PendingIntent;
  5import android.content.Context;
  6import android.content.DialogInterface;
  7import android.content.IntentSender.SendIntentException;
  8import android.os.Bundle;
  9import android.view.ContextMenu;
 10import android.view.LayoutInflater;
 11import android.view.Menu;
 12import android.view.MenuItem;
 13import android.view.View;
 14import android.view.View.OnClickListener;
 15import android.widget.Button;
 16import android.widget.ImageButton;
 17import android.widget.ImageView;
 18import android.widget.LinearLayout;
 19import android.widget.TableLayout;
 20import android.widget.TextView;
 21import android.widget.Toast;
 22
 23import org.openintents.openpgp.util.OpenPgpUtils;
 24
 25import java.util.ArrayList;
 26import java.util.Collections;
 27import java.util.concurrent.atomic.AtomicInteger;
 28
 29import eu.siacs.conversations.Config;
 30import eu.siacs.conversations.R;
 31import eu.siacs.conversations.crypto.PgpEngine;
 32import eu.siacs.conversations.entities.Account;
 33import eu.siacs.conversations.entities.Bookmark;
 34import eu.siacs.conversations.entities.Contact;
 35import eu.siacs.conversations.entities.Conversation;
 36import eu.siacs.conversations.entities.MucOptions;
 37import eu.siacs.conversations.entities.MucOptions.User;
 38import eu.siacs.conversations.services.XmppConnectionService;
 39import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
 40import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
 41import eu.siacs.conversations.xmpp.jid.Jid;
 42
 43public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed {
 44	public static final String ACTION_VIEW_MUC = "view_muc";
 45
 46	private static final float INACTIVE_ALPHA = 0.4684f; //compromise between dark and light theme
 47
 48	private Conversation mConversation;
 49	private OnClickListener inviteListener = new OnClickListener() {
 50
 51		@Override
 52		public void onClick(View v) {
 53			inviteToConversation(mConversation);
 54		}
 55	};
 56	private TextView mYourNick;
 57	private ImageView mYourPhoto;
 58	private TextView mFullJid;
 59	private TextView mAccountJid;
 60	private LinearLayout membersView;
 61	private LinearLayout mMoreDetails;
 62	private TextView mConferenceType;
 63	private TableLayout mConferenceInfoTable;
 64	private TextView mConferenceInfoMam;
 65	private TextView mNotifyStatusText;
 66	private ImageButton mChangeConferenceSettingsButton;
 67	private ImageButton mNotifyStatusButton;
 68	private Button mInviteButton;
 69	private String uuid = null;
 70	private User mSelectedUser = null;
 71
 72	private boolean mAdvancedMode = false;
 73
 74	private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
 75		@Override
 76		public void success(Conversation object) {
 77			runOnUiThread(new Runnable() {
 78				@Override
 79				public void run() {
 80					Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
 81					updateView();
 82				}
 83			});
 84
 85		}
 86
 87		@Override
 88		public void error(final int errorCode, Conversation object) {
 89			runOnUiThread(new Runnable() {
 90				@Override
 91				public void run() {
 92					Toast.makeText(ConferenceDetailsActivity.this,getString(errorCode),Toast.LENGTH_SHORT).show();
 93				}
 94			});
 95		}
 96
 97		@Override
 98		public void userInputRequried(PendingIntent pi, Conversation object) {
 99
100		}
101	};
102
103	private OnClickListener mNotifyStatusClickListener = new OnClickListener() {
104		@Override
105		public void onClick(View v) {
106			AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
107			builder.setTitle(R.string.pref_notification_settings);
108			String[] choices = {
109					getString(R.string.notify_on_all_messages),
110					getString(R.string.notify_only_when_highlighted),
111					getString(R.string.notify_never)
112			};
113			final AtomicInteger choice;
114			if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0) == Long.MAX_VALUE) {
115				choice = new AtomicInteger(2);
116			} else {
117				choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
118			}
119			builder.setSingleChoiceItems(choices, choice.get(), new DialogInterface.OnClickListener() {
120				@Override
121				public void onClick(DialogInterface dialog, int which) {
122					choice.set(which);
123				}
124			});
125			builder.setNegativeButton(R.string.cancel, null);
126			builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
127				@Override
128				public void onClick(DialogInterface dialog, int which) {
129					if (choice.get() == 2) {
130						mConversation.setMutedTill(Long.MAX_VALUE);
131					} else {
132						mConversation.setMutedTill(0);
133						mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY,String.valueOf(choice.get() == 0));
134					}
135					xmppConnectionService.updateConversation(mConversation);
136					updateView();
137				}
138			});
139			builder.create().show();
140		}
141	};
142
143	private OnClickListener mChangeConferenceSettings = new OnClickListener() {
144		@Override
145		public void onClick(View v) {
146			final MucOptions mucOptions = mConversation.getMucOptions();
147			AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
148			builder.setTitle(R.string.conference_options);
149			final String[] options;
150			final boolean[] values;
151			if (mAdvancedMode) {
152				options = new String[]{
153						getString(R.string.members_only),
154						getString(R.string.moderated),
155						getString(R.string.non_anonymous)
156				};
157				values = new boolean[]{
158						mucOptions.membersOnly(),
159						mucOptions.moderated(),
160						mucOptions.nonanonymous()
161				};
162			} else {
163				options = new String[]{
164						getString(R.string.members_only),
165						getString(R.string.non_anonymous)
166				};
167				values = new boolean[]{
168						mucOptions.membersOnly(),
169						mucOptions.nonanonymous()
170				};
171			}
172			builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
173				@Override
174				public void onClick(DialogInterface dialog, int which, boolean isChecked) {
175					values[which] = isChecked;
176				}
177			});
178			builder.setNegativeButton(R.string.cancel, null);
179			builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
180				@Override
181				public void onClick(DialogInterface dialog, int which) {
182					if (!mucOptions.membersOnly() && values[0]) {
183						xmppConnectionService.changeAffiliationsInConference(mConversation,
184								MucOptions.Affiliation.NONE,
185								MucOptions.Affiliation.MEMBER);
186					}
187					Bundle options = new Bundle();
188					options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
189					if (values.length == 2) {
190						options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
191					} else if (values.length == 3) {
192						options.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
193						options.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
194					}
195					options.putString("muc#roomconfig_persistentroom", "1");
196					xmppConnectionService.pushConferenceConfiguration(mConversation,
197							options,
198							ConferenceDetailsActivity.this);
199				}
200			});
201			builder.create().show();
202		}
203	};
204	private OnValueEdited onSubjectEdited = new OnValueEdited() {
205
206		@Override
207		public void onValueEdited(String value) {
208			xmppConnectionService.pushSubjectToConference(mConversation,value);
209		}
210	};
211
212	@Override
213	public void onConversationUpdate() {
214		refreshUi();
215	}
216
217	@Override
218	public void onMucRosterUpdate() {
219		refreshUi();
220	}
221
222	@Override
223	protected void refreshUiReal() {
224		updateView();
225	}
226
227	@Override
228	protected void onCreate(Bundle savedInstanceState) {
229		super.onCreate(savedInstanceState);
230		setContentView(R.layout.activity_muc_details);
231		mYourNick = (TextView) findViewById(R.id.muc_your_nick);
232		mYourPhoto = (ImageView) findViewById(R.id.your_photo);
233		ImageButton mEditNickButton = (ImageButton) findViewById(R.id.edit_nick_button);
234		mFullJid = (TextView) findViewById(R.id.muc_jabberid);
235		membersView = (LinearLayout) findViewById(R.id.muc_members);
236		mAccountJid = (TextView) findViewById(R.id.details_account);
237		mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
238		mMoreDetails.setVisibility(View.GONE);
239		mChangeConferenceSettingsButton = (ImageButton) findViewById(R.id.change_conference_button);
240		mChangeConferenceSettingsButton.setOnClickListener(this.mChangeConferenceSettings);
241		mInviteButton = (Button) findViewById(R.id.invite);
242		mInviteButton.setOnClickListener(inviteListener);
243		mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
244		if (getActionBar() != null) {
245			getActionBar().setHomeButtonEnabled(true);
246			getActionBar().setDisplayHomeAsUpEnabled(true);
247		}
248		mEditNickButton.setOnClickListener(new OnClickListener() {
249
250			@Override
251			public void onClick(View v) {
252				quickEdit(mConversation.getMucOptions().getActualNick(),
253						0,
254						new OnValueEdited() {
255
256							@Override
257							public void onValueEdited(String value) {
258								xmppConnectionService.renameInMuc(mConversation,value,renameCallback);
259							}
260						});
261			}
262		});
263		this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
264		this.mConferenceInfoTable = (TableLayout) findViewById(R.id.muc_info_more);
265		mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
266		this.mConferenceInfoMam = (TextView) findViewById(R.id.muc_info_mam);
267		this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button);
268		this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener);
269		this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text);
270	}
271
272	@Override
273	protected void onStart() {
274		super.onStart();
275		final int theme = findTheme();
276		if (this.mTheme != theme) {
277			recreate();
278		}
279	}
280
281	@Override
282	public boolean onOptionsItemSelected(MenuItem menuItem) {
283		switch (menuItem.getItemId()) {
284			case android.R.id.home:
285				finish();
286				break;
287			case R.id.action_edit_subject:
288				if (mConversation != null) {
289					quickEdit(mConversation.getMucOptions().getSubject(),
290							R.string.edit_subject_hint,
291							this.onSubjectEdited);
292				}
293				break;
294			case R.id.action_share:
295				shareUri();
296				break;
297			case R.id.action_save_as_bookmark:
298				saveAsBookmark();
299				break;
300			case R.id.action_delete_bookmark:
301				deleteBookmark();
302				break;
303			case R.id.action_advanced_mode:
304				this.mAdvancedMode = !menuItem.isChecked();
305				menuItem.setChecked(this.mAdvancedMode);
306				getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).apply();
307				mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
308				invalidateOptionsMenu();
309				updateView();
310				break;
311		}
312		return super.onOptionsItemSelected(menuItem);
313	}
314
315	@Override
316	protected String getShareableUri() {
317		if (mConversation != null) {
318			return "xmpp:" + mConversation.getJid().toBareJid().toString() + "?join";
319		} else {
320			return "";
321		}
322	}
323
324	@Override
325	public boolean onPrepareOptionsMenu(Menu menu) {
326		MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
327		MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
328		MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
329		MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject);
330		menuItemAdvancedMode.setChecked(mAdvancedMode);
331		if (mConversation == null) {
332			return true;
333		}
334		Account account = mConversation.getAccount();
335		if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
336			menuItemSaveBookmark.setVisible(false);
337			menuItemDeleteBookmark.setVisible(true);
338		} else {
339			menuItemDeleteBookmark.setVisible(false);
340			menuItemSaveBookmark.setVisible(true);
341		}
342		menuItemChangeSubject.setVisible(mConversation.getMucOptions().canChangeSubject());
343		return true;
344	}
345
346	@Override
347	public boolean onCreateOptionsMenu(Menu menu) {
348		getMenuInflater().inflate(R.menu.muc_details, menu);
349		return super.onCreateOptionsMenu(menu);
350	}
351
352	@Override
353	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
354		Object tag = v.getTag();
355		if (tag instanceof User) {
356			getMenuInflater().inflate(R.menu.muc_details_context,menu);
357			final User user = (User) tag;
358			final User self = mConversation.getMucOptions().getSelf();
359			this.mSelectedUser = user;
360			String name;
361			final Contact contact = user.getContact();
362			if (contact != null) {
363				name = contact.getDisplayName();
364			} else if (user.getRealJid() != null){
365				name = user.getRealJid().toBareJid().toString();
366			} else {
367				name = user.getName();
368			}
369			menu.setHeaderTitle(name);
370			if (user.getRealJid() != null) {
371				MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
372				MenuItem startConversation = menu.findItem(R.id.start_conversation);
373				MenuItem giveMembership = menu.findItem(R.id.give_membership);
374				MenuItem removeMembership = menu.findItem(R.id.remove_membership);
375				MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
376				MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
377				MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
378				MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
379				MenuItem invite = menu.findItem(R.id.invite);
380				startConversation.setVisible(true);
381				if (contact != null) {
382					showContactDetails.setVisible(!contact.isSelf());
383				}
384				if (user.getRole() == MucOptions.Role.NONE) {
385					invite.setVisible(true);
386				}
387				if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
388						self.getAffiliation().outranks(user.getAffiliation())) {
389					if (mAdvancedMode) {
390						if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
391							giveMembership.setVisible(true);
392						} else {
393							removeMembership.setVisible(true);
394						}
395						banFromConference.setVisible(true);
396					} else {
397						removeFromRoom.setVisible(true);
398					}
399					if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
400						giveAdminPrivileges.setVisible(true);
401					} else {
402						removeAdminPrivileges.setVisible(true);
403					}
404				}
405			} else {
406				MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
407				sendPrivateMessage.setVisible(user.getRole().ranks(MucOptions.Role.PARTICIPANT));
408			}
409
410		}
411		super.onCreateContextMenu(menu, v, menuInfo);
412	}
413
414	@Override
415	public boolean onContextItemSelected(MenuItem item) {
416		Jid jid = mSelectedUser.getRealJid();
417		switch (item.getItemId()) {
418			case R.id.action_contact_details:
419				Contact contact = mSelectedUser.getContact();
420				if (contact != null) {
421					switchToContactDetails(contact);
422				}
423				return true;
424			case R.id.start_conversation:
425				startConversation(mSelectedUser);
426				return true;
427			case R.id.give_admin_privileges:
428				xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.ADMIN,this);
429				return true;
430			case R.id.give_membership:
431				xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.MEMBER,this);
432				return true;
433			case R.id.remove_membership:
434				xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.NONE,this);
435				return true;
436			case R.id.remove_admin_privileges:
437				xmppConnectionService.changeAffiliationInConference(mConversation, jid, MucOptions.Affiliation.MEMBER,this);
438				return true;
439			case R.id.remove_from_room:
440				removeFromRoom(mSelectedUser);
441				return true;
442			case R.id.ban_from_conference:
443				xmppConnectionService.changeAffiliationInConference(mConversation,jid, MucOptions.Affiliation.OUTCAST,this);
444				if (mSelectedUser.getRole() != MucOptions.Role.NONE) {
445					xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, this);
446				}
447				return true;
448			case R.id.send_private_message:
449				privateMsgInMuc(mConversation,mSelectedUser.getName());
450				return true;
451			case R.id.invite:
452				xmppConnectionService.directInvite(mConversation, jid);
453				return true;
454			default:
455				return super.onContextItemSelected(item);
456		}
457	}
458
459	private void removeFromRoom(final User user) {
460		if (mConversation.getMucOptions().membersOnly()) {
461			xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.NONE,this);
462			if (user.getRole() != MucOptions.Role.NONE) {
463				xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
464			}
465		} else {
466			AlertDialog.Builder builder = new AlertDialog.Builder(this);
467			builder.setTitle(R.string.ban_from_conference);
468			builder.setMessage(getString(R.string.removing_from_public_conference,user.getName()));
469			builder.setNegativeButton(R.string.cancel,null);
470			builder.setPositiveButton(R.string.ban_now,new DialogInterface.OnClickListener() {
471				@Override
472				public void onClick(DialogInterface dialog, int which) {
473					xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
474					if (user.getRole() != MucOptions.Role.NONE) {
475						xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
476					}
477				}
478			});
479			builder.create().show();
480		}
481	}
482
483	protected void startConversation(User user) {
484		if (user.getRealJid() != null) {
485			Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false,true);
486			switchToConversation(conversation);
487		}
488	}
489
490	protected void saveAsBookmark() {
491		xmppConnectionService.saveConversationAsBookmark(mConversation,
492				mConversation.getMucOptions().getSubject());
493	}
494
495	protected void deleteBookmark() {
496		Account account = mConversation.getAccount();
497		Bookmark bookmark = mConversation.getBookmark();
498		mConversation.deregisterWithBookmark();
499		account.getBookmarks().remove(bookmark);
500		xmppConnectionService.pushBookmarks(account);
501		updateView();
502	}
503
504	@Override
505	void onBackendConnected() {
506		if (mPendingConferenceInvite != null) {
507			mPendingConferenceInvite.execute(this);
508			mPendingConferenceInvite = null;
509		}
510		if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
511			this.uuid = getIntent().getExtras().getString("uuid");
512		}
513		if (uuid != null) {
514			this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
515			if (this.mConversation != null) {
516				updateView();
517			}
518		}
519	}
520
521	private void updateView() {
522		invalidateOptionsMenu();
523		final MucOptions mucOptions = mConversation.getMucOptions();
524		final User self = mucOptions.getSelf();
525		String account;
526		if (Config.DOMAIN_LOCK != null) {
527			account = mConversation.getAccount().getJid().getLocalpart();
528		} else {
529			account = mConversation.getAccount().getJid().toBareJid().toString();
530		}
531		mAccountJid.setText(getString(R.string.using_account, account));
532		mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
533		setTitle(mConversation.getName());
534		mFullJid.setText(mConversation.getJid().toBareJid().toString());
535		mYourNick.setText(mucOptions.getActualNick());
536		TextView mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
537		if (mucOptions.online()) {
538			mMoreDetails.setVisibility(View.VISIBLE);
539			final String status = getStatus(self);
540			if (status != null) {
541				mRoleAffiliaton.setVisibility(View.VISIBLE);
542				mRoleAffiliaton.setText(status);
543			} else {
544				mRoleAffiliaton.setVisibility(View.GONE);
545			}
546			if (mucOptions.membersOnly()) {
547				mConferenceType.setText(R.string.private_conference);
548			} else {
549				mConferenceType.setText(R.string.public_conference);
550			}
551			if (mucOptions.mamSupport()) {
552				mConferenceInfoMam.setText(R.string.server_info_available);
553			} else {
554				mConferenceInfoMam.setText(R.string.server_info_unavailable);
555			}
556			if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
557				mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
558			} else {
559				mChangeConferenceSettingsButton.setVisibility(View.GONE);
560			}
561		}
562
563		int ic_notifications = 		  getThemeResource(R.attr.icon_notifications, R.drawable.ic_notifications_black_24dp);
564		int ic_notifications_off = 	  getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black_24dp);
565		int ic_notifications_paused = getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black_24dp);
566		int ic_notifications_none =	  getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black_24dp);
567
568		long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
569		if (mutedTill == Long.MAX_VALUE) {
570			mNotifyStatusText.setText(R.string.notify_never);
571			mNotifyStatusButton.setImageResource(ic_notifications_off);
572		} else if (System.currentTimeMillis() < mutedTill) {
573			mNotifyStatusText.setText(R.string.notify_paused);
574			mNotifyStatusButton.setImageResource(ic_notifications_paused);
575		} else if (mConversation.alwaysNotify()) {
576			mNotifyStatusButton.setImageResource(ic_notifications);
577			mNotifyStatusText.setText(R.string.notify_on_all_messages);
578		} else {
579			mNotifyStatusButton.setImageResource(ic_notifications_none);
580			mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
581		}
582
583		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
584		membersView.removeAllViews();
585		final ArrayList<User> users = mucOptions.getUsers();
586		Collections.sort(users);
587		for (final User user : users) {
588			View view = inflater.inflate(R.layout.contact, membersView,false);
589			this.setListItemBackgroundOnView(view);
590			view.setOnClickListener(new OnClickListener() {
591				@Override
592				public void onClick(View view) {
593					highlightInMuc(mConversation, user.getName());
594				}
595			});
596			registerForContextMenu(view);
597			view.setTag(user);
598			TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name);
599			TextView tvKey = (TextView) view.findViewById(R.id.key);
600			TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid);
601			if (mAdvancedMode && user.getPgpKeyId() != 0) {
602				tvKey.setVisibility(View.VISIBLE);
603				tvKey.setOnClickListener(new OnClickListener() {
604
605					@Override
606					public void onClick(View v) {
607						viewPgpKey(user);
608					}
609				});
610				tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
611			}
612			Contact contact = user.getContact();
613			String name = user.getName();
614			if (contact != null) {
615				tvDisplayName.setText(contact.getDisplayName());
616				tvStatus.setText((name != null ? name+ " \u2022 " : "") + getStatus(user));
617			} else {
618				tvDisplayName.setText(name == null ? "" : name);
619				tvStatus.setText(getStatus(user));
620
621			}
622			ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
623			iv.setImageBitmap(avatarService().get(user, getPixel(48), false));
624			if (user.getRole() == MucOptions.Role.NONE) {
625				tvDisplayName.setAlpha(INACTIVE_ALPHA);
626				tvKey.setAlpha(INACTIVE_ALPHA);
627				tvStatus.setAlpha(INACTIVE_ALPHA);
628				iv.setAlpha(INACTIVE_ALPHA);
629			}
630			membersView.addView(view);
631			if (mConversation.getMucOptions().canInvite()) {
632				mInviteButton.setVisibility(View.VISIBLE);
633			} else {
634				mInviteButton.setVisibility(View.GONE);
635			}
636		}
637	}
638
639	private String getStatus(User user) {
640		if (mAdvancedMode) {
641			return getString(user.getAffiliation().getResId()) +
642					" (" + getString(user.getRole().getResId()) + ')';
643		} else {
644			return getString(user.getAffiliation().getResId());
645		}
646	}
647
648	private void viewPgpKey(User user) {
649		PgpEngine pgp = xmppConnectionService.getPgpEngine();
650		if (pgp != null) {
651			PendingIntent intent = pgp.getIntentForKey(user.getPgpKeyId());
652			if (intent != null) {
653				try {
654					startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
655				} catch (SendIntentException ignored) {
656
657				}
658			}
659		}
660	}
661
662	@Override
663	public void onAffiliationChangedSuccessful(Jid jid) {
664		refreshUi();
665	}
666
667	@Override
668	public void onAffiliationChangeFailed(Jid jid, int resId) {
669		displayToast(getString(resId,jid.toBareJid().toString()));
670	}
671
672	@Override
673	public void onRoleChangedSuccessful(String nick) {
674
675	}
676
677	@Override
678	public void onRoleChangeFailed(String nick, int resId) {
679		displayToast(getString(resId,nick));
680	}
681
682	@Override
683	public void onPushSucceeded() {
684		displayToast(getString(R.string.modified_conference_options));
685	}
686
687	@Override
688	public void onPushFailed() {
689		displayToast(getString(R.string.could_not_modify_conference_options));
690	}
691
692	private void displayToast(final String msg) {
693		runOnUiThread(new Runnable() {
694			@Override
695			public void run() {
696				Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show();
697			}
698		});
699	}
700}