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