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