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