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