ConferenceDetailsActivity.java

  1package eu.siacs.conversations.ui;
  2
  3import android.annotation.TargetApi;
  4import android.app.AlertDialog;
  5import android.app.PendingIntent;
  6import android.content.Context;
  7import android.content.DialogInterface;
  8import android.content.IntentSender.SendIntentException;
  9import android.os.Build;
 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_save_as_bookmark:
285				saveAsBookmark();
286				break;
287			case R.id.action_delete_bookmark:
288				deleteBookmark();
289				break;
290			case R.id.action_advanced_mode:
291				this.mAdvancedMode = !menuItem.isChecked();
292				menuItem.setChecked(this.mAdvancedMode);
293				getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).commit();
294				mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
295				invalidateOptionsMenu();
296				updateView();
297				break;
298		}
299		return super.onOptionsItemSelected(menuItem);
300	}
301
302	@Override
303	protected String getShareableUri() {
304		if (mConversation != null) {
305			return "xmpp:" + mConversation.getJid().toBareJid().toString() + "?join";
306		} else {
307			return "";
308		}
309	}
310
311	@Override
312	public boolean onPrepareOptionsMenu(Menu menu) {
313		MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
314		MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
315		MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
316		MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject);
317		menuItemAdvancedMode.setChecked(mAdvancedMode);
318		if (mConversation == null) {
319			return true;
320		}
321		Account account = mConversation.getAccount();
322		if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
323			menuItemSaveBookmark.setVisible(false);
324			menuItemDeleteBookmark.setVisible(true);
325		} else {
326			menuItemDeleteBookmark.setVisible(false);
327			menuItemSaveBookmark.setVisible(true);
328		}
329		menuItemChangeSubject.setVisible(mConversation.getMucOptions().canChangeSubject());
330		return true;
331	}
332
333	@Override
334	public boolean onCreateOptionsMenu(Menu menu) {
335		getMenuInflater().inflate(R.menu.muc_details, menu);
336		return super.onCreateOptionsMenu(menu);
337	}
338
339	@Override
340	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
341		Object tag = v.getTag();
342		if (tag instanceof User) {
343			getMenuInflater().inflate(R.menu.muc_details_context,menu);
344			final User user = (User) tag;
345			final User self = mConversation.getMucOptions().getSelf();
346			this.mSelectedUser = user;
347			String name;
348			final Contact contact = user.getContact();
349			if (contact != null) {
350				name = contact.getDisplayName();
351			} else if (user.getJid() != null){
352				name = user.getJid().toBareJid().toString();
353			} else {
354				name = user.getName();
355			}
356			menu.setHeaderTitle(name);
357			if (user.getJid() != null) {
358				MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
359				MenuItem startConversation = menu.findItem(R.id.start_conversation);
360				MenuItem giveMembership = menu.findItem(R.id.give_membership);
361				MenuItem removeMembership = menu.findItem(R.id.remove_membership);
362				MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
363				MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
364				MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
365				MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
366				startConversation.setVisible(true);
367				if (contact != null) {
368					showContactDetails.setVisible(true);
369				}
370				if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
371						self.getAffiliation().outranks(user.getAffiliation())) {
372					if (mAdvancedMode) {
373						if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
374							giveMembership.setVisible(true);
375						} else {
376							removeMembership.setVisible(true);
377						}
378						banFromConference.setVisible(true);
379					} else {
380						removeFromRoom.setVisible(true);
381					}
382					if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
383						giveAdminPrivileges.setVisible(true);
384					} else {
385						removeAdminPrivileges.setVisible(true);
386					}
387				}
388			} else {
389				MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
390				sendPrivateMessage.setVisible(true);
391			}
392
393		}
394		super.onCreateContextMenu(menu, v, menuInfo);
395	}
396
397	@Override
398	public boolean onContextItemSelected(MenuItem item) {
399		switch (item.getItemId()) {
400			case R.id.action_contact_details:
401				Contact contact = mSelectedUser.getContact();
402				if (contact != null) {
403					switchToContactDetails(contact);
404				}
405				return true;
406			case R.id.start_conversation:
407				startConversation(mSelectedUser);
408				return true;
409			case R.id.give_admin_privileges:
410				xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.ADMIN,this);
411				return true;
412			case R.id.give_membership:
413				xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
414				return true;
415			case R.id.remove_membership:
416				xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.NONE,this);
417				return true;
418			case R.id.remove_admin_privileges:
419				xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
420				return true;
421			case R.id.remove_from_room:
422				removeFromRoom(mSelectedUser);
423				return true;
424			case R.id.ban_from_conference:
425				xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this);
426				xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this);
427				return true;
428			case R.id.send_private_message:
429				privateMsgInMuc(mConversation,mSelectedUser.getName());
430				return true;
431			default:
432				return super.onContextItemSelected(item);
433		}
434	}
435
436	private void removeFromRoom(final User user) {
437		if (mConversation.getMucOptions().membersOnly()) {
438			xmppConnectionService.changeAffiliationInConference(mConversation,user.getJid(), MucOptions.Affiliation.NONE,this);
439			xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
440		} else {
441			AlertDialog.Builder builder = new AlertDialog.Builder(this);
442			builder.setTitle(R.string.ban_from_conference);
443			builder.setMessage(getString(R.string.removing_from_public_conference,user.getName()));
444			builder.setNegativeButton(R.string.cancel,null);
445			builder.setPositiveButton(R.string.ban_now,new DialogInterface.OnClickListener() {
446				@Override
447				public void onClick(DialogInterface dialog, int which) {
448					xmppConnectionService.changeAffiliationInConference(mConversation,user.getJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
449					xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
450				}
451			});
452			builder.create().show();
453		}
454	}
455
456	protected void startConversation(User user) {
457		if (user.getJid() != null) {
458			Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getJid().toBareJid(),false);
459			switchToConversation(conversation);
460		}
461	}
462
463	protected void saveAsBookmark() {
464		Account account = mConversation.getAccount();
465		Bookmark bookmark = new Bookmark(account, mConversation.getJid().toBareJid());
466		if (!mConversation.getJid().isBareJid()) {
467			bookmark.setNick(mConversation.getJid().getResourcepart());
468		}
469		bookmark.setBookmarkName(mConversation.getMucOptions().getSubject());
470		bookmark.setAutojoin(getPreferences().getBoolean("autojoin",true));
471		account.getBookmarks().add(bookmark);
472		xmppConnectionService.pushBookmarks(account);
473		mConversation.setBookmark(bookmark);
474	}
475
476	protected void deleteBookmark() {
477		Account account = mConversation.getAccount();
478		Bookmark bookmark = mConversation.getBookmark();
479		bookmark.unregisterConversation();
480		account.getBookmarks().remove(bookmark);
481		xmppConnectionService.pushBookmarks(account);
482	}
483
484	@Override
485	void onBackendConnected() {
486		if (mPendingConferenceInvite != null) {
487			mPendingConferenceInvite.execute(this);
488			mPendingConferenceInvite = null;
489		}
490		if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
491			this.uuid = getIntent().getExtras().getString("uuid");
492		}
493		if (uuid != null) {
494			this.mConversation = xmppConnectionService
495				.findConversationByUuid(uuid);
496			if (this.mConversation != null) {
497				updateView();
498			}
499		}
500	}
501
502	private void updateView() {
503		final MucOptions mucOptions = mConversation.getMucOptions();
504		final User self = mucOptions.getSelf();
505		String account;
506		if (Config.DOMAIN_LOCK != null) {
507			account = mConversation.getAccount().getJid().getLocalpart();
508		} else {
509			account = mConversation.getAccount().getJid().toBareJid().toString();
510		}
511		mAccountJid.setText(getString(R.string.using_account, account));
512		mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
513		setTitle(mConversation.getName());
514		if (Config.LOCK_DOMAINS_IN_CONVERSATIONS && mConversation.getJid().getDomainpart().equals(Config.CONFERENCE_DOMAIN_LOCK)) {
515			mFullJid.setText(mConversation.getJid().getLocalpart());
516		} else {
517			mFullJid.setText(mConversation.getJid().toBareJid().toString());
518		}
519		mYourNick.setText(mucOptions.getActualNick());
520		mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
521		if (mucOptions.online()) {
522			mMoreDetails.setVisibility(View.VISIBLE);
523			final String status = getStatus(self);
524			if (status != null) {
525				mRoleAffiliaton.setVisibility(View.VISIBLE);
526				mRoleAffiliaton.setText(status);
527			} else {
528				mRoleAffiliaton.setVisibility(View.GONE);
529			}
530			if (mucOptions.membersOnly()) {
531				mConferenceType.setText(R.string.private_conference);
532			} else {
533				mConferenceType.setText(R.string.public_conference);
534			}
535			if (mucOptions.mamSupport()) {
536				mConferenceInfoMam.setText(R.string.server_info_available);
537			} else {
538				mConferenceInfoMam.setText(R.string.server_info_unavailable);
539			}
540			if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
541				mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
542			} else {
543				mChangeConferenceSettingsButton.setVisibility(View.GONE);
544			}
545		}
546
547		long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
548		if (mutedTill == Long.MAX_VALUE) {
549			mNotifyStatusText.setText(R.string.notify_never);
550			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
551		} else if (System.currentTimeMillis() < mutedTill) {
552			mNotifyStatusText.setText(R.string.notify_paused);
553			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
554		} else if (mConversation.alwaysNotify()) {
555			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
556			mNotifyStatusText.setText(R.string.notify_on_all_messages);
557		} else {
558			mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
559			mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
560		}
561
562		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
563		membersView.removeAllViews();
564		final ArrayList<User> users = mucOptions.getUsers();
565		Collections.sort(users,new Comparator<User>() {
566			@Override
567			public int compare(User lhs, User rhs) {
568				return lhs.getName().compareToIgnoreCase(rhs.getName());
569			}
570		});
571		for (final User user : users) {
572			View view = inflater.inflate(R.layout.contact, membersView,false);
573			this.setListItemBackgroundOnView(view);
574			view.setOnClickListener(new OnClickListener() {
575				@Override
576				public void onClick(View view) {
577					highlightInMuc(mConversation, user.getName());
578				}
579			});
580			registerForContextMenu(view);
581			view.setTag(user);
582			TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name);
583			TextView tvKey = (TextView) view.findViewById(R.id.key);
584			TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid);
585			if (mAdvancedMode && user.getPgpKeyId() != 0) {
586				tvKey.setVisibility(View.VISIBLE);
587				tvKey.setOnClickListener(new OnClickListener() {
588
589					@Override
590					public void onClick(View v) {
591						viewPgpKey(user);
592					}
593				});
594				tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
595			}
596			Contact contact = user.getContact();
597			if (contact != null) {
598				tvDisplayName.setText(contact.getDisplayName());
599				tvStatus.setText(user.getName() + " \u2022 " + getStatus(user));
600			} else {
601				tvDisplayName.setText(user.getName());
602				tvStatus.setText(getStatus(user));
603
604			}
605			ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
606			iv.setImageBitmap(avatarService().get(user, getPixel(48), false));
607			membersView.addView(view);
608			if (mConversation.getMucOptions().canInvite()) {
609				mInviteButton.setVisibility(View.VISIBLE);
610			} else {
611				mInviteButton.setVisibility(View.GONE);
612			}
613		}
614	}
615
616	private String getStatus(User user) {
617		if (mAdvancedMode) {
618			StringBuilder builder = new StringBuilder();
619			builder.append(getString(user.getAffiliation().getResId()));
620			builder.append(" (");
621			builder.append(getString(user.getRole().getResId()));
622			builder.append(')');
623			return builder.toString();
624		} else {
625			return getString(user.getAffiliation().getResId());
626		}
627	}
628
629	@SuppressWarnings("deprecation")
630	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
631	private void setListItemBackgroundOnView(View view) {
632		int sdk = android.os.Build.VERSION.SDK_INT;
633		if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
634			view.setBackgroundDrawable(getResources().getDrawable(R.drawable.greybackground));
635		} else {
636			view.setBackground(getResources().getDrawable(R.drawable.greybackground));
637		}
638	}
639
640	private void viewPgpKey(User user) {
641		PgpEngine pgp = xmppConnectionService.getPgpEngine();
642		if (pgp != null) {
643			PendingIntent intent = pgp.getIntentForKey(
644					mConversation.getAccount(), user.getPgpKeyId());
645			if (intent != null) {
646				try {
647					startIntentSenderForResult(intent.getIntentSender(), 0,
648							null, 0, 0, 0);
649				} catch (SendIntentException ignored) {
650
651				}
652			}
653		}
654	}
655
656	@Override
657	public void onAffiliationChangedSuccessful(Jid jid) {
658
659	}
660
661	@Override
662	public void onAffiliationChangeFailed(Jid jid, int resId) {
663		displayToast(getString(resId,jid.toBareJid().toString()));
664	}
665
666	@Override
667	public void onRoleChangedSuccessful(String nick) {
668
669	}
670
671	@Override
672	public void onRoleChangeFailed(String nick, int resId) {
673		displayToast(getString(resId,nick));
674	}
675
676	@Override
677	public void onPushSucceeded() {
678		displayToast(getString(R.string.modified_conference_options));
679	}
680
681	@Override
682	public void onPushFailed() {
683		displayToast(getString(R.string.could_not_modify_conference_options));
684	}
685
686	private void displayToast(final String msg) {
687		runOnUiThread(new Runnable() {
688			@Override
689			public void run() {
690				Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show();
691			}
692		});
693	}
694}