1package eu.siacs.conversations.ui;
2
3import android.app.PendingIntent;
4import android.content.Context;
5import android.content.Intent;
6import android.content.IntentSender.SendIntentException;
7import android.databinding.DataBindingUtil;
8import android.os.Bundle;
9import android.support.v7.app.AlertDialog;
10import android.support.v7.widget.Toolbar;
11import android.text.Editable;
12import android.text.SpannableStringBuilder;
13import android.text.TextWatcher;
14import android.view.Menu;
15import android.view.MenuItem;
16import android.view.View;
17import android.view.View.OnClickListener;
18import android.widget.Toast;
19
20import java.util.Collections;
21import java.util.List;
22import java.util.concurrent.atomic.AtomicInteger;
23
24import eu.siacs.conversations.Config;
25import eu.siacs.conversations.R;
26import eu.siacs.conversations.crypto.PgpEngine;
27import eu.siacs.conversations.databinding.ActivityMucDetailsBinding;
28import eu.siacs.conversations.entities.Account;
29import eu.siacs.conversations.entities.Bookmark;
30import eu.siacs.conversations.entities.Conversation;
31import eu.siacs.conversations.entities.MucOptions;
32import eu.siacs.conversations.entities.MucOptions.User;
33import eu.siacs.conversations.services.XmppConnectionService;
34import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
35import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
36import eu.siacs.conversations.ui.adapter.MediaAdapter;
37import eu.siacs.conversations.ui.adapter.UserPreviewAdapter;
38import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
39import eu.siacs.conversations.ui.util.Attachment;
40import eu.siacs.conversations.ui.util.AvatarWorkerTask;
41import eu.siacs.conversations.ui.util.GridManager;
42import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
43import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
44import eu.siacs.conversations.ui.util.MyLinkify;
45import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
46import eu.siacs.conversations.utils.AccountUtils;
47import eu.siacs.conversations.utils.Compatibility;
48import eu.siacs.conversations.utils.EmojiWrapper;
49import eu.siacs.conversations.utils.StringUtils;
50import eu.siacs.conversations.utils.StylingHelper;
51import eu.siacs.conversations.utils.XmppUri;
52import me.drakeet.support.toast.ToastCompat;
53import rocks.xmpp.addr.Jid;
54
55import static eu.siacs.conversations.entities.Bookmark.printableValue;
56import static eu.siacs.conversations.utils.StringUtils.changed;
57
58public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnConfigurationPushed, XmppConnectionService.OnRoomDestroy, TextWatcher, OnMediaLoaded {
59 public static final String ACTION_VIEW_MUC = "view_muc";
60
61 private Conversation mConversation;
62 private ActivityMucDetailsBinding binding;
63 private MediaAdapter mMediaAdapter;
64 private UserPreviewAdapter mUserPreviewAdapter;
65 private String uuid = null;
66
67 private boolean mAdvancedMode = false;
68
69 private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
70 @Override
71 public void success(Conversation object) {
72 displayToast(getString(R.string.your_nick_has_been_changed));
73 runOnUiThread(() -> {
74 updateView();
75 });
76
77 }
78
79 @Override
80 public void error(final int errorCode, Conversation object) {
81 displayToast(getString(errorCode));
82 }
83
84 @Override
85 public void userInputRequried(PendingIntent pi, Conversation object) {
86
87 }
88 };
89
90 private OnClickListener mNotifyStatusClickListener = new OnClickListener() {
91 @Override
92 public void onClick(View v) {
93 AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
94 builder.setTitle(R.string.pref_notification_settings);
95 String[] choices = {
96 getString(R.string.notify_on_all_messages),
97 getString(R.string.notify_only_when_highlighted),
98 getString(R.string.notify_never)
99 };
100 final AtomicInteger choice;
101 if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0) == Long.MAX_VALUE) {
102 choice = new AtomicInteger(2);
103 } else {
104 choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
105 }
106 builder.setSingleChoiceItems(choices, choice.get(), (dialog, which) -> choice.set(which));
107 builder.setNegativeButton(R.string.cancel, null);
108 builder.setPositiveButton(R.string.ok, (dialog, which) -> {
109 if (choice.get() == 2) {
110 mConversation.setMutedTill(Long.MAX_VALUE);
111 } else {
112 mConversation.setMutedTill(0);
113 mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY, String.valueOf(choice.get() == 0));
114 }
115 xmppConnectionService.updateConversation(mConversation);
116 updateView();
117 });
118 builder.create().show();
119 }
120 };
121
122 private OnClickListener mChangeConferenceSettings = new OnClickListener() {
123 @Override
124 public void onClick(View v) {
125 final MucOptions mucOptions = mConversation.getMucOptions();
126 AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
127 builder.setTitle(R.string.conference_options);
128 final String[] options;
129 final boolean[] values;
130 if (mAdvancedMode) {
131 options = new String[]{
132 getString(R.string.members_only),
133 getString(R.string.moderated),
134 getString(R.string.non_anonymous)
135 };
136 values = new boolean[]{
137 mucOptions.membersOnly(),
138 mucOptions.moderated(),
139 mucOptions.nonanonymous()
140 };
141 } else {
142 options = new String[]{
143 getString(R.string.members_only),
144 getString(R.string.non_anonymous)
145 };
146 values = new boolean[]{
147 mucOptions.membersOnly(),
148 mucOptions.nonanonymous()
149 };
150 }
151 builder.setMultiChoiceItems(options, values, (dialog, which, isChecked) -> values[which] = isChecked);
152 builder.setNegativeButton(R.string.cancel, null);
153 builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
154 if (!mucOptions.membersOnly() && values[0]) {
155 xmppConnectionService.changeAffiliationsInConference(mConversation,
156 MucOptions.Affiliation.NONE,
157 MucOptions.Affiliation.MEMBER);
158 }
159 Bundle options1 = new Bundle();
160 options1.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
161 if (values.length == 2) {
162 options1.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
163 } else if (values.length == 3) {
164 options1.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
165 options1.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
166 }
167 options1.putString("muc#roomconfig_persistentroom", "1");
168 final boolean whois = values.length == 2 ? values[1] : values[2];
169 if (values[0] == whois) {
170 options1.putString("muc#roomconfig_publicroom", whois ? "0" : "1");
171 }
172 xmppConnectionService.pushConferenceConfiguration(mConversation,
173 options1,
174 ConferenceDetailsActivity.this);
175 });
176 builder.create().show();
177 }
178 };
179
180
181 @Override
182 public void onConversationUpdate() {
183 refreshUi();
184 }
185
186 @Override
187 public void onMucRosterUpdate() {
188 refreshUi();
189 }
190
191 @Override
192 protected void refreshUiReal() {
193 updateView();
194 }
195
196 @Override
197 protected void onCreate(Bundle savedInstanceState) {
198 super.onCreate(savedInstanceState);
199 this.binding = DataBindingUtil.setContentView(this, R.layout.activity_muc_details);
200 this.binding.changeConferenceButton.setOnClickListener(this.mChangeConferenceSettings);
201 setSupportActionBar((Toolbar) binding.toolbar);
202 configureActionBar(getSupportActionBar());
203 this.binding.editNickButton.setOnClickListener(v -> quickEdit(mConversation.getMucOptions().getActualNick(),
204 R.string.nickname,
205 value -> {
206 if (xmppConnectionService.renameInMuc(mConversation, value, renameCallback)) {
207 return null;
208 } else {
209 return getString(R.string.invalid_muc_nick);
210 }
211 }));
212 this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
213 this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
214 this.binding.notificationStatusButton.setOnClickListener(this.mNotifyStatusClickListener);
215 this.binding.yourPhoto.setOnClickListener(v -> {
216 final MucOptions mucOptions = mConversation.getMucOptions();
217 if (!mucOptions.hasVCards()) {
218 Toast.makeText(this, R.string.host_does_not_support_group_chat_avatars, Toast.LENGTH_SHORT).show();
219 return;
220 }
221 if (!mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
222 Toast.makeText(this, R.string.only_the_owner_can_change_group_chat_avatar, Toast.LENGTH_SHORT).show();
223 return;
224 }
225 final Intent intent = new Intent(this, PublishGroupChatProfilePictureActivity.class);
226 intent.putExtra("uuid", mConversation.getUuid());
227 startActivity(intent);
228 });
229 this.binding.editMucNameButton.setOnClickListener(this::onMucEditButtonClicked);
230 this.binding.mucEditTitle.addTextChangedListener(this);
231 this.binding.mucEditSubject.addTextChangedListener(this);
232 this.binding.mucEditSubject.addTextChangedListener(new StylingHelper.MessageEditorStyler(this.binding.mucEditSubject));
233 this.mMediaAdapter = new MediaAdapter(this, R.dimen.media_size);
234 this.mUserPreviewAdapter = new UserPreviewAdapter();
235 this.binding.media.setAdapter(mMediaAdapter);
236 this.binding.users.setAdapter(mUserPreviewAdapter);
237 GridManager.setupLayoutManager(this, this.binding.media, R.dimen.media_size);
238 GridManager.setupLayoutManager(this, this.binding.users, R.dimen.media_size);
239 this.binding.invite.setOnClickListener(v -> inviteToConversation(mConversation));
240 this.binding.showUsers.setOnClickListener(v -> {
241 Intent intent = new Intent(this, MucUsersActivity.class);
242 intent.putExtra("uuid", mConversation.getUuid());
243 startActivity(intent);
244 });
245 }
246
247 @Override
248 protected void onStart() {
249 super.onStart();
250 final int theme = findTheme();
251 if (this.mTheme != theme) {
252 recreate();
253 }
254 binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
255 }
256
257 @Override
258 public boolean onOptionsItemSelected(MenuItem menuItem) {
259 if (MenuDoubleTabUtil.shouldIgnoreTap()) {
260 return false;
261 }
262 switch (menuItem.getItemId()) {
263 case android.R.id.home:
264 finish();
265 break;
266 case R.id.action_share_http:
267 shareLink(true);
268 break;
269 case R.id.action_share_uri:
270 shareLink(false);
271 break;
272 case R.id.action_save_as_bookmark:
273 saveAsBookmark();
274 break;
275 case R.id.action_delete_bookmark:
276 deleteBookmark();
277 break;
278 case R.id.action_destroy_room:
279 destroyRoom();
280 break;
281 case R.id.action_advanced_mode:
282 this.mAdvancedMode = !menuItem.isChecked();
283 menuItem.setChecked(this.mAdvancedMode);
284 getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).apply();
285 final boolean online = mConversation != null && mConversation.getMucOptions().online();
286 this.binding.mucInfoMore.setVisibility(this.mAdvancedMode && online ? View.VISIBLE : View.GONE);
287 invalidateOptionsMenu();
288 updateView();
289 break;
290 }
291 return super.onOptionsItemSelected(menuItem);
292 }
293
294 @Override
295 public boolean onContextItemSelected(MenuItem item) {
296 if (!MucDetailsContextMenuHelper.onContextItemSelected(item, mUserPreviewAdapter.getSelectedUser(), this)) {
297 return super.onContextItemSelected(item);
298 }
299 return true;
300 }
301
302 public void onMucEditButtonClicked(View v) {
303 if (this.binding.mucEditor.getVisibility() == View.GONE) {
304 final MucOptions mucOptions = mConversation.getMucOptions();
305 this.binding.mucEditor.setVisibility(View.VISIBLE);
306 this.binding.mucDisplay.setVisibility(View.GONE);
307 this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_cancel, R.drawable.ic_cancel_black_24dp));
308 final String name = mucOptions.getName();
309 this.binding.mucEditTitle.setText("");
310 final boolean owner = mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER);
311 if (owner || printableValue(name)) {
312 this.binding.mucEditTitle.setVisibility(View.VISIBLE);
313 if (name != null) {
314 this.binding.mucEditTitle.append(name);
315 }
316 } else {
317 this.binding.mucEditTitle.setVisibility(View.GONE);
318 }
319 this.binding.mucEditTitle.setEnabled(owner);
320 final String subject = mucOptions.getSubject();
321 this.binding.mucEditSubject.setText("");
322 if (subject != null) {
323 this.binding.mucEditSubject.append(subject);
324 }
325 this.binding.mucEditSubject.setEnabled(mucOptions.canChangeSubject());
326 if (!owner) {
327 this.binding.mucEditSubject.requestFocus();
328 }
329 } else {
330 String subject = this.binding.mucEditSubject.isEnabled() ? this.binding.mucEditSubject.getEditableText().toString().trim() : null;
331 String name = this.binding.mucEditTitle.isEnabled() ? this.binding.mucEditTitle.getEditableText().toString().trim() : null;
332 onMucInfoUpdated(subject, name);
333 SoftKeyboardUtils.hideSoftKeyboard(this);
334 hideEditor();
335 }
336 }
337
338 private void hideEditor() {
339 this.binding.mucEditor.setVisibility(View.GONE);
340 this.binding.mucDisplay.setVisibility(View.VISIBLE);
341 this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_edit_body, R.drawable.ic_edit_black_24dp));
342 }
343
344 private void onMucInfoUpdated(String subject, String name) {
345 final MucOptions mucOptions = mConversation.getMucOptions();
346 if (mucOptions.canChangeSubject() && changed(mucOptions.getSubject(), subject)) {
347 xmppConnectionService.pushSubjectToConference(mConversation, subject);
348 }
349 if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && changed(mucOptions.getName(), name)) {
350 Bundle options = new Bundle();
351 options.putString("muc#roomconfig_persistentroom", "1");
352 options.putString("muc#roomconfig_roomname", StringUtils.nullOnEmpty(name));
353 xmppConnectionService.pushConferenceConfiguration(mConversation, options, this);
354 }
355 }
356
357
358 @Override
359 protected String getShareableUri(boolean http) {
360 if (mConversation != null) {
361 if (http) {
362 return "https://conversations.im/j/" + XmppUri.lameUrlEncode(mConversation.getJid().asBareJid().toEscapedString());
363 } else {
364 return "xmpp:" + mConversation.getJid().asBareJid() + "?join";
365 }
366 } else {
367 return null;
368 }
369 }
370
371 @Override
372 public boolean onPrepareOptionsMenu(Menu menu) {
373 MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
374 MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
375 MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
376 MenuItem menuItemDestroyRoom = menu.findItem(R.id.action_destroy_room);
377 menuItemAdvancedMode.setChecked(mAdvancedMode);
378 if (mConversation == null) {
379 return true;
380 }
381 if (mConversation.getBookmark() != null) {
382 menuItemSaveBookmark.setVisible(false);
383 menuItemDeleteBookmark.setVisible(true);
384 } else {
385 menuItemDeleteBookmark.setVisible(false);
386 menuItemSaveBookmark.setVisible(true);
387 }
388 menuItemDestroyRoom.setVisible(mConversation.getMucOptions().getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER));
389 return true;
390 }
391
392 @Override
393 public boolean onCreateOptionsMenu(Menu menu) {
394 getMenuInflater().inflate(R.menu.muc_details, menu);
395 AccountUtils.showHideMenuItems(menu);
396 return super.onCreateOptionsMenu(menu);
397 }
398
399 @Override
400 public void onMediaLoaded(List<Attachment> attachments) {
401 runOnUiThread(() -> {
402 int limit = GridManager.getCurrentColumnCount(binding.media);
403 mMediaAdapter.setAttachments(attachments.subList(0, Math.min(limit, attachments.size())));
404 binding.mediaWrapper.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
405 });
406
407 }
408
409
410 protected void saveAsBookmark() {
411 xmppConnectionService.saveConversationAsBookmark(mConversation, mConversation.getMucOptions().getName());
412 }
413
414 protected void deleteBookmark() {
415 Account account = mConversation.getAccount();
416 Bookmark bookmark = mConversation.getBookmark();
417 account.getBookmarks().remove(bookmark);
418 bookmark.setConversation(null);
419 xmppConnectionService.pushBookmarks(account);
420 updateView();
421 }
422
423 protected void destroyRoom() {
424 AlertDialog.Builder builder = new AlertDialog.Builder(this);
425 builder.setTitle(R.string.destroy_room);
426 builder.setMessage(R.string.destroy_room_dialog);
427 builder.setPositiveButton(R.string.ok, (dialog, which) -> {
428 xmppConnectionService.destroyRoom(mConversation, ConferenceDetailsActivity.this);
429 });
430 builder.setNegativeButton(R.string.cancel, null);
431 final AlertDialog dialog = builder.create();
432 dialog.setCanceledOnTouchOutside(false);
433 dialog.show();
434 }
435
436 @Override
437 void onBackendConnected() {
438 if (mPendingConferenceInvite != null) {
439 mPendingConferenceInvite.execute(this);
440 mPendingConferenceInvite = null;
441 }
442 if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
443 this.uuid = getIntent().getExtras().getString("uuid");
444 }
445 if (uuid != null) {
446 this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
447 if (this.mConversation != null) {
448 if (Compatibility.hasStoragePermission(this)) {
449 final int limit = GridManager.getCurrentColumnCount(this.binding.media);
450 xmppConnectionService.getAttachments(this.mConversation, limit, this);
451 this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, mConversation));
452 }
453 updateView();
454 }
455 }
456 }
457
458 @Override
459 public void onBackPressed() {
460 if (this.binding.mucEditor.getVisibility() == View.VISIBLE) {
461 hideEditor();
462 } else {
463 super.onBackPressed();
464 }
465 }
466
467 private void updateView() {
468 invalidateOptionsMenu();
469 final MucOptions mucOptions = mConversation.getMucOptions();
470 final User self = mucOptions.getSelf();
471 String account;
472 if (Config.DOMAIN_LOCK != null) {
473 account = mConversation.getAccount().getJid().getLocal();
474 } else {
475 account = mConversation.getAccount().getJid().asBareJid().toString();
476 }
477 setTitle(mucOptions.isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details);
478 this.binding.editMucNameButton.setVisibility((self.getAffiliation().ranks(MucOptions.Affiliation.OWNER) || mucOptions.canChangeSubject()) ? View.VISIBLE : View.GONE);
479 this.binding.detailsAccount.setText(getString(R.string.using_account, account));
480 this.binding.jid.setText(mConversation.getJid().asBareJid().toEscapedString());
481 AvatarWorkerTask.loadAvatar(mConversation, binding.yourPhoto, R.dimen.avatar_on_details_screen_size);
482 String roomName = mucOptions.getName();
483 String subject = mucOptions.getSubject();
484 final boolean hasTitle;
485 if (printableValue(roomName)) {
486 this.binding.mucTitle.setText(EmojiWrapper.transform(roomName));
487 this.binding.mucTitle.setVisibility(View.VISIBLE);
488 hasTitle = true;
489 } else if (!printableValue(subject)) {
490 this.binding.mucTitle.setText(EmojiWrapper.transform(mConversation.getName()));
491 hasTitle = true;
492 this.binding.mucTitle.setVisibility(View.VISIBLE);
493 } else {
494 hasTitle = false;
495 this.binding.mucTitle.setVisibility(View.GONE);
496 }
497 if (printableValue(subject)) {
498 SpannableStringBuilder spannable = new SpannableStringBuilder(subject);
499 StylingHelper.format(spannable, this.binding.mucSubject.getCurrentTextColor());
500 MyLinkify.addLinks(spannable, false);
501 this.binding.mucSubject.setText(EmojiWrapper.transform(spannable));
502 this.binding.mucSubject.setTextAppearance(this, subject.length() > (hasTitle ? 128 : 196) ? R.style.TextAppearance_Conversations_Body1_Linkified : R.style.TextAppearance_Conversations_Subhead);
503 this.binding.mucSubject.setAutoLinkMask(0);
504 this.binding.mucSubject.setVisibility(View.VISIBLE);
505 } else {
506 this.binding.mucSubject.setVisibility(View.GONE);
507 }
508 this.binding.mucYourNick.setText(mucOptions.getActualNick());
509 if (mucOptions.online()) {
510 this.binding.usersWrapper.setVisibility(View.VISIBLE);
511 this.binding.mucSettings.setVisibility(View.VISIBLE);
512 this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
513 this.binding.mucRole.setVisibility(View.VISIBLE);
514 this.binding.mucRole.setText(getStatus(self));
515 if (mucOptions.membersOnly()) {
516 this.binding.mucConferenceType.setText(R.string.private_conference);
517 } else {
518 this.binding.mucConferenceType.setText(R.string.public_conference);
519 }
520 if (mucOptions.mamSupport()) {
521 this.binding.mucInfoMam.setText(R.string.server_info_available);
522 } else {
523 this.binding.mucInfoMam.setText(R.string.server_info_unavailable);
524 }
525 if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
526 this.binding.changeConferenceButton.setVisibility(View.VISIBLE);
527 } else {
528 this.binding.changeConferenceButton.setVisibility(View.INVISIBLE);
529 }
530 } else {
531 this.binding.usersWrapper.setVisibility(View.GONE);
532 this.binding.mucInfoMore.setVisibility(View.GONE);
533 this.binding.mucSettings.setVisibility(View.GONE);
534 }
535
536 int ic_notifications = getThemeResource(R.attr.icon_notifications, R.drawable.ic_notifications_black_24dp);
537 int ic_notifications_off = getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black_24dp);
538 int ic_notifications_paused = getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black_24dp);
539 int ic_notifications_none = getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black_24dp);
540
541 long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
542 if (mutedTill == Long.MAX_VALUE) {
543 this.binding.notificationStatusText.setText(R.string.notify_never);
544 this.binding.notificationStatusButton.setImageResource(ic_notifications_off);
545 } else if (System.currentTimeMillis() < mutedTill) {
546 this.binding.notificationStatusText.setText(R.string.notify_paused);
547 this.binding.notificationStatusButton.setImageResource(ic_notifications_paused);
548 } else if (mConversation.alwaysNotify()) {
549 this.binding.notificationStatusText.setText(R.string.notify_on_all_messages);
550 this.binding.notificationStatusButton.setImageResource(ic_notifications);
551 } else {
552 this.binding.notificationStatusText.setText(R.string.notify_only_when_highlighted);
553 this.binding.notificationStatusButton.setImageResource(ic_notifications_none);
554 }
555 List<User> users = mucOptions.getUsers();
556 Collections.sort(users, (a, b) -> {
557 if (b.getAffiliation().outranks(a.getAffiliation())) {
558 return 1;
559 } else if (a.getAffiliation().outranks(b.getAffiliation())) {
560 return -1;
561 } else {
562 if (a.getAvatar() != null && b.getAvatar() == null) {
563 return -1;
564 } else if (a.getAvatar() == null && b.getAvatar() != null) {
565 return 1;
566 } else {
567 return a.getComparableName().compareToIgnoreCase(b.getComparableName());
568 }
569 }
570 });
571 this.mUserPreviewAdapter.submitList(MucOptions.sub(users, GridManager.getCurrentColumnCount(binding.users)));
572 this.binding.invite.setVisibility(mucOptions.canInvite() ? View.VISIBLE : View.GONE);
573
574 }
575
576 public static String getStatus(Context context, User user, final boolean advanced) {
577 if (advanced) {
578 return String.format("%s (%s)", context.getString(user.getAffiliation().getResId()), context.getString(user.getRole().getResId()));
579 } else {
580 return context.getString(user.getAffiliation().getResId());
581 }
582 }
583
584 private String getStatus(User user) {
585 return getStatus(this, user, mAdvancedMode);
586 }
587
588
589 @Override
590 public void onAffiliationChangedSuccessful(Jid jid) {
591 refreshUi();
592 }
593
594 @Override
595 public void onAffiliationChangeFailed(Jid jid, int resId) {
596 displayToast(getString(resId, jid.asBareJid().toString()));
597 }
598
599 @Override
600 public void onRoomDestroySucceeded() {
601 finish();
602 }
603
604 @Override
605 public void onRoomDestroyFailed() {
606 displayToast(getString(R.string.could_not_destroy_room));
607 }
608
609 @Override
610 public void onPushSucceeded() {
611 displayToast(getString(R.string.modified_conference_options));
612 }
613
614 @Override
615 public void onPushFailed() {
616 displayToast(getString(R.string.could_not_modify_conference_options));
617 }
618
619 private void displayToast(final String msg) {
620 runOnUiThread(() -> {
621 if (isFinishing()) {
622 return;
623 }
624 ToastCompat.makeText(this, msg, Toast.LENGTH_SHORT).show();
625 });
626 }
627
628 @Override
629 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
630
631 }
632
633 @Override
634 public void onTextChanged(CharSequence s, int start, int before, int count) {
635
636 }
637
638 @Override
639 public void afterTextChanged(Editable s) {
640 if (mConversation == null) {
641 return;
642 }
643 final MucOptions mucOptions = mConversation.getMucOptions();
644 if (this.binding.mucEditor.getVisibility() == View.VISIBLE) {
645 boolean subjectChanged = changed(binding.mucEditSubject.getEditableText().toString(), mucOptions.getSubject());
646 boolean nameChanged = changed(binding.mucEditTitle.getEditableText().toString(), mucOptions.getName());
647 if (subjectChanged || nameChanged) {
648 this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_save, R.drawable.ic_save_black_24dp));
649 } else {
650 this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_cancel, R.drawable.ic_cancel_black_24dp));
651 }
652 }
653 }
654
655}