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