1package eu.siacs.conversations.ui;
2
3import android.app.AlertDialog;
4import android.app.PendingIntent;
5import android.content.ActivityNotFoundException;
6import android.content.Context;
7import android.content.DialogInterface;
8import android.content.Intent;
9import android.content.IntentSender.SendIntentException;
10import android.os.Bundle;
11import android.view.ContextMenu;
12import android.view.LayoutInflater;
13import android.view.Menu;
14import android.view.MenuItem;
15import android.view.View;
16import android.view.View.OnClickListener;
17import android.widget.Button;
18import android.widget.ImageButton;
19import android.widget.ImageView;
20import android.widget.LinearLayout;
21import android.widget.TableLayout;
22import android.widget.TextView;
23import android.widget.Toast;
24
25import org.openintents.openpgp.util.OpenPgpUtils;
26
27import java.util.ArrayList;
28import java.util.Collections;
29import java.util.concurrent.atomic.AtomicInteger;
30
31import eu.siacs.conversations.Config;
32import eu.siacs.conversations.R;
33import eu.siacs.conversations.crypto.PgpEngine;
34import eu.siacs.conversations.entities.Account;
35import eu.siacs.conversations.entities.Bookmark;
36import eu.siacs.conversations.entities.Contact;
37import eu.siacs.conversations.entities.Conversation;
38import eu.siacs.conversations.entities.MucOptions;
39import eu.siacs.conversations.entities.MucOptions.User;
40import eu.siacs.conversations.services.XmppConnectionService;
41import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
42import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
43import eu.siacs.conversations.xmpp.jid.Jid;
44
45public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed {
46 public static final String ACTION_VIEW_MUC = "view_muc";
47 private Conversation mConversation;
48 private OnClickListener inviteListener = new OnClickListener() {
49
50 @Override
51 public void onClick(View v) {
52 inviteToConversation(mConversation);
53 }
54 };
55 private TextView mYourNick;
56 private ImageView mYourPhoto;
57 private ImageButton mEditNickButton;
58 private TextView mRoleAffiliaton;
59 private TextView mFullJid;
60 private TextView mAccountJid;
61 private LinearLayout membersView;
62 private LinearLayout mMoreDetails;
63 private TextView mConferenceType;
64 private TableLayout mConferenceInfoTable;
65 private TextView mConferenceInfoMam;
66 private TextView mNotifyStatusText;
67 private ImageButton mChangeConferenceSettingsButton;
68 private ImageButton mNotifyStatusButton;
69 private Button mInviteButton;
70 private String uuid = null;
71 private User mSelectedUser = null;
72
73 private boolean mAdvancedMode = false;
74
75 private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
76 @Override
77 public void success(Conversation object) {
78 runOnUiThread(new Runnable() {
79 @Override
80 public void run() {
81 Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
82 updateView();
83 }
84 });
85
86 }
87
88 @Override
89 public void error(final int errorCode, Conversation object) {
90 runOnUiThread(new Runnable() {
91 @Override
92 public void run() {
93 Toast.makeText(ConferenceDetailsActivity.this,getString(errorCode),Toast.LENGTH_SHORT).show();
94 }
95 });
96 }
97
98 @Override
99 public void userInputRequried(PendingIntent pi, Conversation object) {
100
101 }
102 };
103
104 private OnClickListener mNotifyStatusClickListener = new OnClickListener() {
105 @Override
106 public void onClick(View v) {
107 AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
108 builder.setTitle(R.string.pref_notification_settings);
109 String[] choices = {
110 getString(R.string.notify_on_all_messages),
111 getString(R.string.notify_only_when_highlighted),
112 getString(R.string.notify_never)
113 };
114 final AtomicInteger choice;
115 if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0) == Long.MAX_VALUE) {
116 choice = new AtomicInteger(2);
117 } else {
118 choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
119 }
120 builder.setSingleChoiceItems(choices, choice.get(), new DialogInterface.OnClickListener() {
121 @Override
122 public void onClick(DialogInterface dialog, int which) {
123 choice.set(which);
124 }
125 });
126 builder.setNegativeButton(R.string.cancel, null);
127 builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
128 @Override
129 public void onClick(DialogInterface dialog, int which) {
130 if (choice.get() == 2) {
131 mConversation.setMutedTill(Long.MAX_VALUE);
132 } else {
133 mConversation.setMutedTill(0);
134 mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY,String.valueOf(choice.get() == 0));
135 }
136 xmppConnectionService.updateConversation(mConversation);
137 updateView();
138 }
139 });
140 builder.create().show();
141 }
142 };
143
144 private OnClickListener mChangeConferenceSettings = new OnClickListener() {
145 @Override
146 public void onClick(View v) {
147 final MucOptions mucOptions = mConversation.getMucOptions();
148 AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
149 builder.setTitle(R.string.conference_options);
150 final String[] options;
151 final boolean[] values;
152 if (mAdvancedMode) {
153 options = new String[]{
154 getString(R.string.members_only),
155 getString(R.string.moderated),
156 getString(R.string.non_anonymous)
157 };
158 values = new boolean[]{
159 mucOptions.membersOnly(),
160 mucOptions.moderated(),
161 mucOptions.nonanonymous()
162 };
163 } else {
164 options = new String[]{
165 getString(R.string.members_only),
166 getString(R.string.non_anonymous)
167 };
168 values = new boolean[]{
169 mucOptions.membersOnly(),
170 mucOptions.nonanonymous()
171 };
172 }
173 builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
174 @Override
175 public void onClick(DialogInterface dialog, int which, boolean isChecked) {
176 values[which] = isChecked;
177 }
178 });
179 builder.setNegativeButton(R.string.cancel, null);
180 builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
181 @Override
182 public void onClick(DialogInterface dialog, int which) {
183 if (!mucOptions.membersOnly() && values[0]) {
184 xmppConnectionService.changeAffiliationsInConference(mConversation,
185 MucOptions.Affiliation.NONE,
186 MucOptions.Affiliation.MEMBER);
187 }
188 Bundle options = new Bundle();
189 options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
190 if (values.length == 2) {
191 options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
192 } else if (values.length == 3) {
193 options.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
194 options.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
195 }
196 options.putString("muc#roomconfig_persistentroom", "1");
197 xmppConnectionService.pushConferenceConfiguration(mConversation,
198 options,
199 ConferenceDetailsActivity.this);
200 }
201 });
202 builder.create().show();
203 }
204 };
205 private OnValueEdited onSubjectEdited = new OnValueEdited() {
206
207 @Override
208 public void onValueEdited(String value) {
209 xmppConnectionService.pushSubjectToConference(mConversation,value);
210 }
211 };
212
213 @Override
214 public void onConversationUpdate() {
215 refreshUi();
216 }
217
218 @Override
219 public void onMucRosterUpdate() {
220 refreshUi();
221 }
222
223 @Override
224 protected void refreshUiReal() {
225 updateView();
226 }
227
228 @Override
229 protected void onCreate(Bundle savedInstanceState) {
230 super.onCreate(savedInstanceState);
231 setContentView(R.layout.activity_muc_details);
232 mYourNick = (TextView) findViewById(R.id.muc_your_nick);
233 mYourPhoto = (ImageView) findViewById(R.id.your_photo);
234 mEditNickButton = (ImageButton) findViewById(R.id.edit_nick_button);
235 mFullJid = (TextView) findViewById(R.id.muc_jabberid);
236 membersView = (LinearLayout) findViewById(R.id.muc_members);
237 mAccountJid = (TextView) findViewById(R.id.details_account);
238 mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
239 mMoreDetails.setVisibility(View.GONE);
240 mChangeConferenceSettingsButton = (ImageButton) findViewById(R.id.change_conference_button);
241 mChangeConferenceSettingsButton.setOnClickListener(this.mChangeConferenceSettings);
242 mInviteButton = (Button) findViewById(R.id.invite);
243 mInviteButton.setOnClickListener(inviteListener);
244 mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
245 if (getActionBar() != null) {
246 getActionBar().setHomeButtonEnabled(true);
247 getActionBar().setDisplayHomeAsUpEnabled(true);
248 }
249 mEditNickButton.setOnClickListener(new OnClickListener() {
250
251 @Override
252 public void onClick(View v) {
253 quickEdit(mConversation.getMucOptions().getActualNick(),
254 0,
255 new OnValueEdited() {
256
257 @Override
258 public void onValueEdited(String value) {
259 xmppConnectionService.renameInMuc(mConversation,value,renameCallback);
260 }
261 });
262 }
263 });
264 this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
265 this.mConferenceInfoTable = (TableLayout) findViewById(R.id.muc_info_more);
266 mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
267 this.mConferenceInfoMam = (TextView) findViewById(R.id.muc_info_mam);
268 this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button);
269 this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener);
270 this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text);
271 }
272
273 @Override
274 public boolean onOptionsItemSelected(MenuItem menuItem) {
275 switch (menuItem.getItemId()) {
276 case android.R.id.home:
277 finish();
278 break;
279 case R.id.action_edit_subject:
280 if (mConversation != null) {
281 quickEdit(mConversation.getMucOptions().getSubject(),
282 R.string.edit_subject_hint,
283 this.onSubjectEdited);
284 }
285 break;
286 case R.id.action_share:
287 share();
288 break;
289 case R.id.action_save_as_bookmark:
290 saveAsBookmark();
291 break;
292 case R.id.action_delete_bookmark:
293 deleteBookmark();
294 break;
295 case R.id.action_advanced_mode:
296 this.mAdvancedMode = !menuItem.isChecked();
297 menuItem.setChecked(this.mAdvancedMode);
298 getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).commit();
299 mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
300 invalidateOptionsMenu();
301 updateView();
302 break;
303 }
304 return super.onOptionsItemSelected(menuItem);
305 }
306
307 @Override
308 protected String getShareableUri() {
309 if (mConversation != null) {
310 return "xmpp:" + mConversation.getJid().toBareJid().toString() + "?join";
311 } else {
312 return "";
313 }
314 }
315
316 private void share() {
317 Intent shareIntent = new Intent();
318 shareIntent.setAction(Intent.ACTION_SEND);
319 shareIntent.putExtra(Intent.EXTRA_TEXT, getShareableUri());
320 shareIntent.setType("text/plain");
321 try {
322 startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
323 } catch (ActivityNotFoundException e) {
324 Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
325 }
326 }
327
328 @Override
329 public boolean onPrepareOptionsMenu(Menu menu) {
330 MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
331 MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
332 MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
333 MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject);
334 menuItemAdvancedMode.setChecked(mAdvancedMode);
335 if (mConversation == null) {
336 return true;
337 }
338 Account account = mConversation.getAccount();
339 if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
340 menuItemSaveBookmark.setVisible(false);
341 menuItemDeleteBookmark.setVisible(true);
342 } else {
343 menuItemDeleteBookmark.setVisible(false);
344 menuItemSaveBookmark.setVisible(true);
345 }
346 menuItemChangeSubject.setVisible(mConversation.getMucOptions().canChangeSubject());
347 return true;
348 }
349
350 @Override
351 public boolean onCreateOptionsMenu(Menu menu) {
352 getMenuInflater().inflate(R.menu.muc_details, menu);
353 return super.onCreateOptionsMenu(menu);
354 }
355
356 @Override
357 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
358 Object tag = v.getTag();
359 if (tag instanceof User) {
360 getMenuInflater().inflate(R.menu.muc_details_context,menu);
361 final User user = (User) tag;
362 final User self = mConversation.getMucOptions().getSelf();
363 this.mSelectedUser = user;
364 String name;
365 final Contact contact = user.getContact();
366 if (contact != null) {
367 name = contact.getDisplayName();
368 } else if (user.getRealJid() != null){
369 name = user.getRealJid().toBareJid().toString();
370 } else {
371 name = user.getName();
372 }
373 menu.setHeaderTitle(name);
374 if (user.getRealJid() != null) {
375 MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
376 MenuItem startConversation = menu.findItem(R.id.start_conversation);
377 MenuItem giveMembership = menu.findItem(R.id.give_membership);
378 MenuItem removeMembership = menu.findItem(R.id.remove_membership);
379 MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
380 MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
381 MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
382 MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
383 MenuItem invite = menu.findItem(R.id.invite);
384 startConversation.setVisible(true);
385 if (contact != null) {
386 showContactDetails.setVisible(true);
387 }
388 if (user.getRole() == MucOptions.Role.NONE) {
389 invite.setVisible(true);
390 }
391 if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
392 self.getAffiliation().outranks(user.getAffiliation())) {
393 if (mAdvancedMode) {
394 if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
395 giveMembership.setVisible(true);
396 } else {
397 removeMembership.setVisible(true);
398 }
399 banFromConference.setVisible(true);
400 } else {
401 removeFromRoom.setVisible(true);
402 }
403 if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
404 giveAdminPrivileges.setVisible(true);
405 } else {
406 removeAdminPrivileges.setVisible(true);
407 }
408 }
409 } else {
410 MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
411 sendPrivateMessage.setVisible(user.getRole().ranks(MucOptions.Role.PARTICIPANT));
412 }
413
414 }
415 super.onCreateContextMenu(menu, v, menuInfo);
416 }
417
418 @Override
419 public boolean onContextItemSelected(MenuItem item) {
420 switch (item.getItemId()) {
421 case R.id.action_contact_details:
422 Contact contact = mSelectedUser.getContact();
423 if (contact != null) {
424 switchToContactDetails(contact);
425 }
426 return true;
427 case R.id.start_conversation:
428 startConversation(mSelectedUser);
429 return true;
430 case R.id.give_admin_privileges:
431 xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.ADMIN,this);
432 return true;
433 case R.id.give_membership:
434 xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.MEMBER,this);
435 return true;
436 case R.id.remove_membership:
437 xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.NONE,this);
438 return true;
439 case R.id.remove_admin_privileges:
440 xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.MEMBER,this);
441 return true;
442 case R.id.remove_from_room:
443 removeFromRoom(mSelectedUser);
444 return true;
445 case R.id.ban_from_conference:
446 xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.OUTCAST,this);
447 if (mSelectedUser.getRole() != MucOptions.Role.NONE) {
448 xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, this);
449 }
450 return true;
451 case R.id.send_private_message:
452 privateMsgInMuc(mConversation,mSelectedUser.getName());
453 return true;
454 default:
455 return super.onContextItemSelected(item);
456 }
457 }
458
459 private void removeFromRoom(final User user) {
460 if (mConversation.getMucOptions().membersOnly()) {
461 xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.NONE,this);
462 if (user.getRole() != MucOptions.Role.NONE) {
463 xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
464 }
465 } else {
466 AlertDialog.Builder builder = new AlertDialog.Builder(this);
467 builder.setTitle(R.string.ban_from_conference);
468 builder.setMessage(getString(R.string.removing_from_public_conference,user.getName()));
469 builder.setNegativeButton(R.string.cancel,null);
470 builder.setPositiveButton(R.string.ban_now,new DialogInterface.OnClickListener() {
471 @Override
472 public void onClick(DialogInterface dialog, int which) {
473 xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
474 if (user.getRole() != MucOptions.Role.NONE) {
475 xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
476 }
477 }
478 });
479 builder.create().show();
480 }
481 }
482
483 protected void startConversation(User user) {
484 if (user.getRealJid() != null) {
485 Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false);
486 switchToConversation(conversation);
487 }
488 }
489
490 protected void saveAsBookmark() {
491 xmppConnectionService.saveConversationAsBookmark(mConversation,
492 mConversation.getMucOptions().getSubject());
493 }
494
495 protected void deleteBookmark() {
496 Account account = mConversation.getAccount();
497 Bookmark bookmark = mConversation.getBookmark();
498 bookmark.unregisterConversation();
499 account.getBookmarks().remove(bookmark);
500 xmppConnectionService.pushBookmarks(account);
501 }
502
503 @Override
504 void onBackendConnected() {
505 if (mPendingConferenceInvite != null) {
506 mPendingConferenceInvite.execute(this);
507 mPendingConferenceInvite = null;
508 }
509 if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
510 this.uuid = getIntent().getExtras().getString("uuid");
511 }
512 if (uuid != null) {
513 this.mConversation = xmppConnectionService
514 .findConversationByUuid(uuid);
515 if (this.mConversation != null) {
516 updateView();
517 }
518 }
519 }
520
521 private void updateView() {
522 final MucOptions mucOptions = mConversation.getMucOptions();
523 final User self = mucOptions.getSelf();
524 String account;
525 if (Config.DOMAIN_LOCK != null) {
526 account = mConversation.getAccount().getJid().getLocalpart();
527 } else {
528 account = mConversation.getAccount().getJid().toBareJid().toString();
529 }
530 mAccountJid.setText(getString(R.string.using_account, account));
531 mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
532 setTitle(mConversation.getName());
533 mFullJid.setText(mConversation.getJid().toBareJid().toString());
534 mYourNick.setText(mucOptions.getActualNick());
535 mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
536 if (mucOptions.online()) {
537 mMoreDetails.setVisibility(View.VISIBLE);
538 final String status = getStatus(self);
539 if (status != null) {
540 mRoleAffiliaton.setVisibility(View.VISIBLE);
541 mRoleAffiliaton.setText(status);
542 } else {
543 mRoleAffiliaton.setVisibility(View.GONE);
544 }
545 if (mucOptions.membersOnly()) {
546 mConferenceType.setText(R.string.private_conference);
547 } else {
548 mConferenceType.setText(R.string.public_conference);
549 }
550 if (mucOptions.mamSupport()) {
551 mConferenceInfoMam.setText(R.string.server_info_available);
552 } else {
553 mConferenceInfoMam.setText(R.string.server_info_unavailable);
554 }
555 if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
556 mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
557 } else {
558 mChangeConferenceSettingsButton.setVisibility(View.GONE);
559 }
560 }
561
562 int ic_notifications = getThemeResource(R.attr.icon_notifications, R.drawable.ic_notifications_black54_24dp);
563 int ic_notifications_off = getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black54_24dp);
564 int ic_notifications_paused = getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black54_24dp);
565 int ic_notifications_none = getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black54_24dp);
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(ic_notifications_off);
571 } else if (System.currentTimeMillis() < mutedTill) {
572 mNotifyStatusText.setText(R.string.notify_paused);
573 mNotifyStatusButton.setImageResource(ic_notifications_paused);
574 } else if (mConversation.alwaysNotify()) {
575 mNotifyStatusButton.setImageResource(ic_notifications);
576 mNotifyStatusText.setText(R.string.notify_on_all_messages);
577 } else {
578 mNotifyStatusButton.setImageResource(ic_notifications_none);
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}