1package eu.siacs.conversations.ui;
2
3import android.Manifest;
4import android.annotation.SuppressLint;
5import android.app.Dialog;
6import android.app.PendingIntent;
7import android.content.ActivityNotFoundException;
8import android.content.Context;
9import android.content.DialogInterface;
10import android.content.Intent;
11import android.content.SharedPreferences;
12import android.content.pm.PackageManager;
13import android.databinding.DataBindingUtil;
14import android.net.Uri;
15import android.os.Build;
16import android.os.Bundle;
17import android.support.annotation.DrawableRes;
18import android.support.annotation.NonNull;
19import android.support.annotation.Nullable;
20import android.support.v4.app.Fragment;
21import android.support.v4.app.FragmentManager;
22import android.support.v4.app.FragmentTransaction;
23import android.support.v4.app.ListFragment;
24import android.support.v4.view.PagerAdapter;
25import android.support.v4.view.ViewPager;
26import android.support.v4.widget.SwipeRefreshLayout;
27import android.support.v7.app.ActionBar;
28import android.support.v7.app.AlertDialog;
29import android.support.v7.widget.Toolbar;
30import android.text.Editable;
31import android.text.Html;
32import android.text.SpannableString;
33import android.text.Spanned;
34import android.text.TextWatcher;
35import android.text.method.LinkMovementMethod;
36import android.text.util.Linkify;
37import android.util.Log;
38import android.util.Pair;
39import android.view.ContextMenu;
40import android.view.ContextMenu.ContextMenuInfo;
41import android.view.KeyEvent;
42import android.view.Menu;
43import android.view.MenuItem;
44import android.view.View;
45import android.view.ViewGroup;
46import android.view.inputmethod.InputMethodManager;
47import android.widget.AdapterView;
48import android.widget.AdapterView.AdapterContextMenuInfo;
49import android.widget.ArrayAdapter;
50import android.widget.AutoCompleteTextView;
51import android.widget.CheckBox;
52import android.widget.EditText;
53import android.widget.ListView;
54import android.widget.Spinner;
55import android.widget.TextView;
56import android.widget.Toast;
57
58import java.util.ArrayList;
59import java.util.Collections;
60import java.util.List;
61import java.util.concurrent.atomic.AtomicBoolean;
62
63import eu.siacs.conversations.Config;
64import eu.siacs.conversations.R;
65import eu.siacs.conversations.databinding.ActivityStartConversationBinding;
66import eu.siacs.conversations.entities.Account;
67import eu.siacs.conversations.entities.Bookmark;
68import eu.siacs.conversations.entities.Contact;
69import eu.siacs.conversations.entities.Conversation;
70import eu.siacs.conversations.entities.ListItem;
71import eu.siacs.conversations.entities.Presence;
72import eu.siacs.conversations.services.QuickConversationsService;
73import eu.siacs.conversations.services.XmppConnectionService;
74import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
75import eu.siacs.conversations.ui.adapter.ListItemAdapter;
76import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
77import eu.siacs.conversations.ui.service.EmojiService;
78import eu.siacs.conversations.ui.util.JidDialog;
79import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
80import eu.siacs.conversations.ui.util.PendingItem;
81import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
82import eu.siacs.conversations.ui.widget.SwipeRefreshListFragment;
83import eu.siacs.conversations.utils.AccountUtils;
84import eu.siacs.conversations.utils.XmppUri;
85import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
86import eu.siacs.conversations.xmpp.XmppConnection;
87import rocks.xmpp.addr.Jid;
88
89public class StartConversationActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, CreateConferenceDialog.CreateConferenceDialogListener, JoinConferenceDialog.JoinConferenceDialogListener, SwipeRefreshLayout.OnRefreshListener {
90
91 public static final String EXTRA_INVITE_URI = "eu.siacs.conversations.invite_uri";
92
93 private final int REQUEST_SYNC_CONTACTS = 0x28cf;
94 private final int REQUEST_CREATE_CONFERENCE = 0x39da;
95 private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
96 private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
97 private final AtomicBoolean oneShotKeyboardSuppress = new AtomicBoolean();
98 public int conference_context_id;
99 public int contact_context_id;
100 private ListPagerAdapter mListPagerAdapter;
101 private List<ListItem> contacts = new ArrayList<>();
102 private ListItemAdapter mContactsAdapter;
103 private List<ListItem> conferences = new ArrayList<>();
104 private ListItemAdapter mConferenceAdapter;
105 private List<String> mActivatedAccounts = new ArrayList<>();
106 private EditText mSearchEditText;
107 private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
108 private boolean mHideOfflineContacts = false;
109 private boolean createdByViewIntent = false;
110 private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
111
112 @Override
113 public boolean onMenuItemActionExpand(MenuItem item) {
114 mSearchEditText.post(() -> {
115 updateSearchViewHint();
116 mSearchEditText.requestFocus();
117 if (oneShotKeyboardSuppress.compareAndSet(true, false)) {
118 return;
119 }
120 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
121 if (imm != null) {
122 imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
123 }
124 });
125
126 return true;
127 }
128
129 @Override
130 public boolean onMenuItemActionCollapse(MenuItem item) {
131 SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
132 mSearchEditText.setText("");
133 filter(null);
134 return true;
135 }
136 };
137 private TextWatcher mSearchTextWatcher = new TextWatcher() {
138
139 @Override
140 public void afterTextChanged(Editable editable) {
141 filter(editable.toString());
142 }
143
144 @Override
145 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
146 }
147
148 @Override
149 public void onTextChanged(CharSequence s, int start, int before, int count) {
150 }
151 };
152 private MenuItem mMenuSearchView;
153 private ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() {
154 @Override
155 public void onTagClicked(String tag) {
156 if (mMenuSearchView != null) {
157 mMenuSearchView.expandActionView();
158 mSearchEditText.setText("");
159 mSearchEditText.append(tag);
160 filter(tag);
161 }
162 }
163 };
164 private Pair<Integer, Intent> mPostponedActivityResult;
165 private Toast mToast;
166 private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
167 @Override
168 public void success(final Conversation conversation) {
169 runOnUiThread(() -> {
170 hideToast();
171 switchToConversation(conversation);
172 });
173 }
174
175 @Override
176 public void error(final int errorCode, Conversation object) {
177 runOnUiThread(() -> replaceToast(getString(errorCode)));
178 }
179
180 @Override
181 public void userInputRequried(PendingIntent pi, Conversation object) {
182
183 }
184 };
185 private ActivityStartConversationBinding binding;
186 private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
187 @Override
188 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
189 int pos = binding.startConversationViewPager.getCurrentItem();
190 if (pos == 0) {
191 if (contacts.size() == 1) {
192 openConversationForContact((Contact) contacts.get(0));
193 return true;
194 } else if (contacts.size() == 0 && conferences.size() == 1) {
195 openConversationsForBookmark((Bookmark) conferences.get(0));
196 return true;
197 }
198 } else {
199 if (conferences.size() == 1) {
200 openConversationsForBookmark((Bookmark) conferences.get(0));
201 return true;
202 } else if (conferences.size() == 0 && contacts.size() == 1) {
203 openConversationForContact((Contact) contacts.get(0));
204 return true;
205 }
206 }
207 SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
208 mListPagerAdapter.requestFocus(pos);
209 return true;
210 }
211 };
212 private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
213 @Override
214 public void onPageSelected(int position) {
215 onTabChanged();
216 }
217 };
218
219 public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
220 if (accounts.size() > 0) {
221 ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.simple_list_item, accounts);
222 adapter.setDropDownViewResource(R.layout.simple_list_item);
223 spinner.setAdapter(adapter);
224 spinner.setEnabled(true);
225 } else {
226 ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
227 R.layout.simple_list_item,
228 Collections.singletonList(context.getString(R.string.no_accounts)));
229 adapter.setDropDownViewResource(R.layout.simple_list_item);
230 spinner.setAdapter(adapter);
231 spinner.setEnabled(false);
232 }
233 }
234
235 public static void launch(Context context) {
236 final Intent intent = new Intent(context, StartConversationActivity.class);
237 context.startActivity(intent);
238 }
239
240 private static Intent createLauncherIntent(Context context) {
241 final Intent intent = new Intent(context, StartConversationActivity.class);
242 intent.setAction(Intent.ACTION_MAIN);
243 intent.addCategory(Intent.CATEGORY_LAUNCHER);
244 return intent;
245 }
246
247 private static boolean isViewIntent(final Intent i) {
248 return i != null && (Intent.ACTION_VIEW.equals(i.getAction()) || Intent.ACTION_SENDTO.equals(i.getAction()) || i.hasExtra(EXTRA_INVITE_URI));
249 }
250
251 protected void hideToast() {
252 if (mToast != null) {
253 mToast.cancel();
254 }
255 }
256
257 protected void replaceToast(String msg) {
258 hideToast();
259 mToast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
260 mToast.show();
261 }
262
263 @Override
264 public void onRosterUpdate() {
265 this.refreshUi();
266 }
267
268 @Override
269 public void onCreate(Bundle savedInstanceState) {
270 super.onCreate(savedInstanceState);
271 new EmojiService(this).init();
272 this.binding = DataBindingUtil.setContentView(this, R.layout.activity_start_conversation);
273 Toolbar toolbar = (Toolbar) binding.toolbar;
274 setSupportActionBar(toolbar);
275 configureActionBar(getSupportActionBar());
276 this.binding.fab.setOnClickListener((v) -> {
277 if (binding.startConversationViewPager.getCurrentItem() == 0) {
278 String searchString = mSearchEditText != null ? mSearchEditText.getText().toString() : null;
279 if (searchString != null && !searchString.trim().isEmpty()) {
280 try {
281 Jid jid = Jid.of(searchString);
282 if (jid.getLocal() != null && jid.isBareJid() && jid.getDomain().contains(".")) {
283 showCreateContactDialog(jid.toString(), null);
284 return;
285 }
286 } catch (IllegalArgumentException ignored) {
287 //ignore and fall through
288 }
289 }
290 showCreateContactDialog(null, null);
291 } else {
292 showCreateConferenceDialog();
293 }
294 });
295 binding.tabLayout.setupWithViewPager(binding.startConversationViewPager);
296 binding.startConversationViewPager.addOnPageChangeListener(mOnPageChangeListener);
297 mListPagerAdapter = new ListPagerAdapter(getSupportFragmentManager());
298 binding.startConversationViewPager.setAdapter(mListPagerAdapter);
299
300 mConferenceAdapter = new ListItemAdapter(this, conferences);
301 mContactsAdapter = new ListItemAdapter(this, contacts);
302 mContactsAdapter.setOnTagClickedListener(this.mOnTagClickedListener);
303
304 final SharedPreferences preferences = getPreferences();
305
306 this.mHideOfflineContacts = QuickConversationsService.isConversations() && preferences.getBoolean("hide_offline", false);
307
308 final boolean startSearching = preferences.getBoolean("start_searching",getResources().getBoolean(R.bool.start_searching));
309
310 final Intent intent;
311 if (savedInstanceState == null) {
312 intent = getIntent();
313 } else {
314 createdByViewIntent = savedInstanceState.getBoolean("created_by_view_intent", false);
315 final String search = savedInstanceState.getString("search");
316 if (search != null) {
317 mInitialSearchValue.push(search);
318 }
319 intent = savedInstanceState.getParcelable("intent");
320 }
321
322 if (isViewIntent(intent)) {
323 pendingViewIntent.push(intent);
324 createdByViewIntent = true;
325 setIntent(createLauncherIntent(this));
326 } else if (startSearching && mInitialSearchValue.peek() == null) {
327 mInitialSearchValue.push("");
328 }
329 mRequestedContactsPermission.set(savedInstanceState != null && savedInstanceState.getBoolean("requested_contacts_permission",false));
330 }
331
332 @Override
333 public void onSaveInstanceState(Bundle savedInstanceState) {
334 Intent pendingIntent = pendingViewIntent.peek();
335 savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
336 savedInstanceState.putBoolean("requested_contacts_permission",mRequestedContactsPermission.get());
337 savedInstanceState.putBoolean("created_by_view_intent",createdByViewIntent);
338 if (mMenuSearchView != null && mMenuSearchView.isActionViewExpanded()) {
339 savedInstanceState.putString("search", mSearchEditText != null ? mSearchEditText.getText().toString() : null);
340 }
341 super.onSaveInstanceState(savedInstanceState);
342 }
343
344 @Override
345 public void onStart() {
346 super.onStart();
347 final int theme = findTheme();
348 if (this.mTheme != theme) {
349 recreate();
350 } else {
351 if (pendingViewIntent.peek() == null) {
352 askForContactsPermissions();
353 }
354 }
355 mConferenceAdapter.refreshSettings();
356 mContactsAdapter.refreshSettings();
357 }
358
359 @Override
360 public void onNewIntent(final Intent intent) {
361 if (xmppConnectionServiceBound) {
362 processViewIntent(intent);
363 } else {
364 pendingViewIntent.push(intent);
365 }
366 setIntent(createLauncherIntent(this));
367 }
368
369 protected void openConversationForContact(int position) {
370 Contact contact = (Contact) contacts.get(position);
371 openConversationForContact(contact);
372 }
373
374 protected void openConversationForContact(Contact contact) {
375 Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
376 SoftKeyboardUtils.hideSoftKeyboard(this);
377 switchToConversation(conversation);
378 }
379
380 protected void openConversationForBookmark() {
381 openConversationForBookmark(conference_context_id);
382 }
383
384 protected void openConversationForBookmark(int position) {
385 Bookmark bookmark = (Bookmark) conferences.get(position);
386 openConversationsForBookmark(bookmark);
387 }
388
389 protected void shareBookmarkUri() {
390 shareBookmarkUri(conference_context_id);
391 }
392
393 protected void shareBookmarkUri(int position) {
394 Bookmark bookmark = (Bookmark) conferences.get(position);
395 Intent shareIntent = new Intent();
396 shareIntent.setAction(Intent.ACTION_SEND);
397 shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toEscapedString() + "?join");
398 shareIntent.setType("text/plain");
399 try {
400 startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
401 } catch (ActivityNotFoundException e) {
402 Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
403 }
404 }
405
406 protected void openConversationsForBookmark(Bookmark bookmark) {
407 final Jid jid = bookmark.getFullJid();
408 if (jid == null) {
409 Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
410 return;
411 }
412 Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
413 bookmark.setConversation(conversation);
414 if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))) {
415 bookmark.setAutojoin(true);
416 xmppConnectionService.pushBookmarks(bookmark.getAccount());
417 }
418 SoftKeyboardUtils.hideSoftKeyboard(this);
419 switchToConversation(conversation);
420 }
421
422 protected void openDetailsForContact() {
423 int position = contact_context_id;
424 Contact contact = (Contact) contacts.get(position);
425 switchToContactDetails(contact);
426 }
427
428 protected void showQrForContact() {
429 int position = contact_context_id;
430 Contact contact = (Contact) contacts.get(position);
431 showQrCode("xmpp:"+contact.getJid().asBareJid().toEscapedString());
432 }
433
434 protected void toggleContactBlock() {
435 final int position = contact_context_id;
436 BlockContactDialog.show(this, (Contact) contacts.get(position));
437 }
438
439 protected void deleteContact() {
440 final int position = contact_context_id;
441 final Contact contact = (Contact) contacts.get(position);
442 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
443 builder.setNegativeButton(R.string.cancel, null);
444 builder.setTitle(R.string.action_delete_contact);
445 builder.setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()));
446 builder.setPositiveButton(R.string.delete, (dialog, which) -> {
447 xmppConnectionService.deleteContactOnServer(contact);
448 filter(mSearchEditText.getText().toString());
449 });
450 builder.create().show();
451 }
452
453 protected void deleteConference() {
454 int position = conference_context_id;
455 final Bookmark bookmark = (Bookmark) conferences.get(position);
456
457 AlertDialog.Builder builder = new AlertDialog.Builder(this);
458 builder.setNegativeButton(R.string.cancel, null);
459 builder.setTitle(R.string.delete_bookmark);
460 builder.setMessage(JidDialog.style(this, R.string.remove_bookmark_text, bookmark.getJid().toEscapedString()));
461 builder.setPositiveButton(R.string.delete, (dialog, which) -> {
462 bookmark.setConversation(null);
463 Account account = bookmark.getAccount();
464 account.getBookmarks().remove(bookmark);
465 xmppConnectionService.pushBookmarks(account);
466 filter(mSearchEditText.getText().toString());
467 });
468 builder.create().show();
469
470 }
471
472 @SuppressLint("InflateParams")
473 protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
474 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
475 Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
476 if (prev != null) {
477 ft.remove(prev);
478 }
479 ft.addToBackStack(null);
480 EnterJidDialog dialog = EnterJidDialog.newInstance(
481 mActivatedAccounts,
482 getString(R.string.dialog_title_create_contact),
483 getString(R.string.create),
484 prefilledJid,
485 null,
486 invite == null || !invite.hasFingerprints()
487 );
488
489 dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
490 if (!xmppConnectionServiceBound) {
491 return false;
492 }
493
494 final Account account = xmppConnectionService.findAccountByJid(accountJid);
495 if (account == null) {
496 return true;
497 }
498
499 final Contact contact = account.getRoster().getContact(contactJid);
500 if (invite != null && invite.getName() != null) {
501 contact.setServerName(invite.getName());
502 }
503 if (contact.isSelf()) {
504 switchToConversation(contact);
505 return true;
506 } else if (contact.showInRoster()) {
507 throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
508 } else {
509 xmppConnectionService.createContact(contact, true);
510 if (invite != null && invite.hasFingerprints()) {
511 xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
512 }
513 switchToConversationDoNotAppend(contact, invite == null ? null : invite.getBody());
514 return true;
515 }
516 });
517 dialog.show(ft, FRAGMENT_TAG_DIALOG);
518 }
519
520 @SuppressLint("InflateParams")
521 protected void showJoinConferenceDialog(final String prefilledJid) {
522 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
523 Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
524 if (prev != null) {
525 ft.remove(prev);
526 }
527 ft.addToBackStack(null);
528 JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts);
529 joinConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
530 }
531
532 private void showCreateConferenceDialog() {
533 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
534 Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
535 if (prev != null) {
536 ft.remove(prev);
537 }
538 ft.addToBackStack(null);
539 CreateConferenceDialog createConferenceFragment = CreateConferenceDialog.newInstance(mActivatedAccounts);
540 createConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
541 }
542
543 private Account getSelectedAccount(Spinner spinner) {
544 if (!spinner.isEnabled()) {
545 return null;
546 }
547 Jid jid;
548 try {
549 if (Config.DOMAIN_LOCK != null) {
550 jid = Jid.of((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
551 } else {
552 jid = Jid.of((String) spinner.getSelectedItem());
553 }
554 } catch (final IllegalArgumentException e) {
555 return null;
556 }
557 return xmppConnectionService.findAccountByJid(jid);
558 }
559
560 protected void switchToConversation(Contact contact) {
561 Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
562 switchToConversation(conversation);
563 }
564
565 protected void switchToConversationDoNotAppend(Contact contact, String body) {
566 Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
567 switchToConversationDoNotAppend(conversation, body);
568 }
569
570 @Override
571 public void invalidateOptionsMenu() {
572 boolean isExpanded = mMenuSearchView != null && mMenuSearchView.isActionViewExpanded();
573 String text = mSearchEditText != null ? mSearchEditText.getText().toString() : "";
574 if (isExpanded) {
575 mInitialSearchValue.push(text);
576 oneShotKeyboardSuppress.set(true);
577 }
578 super.invalidateOptionsMenu();
579 }
580
581 private void updateSearchViewHint() {
582 if (binding == null || mSearchEditText == null) {
583 return;
584 }
585 if (binding.startConversationViewPager.getCurrentItem() == 0) {
586 mSearchEditText.setHint(R.string.search_contacts);
587 } else {
588 mSearchEditText.setHint(R.string.search_groups);
589 }
590 }
591
592 @Override
593 public boolean onCreateOptionsMenu(Menu menu) {
594 getMenuInflater().inflate(R.menu.start_conversation, menu);
595 AccountUtils.showHideMenuItems(menu);
596 MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
597 MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference);
598 MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
599 joinGroupChat.setVisible(binding.startConversationViewPager.getCurrentItem() == 1);
600 qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable());
601 if (QuickConversationsService.isQuicksy()) {
602 menuHideOffline.setVisible(false);
603 } else {
604 menuHideOffline.setVisible(true);
605 menuHideOffline.setChecked(this.mHideOfflineContacts);
606 }
607 mMenuSearchView = menu.findItem(R.id.action_search);
608 mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
609 View mSearchView = mMenuSearchView.getActionView();
610 mSearchEditText = mSearchView.findViewById(R.id.search_field);
611 mSearchEditText.addTextChangedListener(mSearchTextWatcher);
612 mSearchEditText.setOnEditorActionListener(mSearchDone);
613 String initialSearchValue = mInitialSearchValue.pop();
614 if (initialSearchValue != null) {
615 mMenuSearchView.expandActionView();
616 mSearchEditText.append(initialSearchValue);
617 filter(initialSearchValue);
618 }
619 updateSearchViewHint();
620 return super.onCreateOptionsMenu(menu);
621 }
622
623 @Override
624 public boolean onOptionsItemSelected(MenuItem item) {
625 if (MenuDoubleTabUtil.shouldIgnoreTap()) {
626 return false;
627 }
628 switch (item.getItemId()) {
629 case android.R.id.home:
630 navigateBack();
631 return true;
632 case R.id.action_join_conference:
633 showJoinConferenceDialog(null);
634 return true;
635 case R.id.action_scan_qr_code:
636 UriHandlerActivity.scan(this);
637 return true;
638 case R.id.action_hide_offline:
639 mHideOfflineContacts = !item.isChecked();
640 getPreferences().edit().putBoolean("hide_offline", mHideOfflineContacts).apply();
641 if (mSearchEditText != null) {
642 filter(mSearchEditText.getText().toString());
643 }
644 invalidateOptionsMenu();
645 }
646 return super.onOptionsItemSelected(item);
647 }
648
649 @Override
650 public boolean onKeyUp(int keyCode, KeyEvent event) {
651 if (keyCode == KeyEvent.KEYCODE_SEARCH && !event.isLongPress()) {
652 openSearch();
653 return true;
654 }
655 int c = event.getUnicodeChar();
656 if (c > 32) {
657 if (mSearchEditText != null && !mSearchEditText.isFocused()) {
658 openSearch();
659 mSearchEditText.append(Character.toString((char) c));
660 return true;
661 }
662 }
663 return super.onKeyUp(keyCode, event);
664 }
665
666 private void openSearch() {
667 if (mMenuSearchView != null) {
668 mMenuSearchView.expandActionView();
669 }
670 }
671
672 @Override
673 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
674 if (resultCode == RESULT_OK) {
675 if (xmppConnectionServiceBound) {
676 this.mPostponedActivityResult = null;
677 if (requestCode == REQUEST_CREATE_CONFERENCE) {
678 Account account = extractAccount(intent);
679 final String name = intent.getStringExtra(ChooseContactActivity.EXTRA_GROUP_CHAT_NAME);
680 final List<Jid> jids = ChooseContactActivity.extractJabberIds(intent);
681 if (account != null && jids.size() > 0) {
682 if (xmppConnectionService.createAdhocConference(account, name, jids, mAdhocConferenceCallback)) {
683 mToast = Toast.makeText(this, R.string.creating_conference, Toast.LENGTH_LONG);
684 mToast.show();
685 }
686 }
687 }
688 } else {
689 this.mPostponedActivityResult = new Pair<>(requestCode, intent);
690 }
691 }
692 super.onActivityResult(requestCode, requestCode, intent);
693 }
694
695 private void askForContactsPermissions() {
696 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
697 if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
698 if (mRequestedContactsPermission.compareAndSet(false, true)) {
699 if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
700 AlertDialog.Builder builder = new AlertDialog.Builder(this);
701 builder.setTitle(R.string.sync_with_contacts);
702 if (QuickConversationsService.isQuicksy()) {
703 builder.setMessage(Html.fromHtml(getString(R.string.sync_with_contacts_quicksy)));
704 } else {
705 builder.setMessage(R.string.sync_with_contacts_long);
706 }
707 builder.setPositiveButton(R.string.next, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS));
708 builder.setOnDismissListener(dialog -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS));
709 builder.setCancelable(false);
710 AlertDialog dialog = builder.create();
711 dialog.setCanceledOnTouchOutside(false);
712 dialog.setOnShowListener(dialogInterface -> {
713 final TextView tv = dialog.findViewById(android.R.id.message);
714 if (tv != null) {
715 tv.setMovementMethod(LinkMovementMethod.getInstance());
716 }
717 });
718 dialog.show();
719 } else {
720 requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
721 }
722 }
723 }
724 }
725 }
726
727 @Override
728 public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
729 if (grantResults.length > 0)
730 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
731 ScanActivity.onRequestPermissionResult(this, requestCode, grantResults);
732 if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
733 if (QuickConversationsService.isQuicksy()) {
734 setRefreshing(true);
735 }
736 xmppConnectionService.loadPhoneContacts();
737 xmppConnectionService.startContactObserver();
738 }
739 }
740 }
741
742 private void configureHomeButton() {
743 final ActionBar actionBar = getSupportActionBar();
744 if (actionBar == null) {
745 return;
746 }
747 boolean openConversations = !createdByViewIntent && !xmppConnectionService.isConversationsListEmpty(null);
748 actionBar.setDisplayHomeAsUpEnabled(openConversations);
749 actionBar.setDisplayHomeAsUpEnabled(openConversations);
750
751 }
752
753 @Override
754 protected void onBackendConnected() {
755
756 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
757 xmppConnectionService.getQuickConversationsService().considerSyncBackground(false);
758 }
759 if (mPostponedActivityResult != null) {
760 onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
761 this.mPostponedActivityResult = null;
762 }
763 this.mActivatedAccounts.clear();
764 for (Account account : xmppConnectionService.getAccounts()) {
765 if (account.getStatus() != Account.State.DISABLED) {
766 if (Config.DOMAIN_LOCK != null) {
767 this.mActivatedAccounts.add(account.getJid().getLocal());
768 } else {
769 this.mActivatedAccounts.add(account.getJid().asBareJid().toString());
770 }
771 }
772 }
773 configureHomeButton();
774 Intent intent = pendingViewIntent.pop();
775 if (intent != null && processViewIntent(intent)) {
776 filter(null);
777 } else {
778 if (mSearchEditText != null) {
779 filter(mSearchEditText.getText().toString());
780 } else {
781 filter(null);
782 }
783 }
784 Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
785 if (fragment instanceof OnBackendConnected) {
786 Log.d(Config.LOGTAG, "calling on backend connected on dialog");
787 ((OnBackendConnected) fragment).onBackendConnected();
788 }
789 if (QuickConversationsService.isQuicksy()) {
790 setRefreshing(xmppConnectionService.getQuickConversationsService().isSynchronizing());
791 }
792 }
793
794 protected boolean processViewIntent(@NonNull Intent intent) {
795 final String inviteUri = intent.getStringExtra(EXTRA_INVITE_URI);
796 if (inviteUri != null) {
797 Invite invite = new Invite(inviteUri);
798 if (invite.isJidValid()) {
799 return invite.invite();
800 }
801 }
802 final String action = intent.getAction();
803 if (action == null) {
804 return false;
805 }
806 switch (action) {
807 case Intent.ACTION_SENDTO:
808 case Intent.ACTION_VIEW:
809 Uri uri = intent.getData();
810 if (uri != null) {
811 Invite invite = new Invite(intent.getData(), intent.getBooleanExtra("scanned", false));
812 invite.account = intent.getStringExtra("account");
813 return invite.invite();
814 } else {
815 return false;
816 }
817 }
818 return false;
819 }
820
821 private boolean handleJid(Invite invite) {
822 List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
823 if (invite.isAction(XmppUri.ACTION_JOIN)) {
824 Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
825 if (muc != null) {
826 switchToConversationDoNotAppend(muc, invite.getBody());
827 return true;
828 } else {
829 showJoinConferenceDialog(invite.getJid().asBareJid().toString());
830 return false;
831 }
832 } else if (contacts.size() == 0) {
833 showCreateContactDialog(invite.getJid().toString(), invite);
834 return false;
835 } else if (contacts.size() == 1) {
836 Contact contact = contacts.get(0);
837 if (!invite.isSafeSource() && invite.hasFingerprints()) {
838 displayVerificationWarningDialog(contact, invite);
839 } else {
840 if (invite.hasFingerprints()) {
841 if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
842 Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
843 }
844 }
845 if (invite.account != null) {
846 xmppConnectionService.getShortcutService().report(contact);
847 }
848 switchToConversationDoNotAppend(contact, invite.getBody());
849 }
850 return true;
851 } else {
852 if (mMenuSearchView != null) {
853 mMenuSearchView.expandActionView();
854 mSearchEditText.setText("");
855 mSearchEditText.append(invite.getJid().toString());
856 filter(invite.getJid().toString());
857 } else {
858 mInitialSearchValue.push(invite.getJid().toString());
859 }
860 return true;
861 }
862 }
863
864 private void displayVerificationWarningDialog(final Contact contact, final Invite invite) {
865 AlertDialog.Builder builder = new AlertDialog.Builder(this);
866 builder.setTitle(R.string.verify_omemo_keys);
867 View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null);
868 final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source);
869 TextView warning = view.findViewById(R.id.warning);
870 warning.setText(JidDialog.style(this, R.string.verifying_omemo_keys_trusted_source, contact.getJid().asBareJid().toEscapedString(), contact.getDisplayName()));
871 builder.setView(view);
872 builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
873 if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
874 xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
875 }
876 switchToConversationDoNotAppend(contact, invite.getBody());
877 });
878 builder.setNegativeButton(R.string.cancel, (dialog, which) -> StartConversationActivity.this.finish());
879 AlertDialog dialog = builder.create();
880 dialog.setCanceledOnTouchOutside(false);
881 dialog.setOnCancelListener(dialog1 -> StartConversationActivity.this.finish());
882 dialog.show();
883 }
884
885 protected void filter(String needle) {
886 if (xmppConnectionServiceBound) {
887 this.filterContacts(needle);
888 this.filterConferences(needle);
889 }
890 }
891
892 protected void filterContacts(String needle) {
893 this.contacts.clear();
894 final List<Account> accounts = xmppConnectionService.getAccounts();
895 for (Account account : accounts) {
896 if (account.getStatus() != Account.State.DISABLED) {
897 for (Contact contact : account.getRoster().getContacts()) {
898 Presence.Status s = contact.getShownStatus();
899 if (contact.showInContactList() && contact.match(this, needle)
900 && (!this.mHideOfflineContacts
901 || (needle != null && !needle.trim().isEmpty())
902 || s.compareTo(Presence.Status.OFFLINE) < 0)) {
903 this.contacts.add(contact);
904 }
905 }
906 }
907 }
908 Collections.sort(this.contacts);
909 mContactsAdapter.notifyDataSetChanged();
910 }
911
912 protected void filterConferences(String needle) {
913 this.conferences.clear();
914 for (Account account : xmppConnectionService.getAccounts()) {
915 if (account.getStatus() != Account.State.DISABLED) {
916 for (Bookmark bookmark : account.getBookmarks()) {
917 if (bookmark.match(this, needle)) {
918 this.conferences.add(bookmark);
919 }
920 }
921 }
922 }
923 Collections.sort(this.conferences);
924 mConferenceAdapter.notifyDataSetChanged();
925 }
926
927 private void onTabChanged() {
928 @DrawableRes final int fabDrawable;
929 if (binding.startConversationViewPager.getCurrentItem() == 0) {
930 fabDrawable = R.drawable.ic_person_add_white_24dp;
931 } else {
932 fabDrawable = R.drawable.ic_group_add_white_24dp;
933 }
934 binding.fab.setImageResource(fabDrawable);
935 invalidateOptionsMenu();
936 }
937
938 @Override
939 public void OnUpdateBlocklist(final Status status) {
940 refreshUi();
941 }
942
943 @Override
944 protected void refreshUiReal() {
945 if (mSearchEditText != null) {
946 filter(mSearchEditText.getText().toString());
947 }
948 configureHomeButton();
949 if (QuickConversationsService.isQuicksy()) {
950 setRefreshing(xmppConnectionService.getQuickConversationsService().isSynchronizing());
951 }
952 }
953
954 @Override
955 public void onBackPressed() {
956 navigateBack();
957 }
958
959 private void navigateBack() {
960 if (!createdByViewIntent && xmppConnectionService != null && !xmppConnectionService.isConversationsListEmpty(null)) {
961 Intent intent = new Intent(this, ConversationsActivity.class);
962 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
963 startActivity(intent);
964 }
965 finish();
966 }
967
968 @Override
969 public void onCreateDialogPositiveClick(Spinner spinner, String name) {
970 if (!xmppConnectionServiceBound) {
971 return;
972 }
973 final Account account = getSelectedAccount(spinner);
974 if (account == null) {
975 return;
976 }
977 Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
978 intent.putExtra(ChooseContactActivity.EXTRA_SHOW_ENTER_JID, false);
979 intent.putExtra(ChooseContactActivity.EXTRA_SELECT_MULTIPLE, true);
980 intent.putExtra(ChooseContactActivity.EXTRA_GROUP_CHAT_NAME, name.trim());
981 intent.putExtra(ChooseContactActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toString());
982 intent.putExtra(ChooseContactActivity.EXTRA_TITLE_RES_ID, R.string.choose_participants);
983 startActivityForResult(intent, REQUEST_CREATE_CONFERENCE);
984 }
985
986 @Override
987 public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked) {
988 if (!xmppConnectionServiceBound) {
989 return;
990 }
991 final Account account = getSelectedAccount(spinner);
992 if (account == null) {
993 return;
994 }
995 final Jid conferenceJid;
996 try {
997 conferenceJid = Jid.of(jid.getText().toString());
998 } catch (final IllegalArgumentException e) {
999 jid.setError(getString(R.string.invalid_jid));
1000 return;
1001 }
1002
1003 if (isBookmarkChecked) {
1004 if (account.hasBookmarkFor(conferenceJid)) {
1005 jid.setError(getString(R.string.bookmark_already_exists));
1006 } else {
1007 final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid());
1008 bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin));
1009 String nick = conferenceJid.getResource();
1010 if (nick != null && !nick.isEmpty()) {
1011 bookmark.setNick(nick);
1012 }
1013 account.getBookmarks().add(bookmark);
1014 xmppConnectionService.pushBookmarks(account);
1015 final Conversation conversation = xmppConnectionService
1016 .findOrCreateConversation(account, conferenceJid, true, true, true);
1017 bookmark.setConversation(conversation);
1018 dialog.dismiss();
1019 switchToConversation(conversation);
1020 }
1021 } else {
1022 final Conversation conversation = xmppConnectionService
1023 .findOrCreateConversation(account, conferenceJid, true, true, true);
1024 dialog.dismiss();
1025 switchToConversation(conversation);
1026 }
1027 }
1028
1029 @Override
1030 public void onConversationUpdate() {
1031 refreshUi();
1032 }
1033
1034 @Override
1035 public void onRefresh() {
1036 Log.d(Config.LOGTAG,"user requested to refresh");
1037 if (QuickConversationsService.isQuicksy() && xmppConnectionService != null) {
1038 xmppConnectionService.getQuickConversationsService().considerSyncBackground(true);
1039 }
1040 }
1041
1042
1043 private void setRefreshing(boolean refreshing) {
1044 MyListFragment fragment = (MyListFragment) mListPagerAdapter.getItem(0);
1045 if (fragment != null) {
1046 fragment.setRefreshing(refreshing);
1047 }
1048 }
1049
1050 public static class MyListFragment extends SwipeRefreshListFragment {
1051 private AdapterView.OnItemClickListener mOnItemClickListener;
1052 private int mResContextMenu;
1053
1054 public void setContextMenu(final int res) {
1055 this.mResContextMenu = res;
1056 }
1057
1058 @Override
1059 public void onListItemClick(final ListView l, final View v, final int position, final long id) {
1060 if (mOnItemClickListener != null) {
1061 mOnItemClickListener.onItemClick(l, v, position, id);
1062 }
1063 }
1064
1065 public void setOnListItemClickListener(AdapterView.OnItemClickListener l) {
1066 this.mOnItemClickListener = l;
1067 }
1068
1069 @Override
1070 public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) {
1071 super.onViewCreated(view, savedInstanceState);
1072 registerForContextMenu(getListView());
1073 getListView().setFastScrollEnabled(true);
1074 getListView().setDivider(null);
1075 getListView().setDividerHeight(0);
1076 }
1077
1078 @Override
1079 public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
1080 super.onCreateContextMenu(menu, v, menuInfo);
1081 final StartConversationActivity activity = (StartConversationActivity) getActivity();
1082 if (activity == null) {
1083 return;
1084 }
1085 activity.getMenuInflater().inflate(mResContextMenu, menu);
1086 final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
1087 if (mResContextMenu == R.menu.conference_context) {
1088 activity.conference_context_id = acmi.position;
1089 } else if (mResContextMenu == R.menu.contact_context) {
1090 activity.contact_context_id = acmi.position;
1091 final Contact contact = (Contact) activity.contacts.get(acmi.position);
1092 final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
1093 final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
1094 final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
1095 if (contact.isSelf()) {
1096 showContactDetailsItem.setVisible(false);
1097 }
1098 deleteContactMenuItem.setVisible(contact.showInRoster() && !contact.getOption(Contact.Options.SYNCED_VIA_OTHER));
1099 XmppConnection xmpp = contact.getAccount().getXmppConnection();
1100 if (xmpp != null && xmpp.getFeatures().blocking() && !contact.isSelf()) {
1101 if (contact.isBlocked()) {
1102 blockUnblockItem.setTitle(R.string.unblock_contact);
1103 } else {
1104 blockUnblockItem.setTitle(R.string.block_contact);
1105 }
1106 } else {
1107 blockUnblockItem.setVisible(false);
1108 }
1109 }
1110 }
1111
1112 @Override
1113 public boolean onContextItemSelected(final MenuItem item) {
1114 StartConversationActivity activity = (StartConversationActivity) getActivity();
1115 if (activity == null) {
1116 return true;
1117 }
1118 switch (item.getItemId()) {
1119 case R.id.context_contact_details:
1120 activity.openDetailsForContact();
1121 break;
1122 case R.id.context_show_qr:
1123 activity.showQrForContact();
1124 break;
1125 case R.id.context_contact_block_unblock:
1126 activity.toggleContactBlock();
1127 break;
1128 case R.id.context_delete_contact:
1129 activity.deleteContact();
1130 break;
1131 case R.id.context_join_conference:
1132 activity.openConversationForBookmark();
1133 break;
1134 case R.id.context_share_uri:
1135 activity.shareBookmarkUri();
1136 break;
1137 case R.id.context_delete_conference:
1138 activity.deleteConference();
1139 }
1140 return true;
1141 }
1142 }
1143
1144 public class ListPagerAdapter extends PagerAdapter {
1145 private final FragmentManager fragmentManager;
1146 private final MyListFragment[] fragments;
1147
1148 ListPagerAdapter(FragmentManager fm) {
1149 fragmentManager = fm;
1150 fragments = new MyListFragment[2];
1151 }
1152
1153 public void requestFocus(int pos) {
1154 if (fragments.length > pos) {
1155 fragments[pos].getListView().requestFocus();
1156 }
1157 }
1158
1159 @Override
1160 public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
1161 FragmentTransaction trans = fragmentManager.beginTransaction();
1162 trans.remove(fragments[position]);
1163 trans.commit();
1164 fragments[position] = null;
1165 }
1166
1167 @NonNull
1168 @Override
1169 public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
1170 final Fragment fragment = getItem(position);
1171 final FragmentTransaction trans = fragmentManager.beginTransaction();
1172 trans.add(container.getId(), fragment, "fragment:" + position);
1173 try {
1174 trans.commit();
1175 } catch (IllegalStateException e) {
1176 //ignore
1177 }
1178 return fragment;
1179 }
1180
1181 @Override
1182 public int getCount() {
1183 return fragments.length;
1184 }
1185
1186 @Override
1187 public boolean isViewFromObject(@NonNull View view, @NonNull Object fragment) {
1188 return ((Fragment) fragment).getView() == view;
1189 }
1190
1191 @Nullable
1192 @Override
1193 public CharSequence getPageTitle(int position) {
1194 switch (position) {
1195 case 0:
1196 return getResources().getString(R.string.contacts);
1197 case 1:
1198 return getResources().getString(R.string.conferences);
1199 default:
1200 return super.getPageTitle(position);
1201 }
1202 }
1203
1204 Fragment getItem(int position) {
1205 if (fragments[position] == null) {
1206 final MyListFragment listFragment = new MyListFragment();
1207 if (position == 1) {
1208 listFragment.setListAdapter(mConferenceAdapter);
1209 listFragment.setContextMenu(R.menu.conference_context);
1210 listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
1211 } else {
1212 listFragment.setListAdapter(mContactsAdapter);
1213 listFragment.setContextMenu(R.menu.contact_context);
1214 listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
1215 if (QuickConversationsService.isQuicksy()) {
1216 listFragment.setOnRefreshListener(StartConversationActivity.this);
1217 }
1218 }
1219 fragments[position] = listFragment;
1220 }
1221 return fragments[position];
1222 }
1223 }
1224
1225 public static void addInviteUri(Intent to, Intent from) {
1226 if (from != null && from.hasExtra(EXTRA_INVITE_URI)) {
1227 to.putExtra(EXTRA_INVITE_URI, from.getStringExtra(EXTRA_INVITE_URI));
1228 }
1229 }
1230
1231 private class Invite extends XmppUri {
1232
1233 public String account;
1234
1235 public Invite(final Uri uri) {
1236 super(uri);
1237 }
1238
1239 public Invite(final String uri) {
1240 super(uri);
1241 }
1242
1243 public Invite(Uri uri, boolean safeSource) {
1244 super(uri, safeSource);
1245 }
1246
1247 boolean invite() {
1248 if (!isJidValid()) {
1249 Toast.makeText(StartConversationActivity.this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
1250 return false;
1251 }
1252 if (getJid() != null) {
1253 return handleJid(this);
1254 }
1255 return false;
1256 }
1257 }
1258}