ConferenceDetailsActivity.java

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