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