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				if (mSelectedUser.getRole() != MucOptions.Role.NONE) {
442					xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, this);
443				}
444				return true;
445			case R.id.send_private_message:
446				privateMsgInMuc(mConversation,mSelectedUser.getName());
447				return true;
448			default:
449				return super.onContextItemSelected(item);
450		}
451	}
452
453	private void removeFromRoom(final User user) {
454		if (mConversation.getMucOptions().membersOnly()) {
455			xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.NONE,this);
456			if (user.getRole() != MucOptions.Role.NONE) {
457				xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
458			}
459		} else {
460			AlertDialog.Builder builder = new AlertDialog.Builder(this);
461			builder.setTitle(R.string.ban_from_conference);
462			builder.setMessage(getString(R.string.removing_from_public_conference,user.getName()));
463			builder.setNegativeButton(R.string.cancel,null);
464			builder.setPositiveButton(R.string.ban_now,new DialogInterface.OnClickListener() {
465				@Override
466				public void onClick(DialogInterface dialog, int which) {
467					xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
468					if (user.getRole() != MucOptions.Role.NONE) {
469						xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
470					}
471				}
472			});
473			builder.create().show();
474		}
475	}
476
477	protected void startConversation(User user) {
478		if (user.getRealJid() != null) {
479			Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false);
480			switchToConversation(conversation);
481		}
482	}
483
484	protected void saveAsBookmark() {
485		Account account = mConversation.getAccount();
486		Bookmark bookmark = new Bookmark(account, mConversation.getJid().toBareJid());
487		if (!mConversation.getJid().isBareJid()) {
488			bookmark.setNick(mConversation.getJid().getResourcepart());
489		}
490		bookmark.setBookmarkName(mConversation.getMucOptions().getSubject());
491		bookmark.setAutojoin(getPreferences().getBoolean("autojoin",true));
492		account.getBookmarks().add(bookmark);
493		xmppConnectionService.pushBookmarks(account);
494		mConversation.setBookmark(bookmark);
495	}
496
497	protected void deleteBookmark() {
498		Account account = mConversation.getAccount();
499		Bookmark bookmark = mConversation.getBookmark();
500		bookmark.unregisterConversation();
501		account.getBookmarks().remove(bookmark);
502		xmppConnectionService.pushBookmarks(account);
503	}
504
505	@Override
506	void onBackendConnected() {
507		if (mPendingConferenceInvite != null) {
508			mPendingConferenceInvite.execute(this);
509			mPendingConferenceInvite = null;
510		}
511		if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
512			this.uuid = getIntent().getExtras().getString("uuid");
513		}
514		if (uuid != null) {
515			this.mConversation = xmppConnectionService
516				.findConversationByUuid(uuid);
517			if (this.mConversation != null) {
518				updateView();
519			}
520		}
521	}
522
523	private void updateView() {
524		final MucOptions mucOptions = mConversation.getMucOptions();
525		final User self = mucOptions.getSelf();
526		String account;
527		if (Config.DOMAIN_LOCK != null) {
528			account = mConversation.getAccount().getJid().getLocalpart();
529		} else {
530			account = mConversation.getAccount().getJid().toBareJid().toString();
531		}
532		mAccountJid.setText(getString(R.string.using_account, account));
533		mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
534		setTitle(mConversation.getName());
535		mFullJid.setText(mConversation.getJid().toBareJid().toString());
536		mYourNick.setText(mucOptions.getActualNick());
537		mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
538		if (mucOptions.online()) {
539			mMoreDetails.setVisibility(View.VISIBLE);
540			final String status = getStatus(self);
541			if (status != null) {
542				mRoleAffiliaton.setVisibility(View.VISIBLE);
543				mRoleAffiliaton.setText(status);
544			} else {
545				mRoleAffiliaton.setVisibility(View.GONE);
546			}
547			if (mucOptions.membersOnly()) {
548				mConferenceType.setText(R.string.private_conference);
549			} else {
550				mConferenceType.setText(R.string.public_conference);
551			}
552			if (mucOptions.mamSupport()) {
553				mConferenceInfoMam.setText(R.string.server_info_available);
554			} else {
555				mConferenceInfoMam.setText(R.string.server_info_unavailable);
556			}
557			if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
558				mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
559			} else {
560				mChangeConferenceSettingsButton.setVisibility(View.GONE);
561			}
562		}
563
564		long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
565		if (mutedTill == Long.MAX_VALUE) {
566			mNotifyStatusText.setText(R.string.notify_never);
567			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
568		} else if (System.currentTimeMillis() < mutedTill) {
569			mNotifyStatusText.setText(R.string.notify_paused);
570			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
571		} else if (mConversation.alwaysNotify()) {
572			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
573			mNotifyStatusText.setText(R.string.notify_on_all_messages);
574		} else {
575			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
576			mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
577		}
578
579		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
580		membersView.removeAllViews();
581		final ArrayList<User> users = mucOptions.getUsers();
582		Collections.sort(users,new Comparator<User>() {
583			@Override
584			public int compare(User l, User r) {
585				return l.getName() == null || r.getName() == null ? 0 : l.getName().compareToIgnoreCase(r.getName());
586			}
587		});
588		for (final User user : users) {
589			View view = inflater.inflate(R.layout.contact, membersView,false);
590			this.setListItemBackgroundOnView(view);
591			view.setOnClickListener(new OnClickListener() {
592				@Override
593				public void onClick(View view) {
594					highlightInMuc(mConversation, user.getName());
595				}
596			});
597			registerForContextMenu(view);
598			view.setTag(user);
599			TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name);
600			TextView tvKey = (TextView) view.findViewById(R.id.key);
601			TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid);
602			if (mAdvancedMode && user.getPgpKeyId() != 0) {
603				tvKey.setVisibility(View.VISIBLE);
604				tvKey.setOnClickListener(new OnClickListener() {
605
606					@Override
607					public void onClick(View v) {
608						viewPgpKey(user);
609					}
610				});
611				tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
612			}
613			Contact contact = user.getContact();
614			String name = user.getName();
615			if (contact != null) {
616				tvDisplayName.setText(contact.getDisplayName());
617				tvStatus.setText((name != null ? name+ " \u2022 " : "") + getStatus(user));
618			} else {
619				tvDisplayName.setText(name == null ? "" : name);
620				tvStatus.setText(getStatus(user));
621
622			}
623			ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
624			iv.setImageBitmap(avatarService().get(user, getPixel(48), false));
625			membersView.addView(view);
626			if (mConversation.getMucOptions().canInvite()) {
627				mInviteButton.setVisibility(View.VISIBLE);
628			} else {
629				mInviteButton.setVisibility(View.GONE);
630			}
631		}
632	}
633
634	private String getStatus(User user) {
635		if (mAdvancedMode) {
636			StringBuilder builder = new StringBuilder();
637			builder.append(getString(user.getAffiliation().getResId()));
638			builder.append(" (");
639			builder.append(getString(user.getRole().getResId()));
640			builder.append(')');
641			return builder.toString();
642		} else {
643			return getString(user.getAffiliation().getResId());
644		}
645	}
646
647	private void viewPgpKey(User user) {
648		PgpEngine pgp = xmppConnectionService.getPgpEngine();
649		if (pgp != null) {
650			PendingIntent intent = pgp.getIntentForKey(
651					mConversation.getAccount(), user.getPgpKeyId());
652			if (intent != null) {
653				try {
654					startIntentSenderForResult(intent.getIntentSender(), 0,
655							null, 0, 0, 0);
656				} catch (SendIntentException ignored) {
657
658				}
659			}
660		}
661	}
662
663	@Override
664	public void onAffiliationChangedSuccessful(Jid jid) {
665		refreshUi();
666	}
667
668	@Override
669	public void onAffiliationChangeFailed(Jid jid, int resId) {
670		displayToast(getString(resId,jid.toBareJid().toString()));
671	}
672
673	@Override
674	public void onRoleChangedSuccessful(String nick) {
675
676	}
677
678	@Override
679	public void onRoleChangeFailed(String nick, int resId) {
680		displayToast(getString(resId,nick));
681	}
682
683	@Override
684	public void onPushSucceeded() {
685		displayToast(getString(R.string.modified_conference_options));
686	}
687
688	@Override
689	public void onPushFailed() {
690		displayToast(getString(R.string.could_not_modify_conference_options));
691	}
692
693	private void displayToast(final String msg) {
694		runOnUiThread(new Runnable() {
695			@Override
696			public void run() {
697				Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show();
698			}
699		});
700	}
701}