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