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