ConferenceDetailsActivity.java

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