ConferenceDetailsActivity.java

  1package eu.siacs.conversations.ui;
  2
  3import android.databinding.DataBindingUtil;
  4import android.support.v7.app.AlertDialog;
  5import android.app.PendingIntent;
  6import android.content.Context;
  7import android.content.DialogInterface;
  8import android.content.IntentSender.SendIntentException;
  9import android.content.res.Resources;
 10import android.graphics.Bitmap;
 11import android.graphics.drawable.BitmapDrawable;
 12import android.graphics.drawable.Drawable;
 13import android.os.AsyncTask;
 14import android.os.Bundle;
 15import android.support.v7.widget.CardView;
 16import android.view.ContextMenu;
 17import android.view.LayoutInflater;
 18import android.view.Menu;
 19import android.view.MenuItem;
 20import android.view.View;
 21import android.view.View.OnClickListener;
 22import android.widget.Button;
 23import android.widget.ImageButton;
 24import android.widget.ImageView;
 25import android.widget.LinearLayout;
 26import android.widget.RelativeLayout;
 27import android.widget.TableLayout;
 28import android.widget.TextView;
 29import android.widget.Toast;
 30
 31import org.openintents.openpgp.util.OpenPgpUtils;
 32
 33import java.lang.ref.WeakReference;
 34import java.util.ArrayList;
 35import java.util.Collections;
 36import java.util.concurrent.RejectedExecutionException;
 37import java.util.concurrent.atomic.AtomicInteger;
 38
 39import eu.siacs.conversations.Config;
 40import eu.siacs.conversations.R;
 41import eu.siacs.conversations.crypto.PgpEngine;
 42import eu.siacs.conversations.databinding.ContactBinding;
 43import eu.siacs.conversations.entities.Account;
 44import eu.siacs.conversations.entities.Bookmark;
 45import eu.siacs.conversations.entities.Contact;
 46import eu.siacs.conversations.entities.Conversation;
 47import eu.siacs.conversations.entities.MucOptions;
 48import eu.siacs.conversations.entities.MucOptions.User;
 49import eu.siacs.conversations.services.XmppConnectionService;
 50import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
 51import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
 52import eu.siacs.conversations.utils.UIHelper;
 53import rocks.xmpp.addr.Jid;
 54
 55public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed {
 56	public static final String ACTION_VIEW_MUC = "view_muc";
 57
 58	private static final float INACTIVE_ALPHA = 0.4684f; //compromise between dark and light theme
 59
 60	private Conversation mConversation;
 61	private OnClickListener inviteListener = new OnClickListener() {
 62
 63		@Override
 64		public void onClick(View v) {
 65			inviteToConversation(mConversation);
 66		}
 67	};
 68	private TextView mYourNick;
 69	private ImageView mYourPhoto;
 70	private TextView mFullJid;
 71	private TextView mAccountJid;
 72	private LinearLayout membersView;
 73	private CardView mMoreDetails;
 74	private RelativeLayout mMucSettings;
 75	private TextView mConferenceType;
 76	private TableLayout mConferenceInfoTable;
 77	private TextView mConferenceInfoMam;
 78	private TextView mNotifyStatusText;
 79	private ImageButton mChangeConferenceSettingsButton;
 80	private ImageButton mNotifyStatusButton;
 81	private Button mInviteButton;
 82	private String uuid = null;
 83	private User mSelectedUser = null;
 84
 85	private boolean mAdvancedMode = false;
 86
 87	private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
 88		@Override
 89		public void success(Conversation object) {
 90			runOnUiThread(new Runnable() {
 91				@Override
 92				public void run() {
 93					Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
 94					updateView();
 95				}
 96			});
 97
 98		}
 99
100		@Override
101		public void error(final int errorCode, Conversation object) {
102			runOnUiThread(new Runnable() {
103				@Override
104				public void run() {
105					Toast.makeText(ConferenceDetailsActivity.this,getString(errorCode),Toast.LENGTH_SHORT).show();
106				}
107			});
108		}
109
110		@Override
111		public void userInputRequried(PendingIntent pi, Conversation object) {
112
113		}
114	};
115
116	private OnClickListener mNotifyStatusClickListener = new OnClickListener() {
117		@Override
118		public void onClick(View v) {
119			AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
120			builder.setTitle(R.string.pref_notification_settings);
121			String[] choices = {
122					getString(R.string.notify_on_all_messages),
123					getString(R.string.notify_only_when_highlighted),
124					getString(R.string.notify_never)
125			};
126			final AtomicInteger choice;
127			if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0) == Long.MAX_VALUE) {
128				choice = new AtomicInteger(2);
129			} else {
130				choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
131			}
132			builder.setSingleChoiceItems(choices, choice.get(), new DialogInterface.OnClickListener() {
133				@Override
134				public void onClick(DialogInterface dialog, int which) {
135					choice.set(which);
136				}
137			});
138			builder.setNegativeButton(R.string.cancel, null);
139			builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
140				@Override
141				public void onClick(DialogInterface dialog, int which) {
142					if (choice.get() == 2) {
143						mConversation.setMutedTill(Long.MAX_VALUE);
144					} else {
145						mConversation.setMutedTill(0);
146						mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY,String.valueOf(choice.get() == 0));
147					}
148					xmppConnectionService.updateConversation(mConversation);
149					updateView();
150				}
151			});
152			builder.create().show();
153		}
154	};
155
156	private OnClickListener mChangeConferenceSettings = new OnClickListener() {
157		@Override
158		public void onClick(View v) {
159			final MucOptions mucOptions = mConversation.getMucOptions();
160			AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
161			builder.setTitle(R.string.conference_options);
162			final String[] options;
163			final boolean[] values;
164			if (mAdvancedMode) {
165				options = new String[]{
166						getString(R.string.members_only),
167						getString(R.string.moderated),
168						getString(R.string.non_anonymous)
169				};
170				values = new boolean[]{
171						mucOptions.membersOnly(),
172						mucOptions.moderated(),
173						mucOptions.nonanonymous()
174				};
175			} else {
176				options = new String[]{
177						getString(R.string.members_only),
178						getString(R.string.non_anonymous)
179				};
180				values = new boolean[]{
181						mucOptions.membersOnly(),
182						mucOptions.nonanonymous()
183				};
184			}
185			builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
186				@Override
187				public void onClick(DialogInterface dialog, int which, boolean isChecked) {
188					values[which] = isChecked;
189				}
190			});
191			builder.setNegativeButton(R.string.cancel, null);
192			builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
193				@Override
194				public void onClick(DialogInterface dialog, int which) {
195					if (!mucOptions.membersOnly() && values[0]) {
196						xmppConnectionService.changeAffiliationsInConference(mConversation,
197								MucOptions.Affiliation.NONE,
198								MucOptions.Affiliation.MEMBER);
199					}
200					Bundle options = new Bundle();
201					options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
202					if (values.length == 2) {
203						options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
204					} else if (values.length == 3) {
205						options.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
206						options.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
207					}
208					options.putString("muc#roomconfig_persistentroom", "1");
209					xmppConnectionService.pushConferenceConfiguration(mConversation,
210							options,
211							ConferenceDetailsActivity.this);
212				}
213			});
214			builder.create().show();
215		}
216	};
217	private OnValueEdited onSubjectEdited = new OnValueEdited() {
218
219		@Override
220		public String onValueEdited(String value) {
221			xmppConnectionService.pushSubjectToConference(mConversation,value);
222			return null;
223		}
224	};
225
226	@Override
227	public void onConversationUpdate() {
228		refreshUi();
229	}
230
231	@Override
232	public void onMucRosterUpdate() {
233		refreshUi();
234	}
235
236	@Override
237	protected void refreshUiReal() {
238		updateView();
239	}
240
241	@Override
242	protected void onCreate(Bundle savedInstanceState) {
243		super.onCreate(savedInstanceState);
244		setContentView(R.layout.activity_muc_details);
245		mYourNick = findViewById(R.id.muc_your_nick);
246		mYourPhoto = findViewById(R.id.your_photo);
247		ImageButton mEditNickButton = findViewById(R.id.edit_nick_button);
248		mFullJid = findViewById(R.id.muc_jabberid);
249		membersView = findViewById(R.id.muc_members);
250		mAccountJid = findViewById(R.id.details_account);
251		mMucSettings = findViewById(R.id.muc_settings);
252		mMoreDetails = findViewById(R.id.muc_more_details);
253		mMoreDetails.setVisibility(View.GONE);
254		mChangeConferenceSettingsButton = findViewById(R.id.change_conference_button);
255		mChangeConferenceSettingsButton.setOnClickListener(this.mChangeConferenceSettings);
256		mInviteButton = findViewById(R.id.invite);
257		mInviteButton.setOnClickListener(inviteListener);
258		mConferenceType = findViewById(R.id.muc_conference_type);
259		if (getSupportActionBar() != null) {
260			getSupportActionBar().setHomeButtonEnabled(true);
261			getSupportActionBar().setDisplayHomeAsUpEnabled(true);
262		}
263		mEditNickButton.setOnClickListener(v -> quickEdit(mConversation.getMucOptions().getActualNick(),
264				0,
265				value -> {
266					if (xmppConnectionService.renameInMuc(mConversation,value,renameCallback)) {
267						return null;
268					} else {
269						return getString(R.string.invalid_username);
270					}
271				}));
272		this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
273		this.mConferenceInfoTable = (TableLayout) findViewById(R.id.muc_info_more);
274		this.mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
275		this.mConferenceInfoMam = (TextView) findViewById(R.id.muc_info_mam);
276		this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button);
277		this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener);
278		this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text);
279	}
280
281	@Override
282	protected void onStart() {
283		super.onStart();
284		final int theme = findTheme();
285		if (this.mTheme != theme) {
286			recreate();
287		}
288	}
289
290	@Override
291	public boolean onOptionsItemSelected(MenuItem menuItem) {
292		switch (menuItem.getItemId()) {
293			case android.R.id.home:
294				finish();
295				break;
296			case R.id.action_edit_subject:
297				if (mConversation != null) {
298					quickEdit(mConversation.getMucOptions().getSubject(),
299							R.string.edit_subject_hint,
300							this.onSubjectEdited);
301				}
302				break;
303			case R.id.action_share_http:
304				shareLink(true);
305				break;
306			case R.id.action_share_uri:
307				shareLink(false);
308				break;
309			case R.id.action_save_as_bookmark:
310				saveAsBookmark();
311				break;
312			case R.id.action_delete_bookmark:
313				deleteBookmark();
314				break;
315			case R.id.action_advanced_mode:
316				this.mAdvancedMode = !menuItem.isChecked();
317				menuItem.setChecked(this.mAdvancedMode);
318				getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).apply();
319				final boolean online = mConversation != null && mConversation.getMucOptions().online();
320				mConferenceInfoTable.setVisibility(this.mAdvancedMode && online ? View.VISIBLE : View.GONE);
321				invalidateOptionsMenu();
322				updateView();
323				break;
324		}
325		return super.onOptionsItemSelected(menuItem);
326	}
327
328	@Override
329	protected String getShareableUri(boolean http) {
330		if (mConversation != null) {
331			if (http) {
332				return "https://conversations.im/j/"+ mConversation.getJid().asBareJid().toEscapedString();
333			} else {
334				return "xmpp:"+mConversation.getJid().asBareJid()+"?join";
335			}
336		} else {
337			return null;
338		}
339	}
340
341	@Override
342	public boolean onPrepareOptionsMenu(Menu menu) {
343		MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
344		MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
345		MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
346		MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject);
347		menuItemAdvancedMode.setChecked(mAdvancedMode);
348		if (mConversation == null) {
349			return true;
350		}
351		if (mConversation.getBookmark() != null) {
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().asBareJid().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().asBareJid(),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		account.getBookmarks().remove(bookmark);
519		bookmark.setConversation(null);
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().getLocal();
548		} else {
549			account = mConversation.getAccount().getJid().asBareJid().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().asBareJid().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		final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
610		membersView.removeAllViews();
611		if (inflater == null) {
612			return;
613		}
614		final ArrayList<User> users = mucOptions.getUsers();
615		Collections.sort(users);
616		for (final User user : users) {
617			ContactBinding binding = DataBindingUtil.inflate(inflater,R.layout.contact,membersView,false);
618			this.setListItemBackgroundOnView(binding.getRoot());
619			binding.getRoot().setOnClickListener(view1 -> highlightInMuc(mConversation, user.getName()));
620			registerForContextMenu(binding.getRoot());
621			binding.getRoot().setTag(user);
622			if (mAdvancedMode && user.getPgpKeyId() != 0) {
623				binding.key.setVisibility(View.VISIBLE);
624				binding.key.setOnClickListener(v -> viewPgpKey(user));
625				binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
626			}
627			Contact contact = user.getContact();
628			String name = user.getName();
629			if (contact != null) {
630				binding.contactDisplayName.setText(contact.getDisplayName());
631				binding.contactJid.setText((name != null ? name+ " \u2022 " : "") + getStatus(user));
632			} else {
633				binding.contactDisplayName.setText(name == null ? "" : name);
634				binding.contactJid.setText(getStatus(user));
635
636			}
637			loadAvatar(user,binding.contactPhoto);
638			if (user.getRole() == MucOptions.Role.NONE) {
639				binding.contactJid.setAlpha(INACTIVE_ALPHA);
640				binding.key.setAlpha(INACTIVE_ALPHA);
641				binding.contactDisplayName.setAlpha(INACTIVE_ALPHA);
642				binding.contactPhoto.setAlpha(INACTIVE_ALPHA);
643			}
644			membersView.addView(binding.getRoot());
645			if (mConversation.getMucOptions().canInvite()) {
646				mInviteButton.setVisibility(View.VISIBLE);
647			} else {
648				mInviteButton.setVisibility(View.GONE);
649			}
650		}
651	}
652
653	private String getStatus(User user) {
654		if (mAdvancedMode) {
655			return getString(user.getAffiliation().getResId()) +
656					" (" + getString(user.getRole().getResId()) + ')';
657		} else {
658			return getString(user.getAffiliation().getResId());
659		}
660	}
661
662	private void viewPgpKey(User user) {
663		PgpEngine pgp = xmppConnectionService.getPgpEngine();
664		if (pgp != null) {
665			PendingIntent intent = pgp.getIntentForKey(user.getPgpKeyId());
666			if (intent != null) {
667				try {
668					startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
669				} catch (SendIntentException ignored) {
670
671				}
672			}
673		}
674	}
675
676	@Override
677	public void onAffiliationChangedSuccessful(Jid jid) {
678		refreshUi();
679	}
680
681	@Override
682	public void onAffiliationChangeFailed(Jid jid, int resId) {
683		displayToast(getString(resId,jid.asBareJid().toString()));
684	}
685
686	@Override
687	public void onRoleChangedSuccessful(String nick) {
688
689	}
690
691	@Override
692	public void onRoleChangeFailed(String nick, int resId) {
693		displayToast(getString(resId,nick));
694	}
695
696	@Override
697	public void onPushSucceeded() {
698		displayToast(getString(R.string.modified_conference_options));
699	}
700
701	@Override
702	public void onPushFailed() {
703		displayToast(getString(R.string.could_not_modify_conference_options));
704	}
705
706	private void displayToast(final String msg) {
707		runOnUiThread(() -> Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show());
708	}
709
710
711	class BitmapWorkerTask extends AsyncTask<User, Void, Bitmap> {
712		private final WeakReference<ImageView> imageViewReference;
713		private User o = null;
714
715		private BitmapWorkerTask(ImageView imageView) {
716			imageViewReference = new WeakReference<>(imageView);
717		}
718
719		@Override
720		protected Bitmap doInBackground(User... params) {
721			this.o = params[0];
722			if (imageViewReference.get() == null) {
723				return null;
724			}
725			return avatarService().get(this.o, getPixel(48), isCancelled());
726		}
727
728		@Override
729		protected void onPostExecute(Bitmap bitmap) {
730			if (bitmap != null && !isCancelled()) {
731				final ImageView imageView = imageViewReference.get();
732				if (imageView != null) {
733					imageView.setImageBitmap(bitmap);
734					imageView.setBackgroundColor(0x00000000);
735				}
736			}
737		}
738	}
739
740	public void loadAvatar(User user, ImageView imageView) {
741		if (cancelPotentialWork(user, imageView)) {
742			final Bitmap bm = avatarService().get(user,getPixel(48),true);
743			if (bm != null) {
744				cancelPotentialWork(user, imageView);
745				imageView.setImageBitmap(bm);
746				imageView.setBackgroundColor(0x00000000);
747			} else {
748				String seed = user.getRealJid() != null ? user.getRealJid().asBareJid().toString() : null;
749				imageView.setBackgroundColor(UIHelper.getColorForName(seed == null ? user.getName() : seed));
750				imageView.setImageDrawable(null);
751				final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
752				final AsyncDrawable asyncDrawable = new AsyncDrawable(getResources(), null, task);
753				imageView.setImageDrawable(asyncDrawable);
754				try {
755					task.execute(user);
756				} catch (final RejectedExecutionException ignored) {
757				}
758			}
759		}
760	}
761
762	public static boolean cancelPotentialWork(User user, ImageView imageView) {
763		final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
764
765		if (bitmapWorkerTask != null) {
766			final User old = bitmapWorkerTask.o;
767			if (old == null || user != old) {
768				bitmapWorkerTask.cancel(true);
769			} else {
770				return false;
771			}
772		}
773		return true;
774	}
775
776	private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
777		if (imageView != null) {
778			final Drawable drawable = imageView.getDrawable();
779			if (drawable instanceof AsyncDrawable) {
780				final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
781				return asyncDrawable.getBitmapWorkerTask();
782			}
783		}
784		return null;
785	}
786
787	static class AsyncDrawable extends BitmapDrawable {
788		private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
789
790		public AsyncDrawable(Resources res, Bitmap bitmap, BitmapWorkerTask bitmapWorkerTask) {
791			super(res, bitmap);
792			bitmapWorkerTaskReference = new WeakReference<>(bitmapWorkerTask);
793		}
794
795		public BitmapWorkerTask getBitmapWorkerTask() {
796			return bitmapWorkerTaskReference.get();
797		}
798	}
799
800}