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