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