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