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