ConferenceDetailsActivity.java

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