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