2014-06-30 18:39:15 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2015-12-06 23:33:50 +00:00
|
|
|
import android.Manifest;
|
2014-09-27 09:46:56 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2016-08-31 15:04:43 +00:00
|
|
|
import android.app.Dialog;
|
2016-05-26 20:53:55 +00:00
|
|
|
import android.app.PendingIntent;
|
2017-01-24 23:15:50 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2014-07-07 07:32:10 +00:00
|
|
|
import android.content.Context;
|
2014-09-27 09:37:02 +00:00
|
|
|
import android.content.Intent;
|
2018-06-10 17:40:55 +00:00
|
|
|
import android.content.SharedPreferences;
|
2015-12-06 23:33:50 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2014-09-27 09:37:02 +00:00
|
|
|
import android.net.Uri;
|
2014-11-04 08:30:03 +00:00
|
|
|
import android.os.Build;
|
2014-07-02 14:13:25 +00:00
|
|
|
import android.os.Bundle;
|
2014-07-11 21:44:59 +00:00
|
|
|
import android.text.Editable;
|
2018-11-08 18:04:07 +00:00
|
|
|
import android.text.Html;
|
2014-07-11 21:44:59 +00:00
|
|
|
import android.text.TextWatcher;
|
2018-11-08 18:04:07 +00:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2018-03-14 09:07:52 +00:00
|
|
|
import android.util.Log;
|
2016-05-26 20:53:55 +00:00
|
|
|
import android.util.Pair;
|
2014-07-09 23:55:19 +00:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2014-08-07 22:43:07 +00:00
|
|
|
import android.view.KeyEvent;
|
2014-07-04 09:36:02 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-07-07 07:32:10 +00:00
|
|
|
import android.view.View;
|
2016-08-31 15:04:43 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-07-11 21:44:59 +00:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2014-07-07 07:32:10 +00:00
|
|
|
import android.widget.AdapterView;
|
2014-07-09 23:55:19 +00:00
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2014-07-07 07:32:10 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
2014-07-10 17:42:37 +00:00
|
|
|
import android.widget.AutoCompleteTextView;
|
2014-07-15 12:32:19 +00:00
|
|
|
import android.widget.CheckBox;
|
2014-07-11 21:44:59 +00:00
|
|
|
import android.widget.EditText;
|
2014-07-07 07:32:10 +00:00
|
|
|
import android.widget.ListView;
|
2014-07-10 11:19:42 +00:00
|
|
|
import android.widget.Spinner;
|
2016-02-24 15:53:19 +00:00
|
|
|
import android.widget.TextView;
|
2015-07-15 15:42:08 +00:00
|
|
|
import android.widget.Toast;
|
2014-11-03 21:47:07 +00:00
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
|
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
|
|
|
2014-11-03 22:47:49 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2015-12-06 23:33:50 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2014-11-03 22:47:49 +00:00
|
|
|
|
2014-11-04 12:14:29 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-07-02 14:13:25 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-02-18 19:01:01 +00:00
|
|
|
import eu.siacs.conversations.databinding.ActivityStartConversationBinding;
|
2014-07-07 07:32:10 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-07-14 09:47:42 +00:00
|
|
|
import eu.siacs.conversations.entities.Bookmark;
|
2014-07-07 07:32:10 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.ListItem;
|
2019-08-19 11:55:52 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2016-01-17 21:28:38 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2018-10-25 13:31:56 +00:00
|
|
|
import eu.siacs.conversations.services.QuickConversationsService;
|
2018-04-11 07:27:16 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2014-07-18 13:35:31 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
|
2014-07-16 22:03:37 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.ListItemAdapter;
|
2018-03-14 09:07:52 +00:00
|
|
|
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
2018-10-06 15:03:12 +00:00
|
|
|
import eu.siacs.conversations.ui.util.JidDialog;
|
2018-03-18 22:32:30 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
2018-03-18 08:31:37 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-04-25 18:25:28 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
2018-11-07 12:42:01 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.SwipeRefreshListFragment;
|
2018-10-17 20:50:34 +00:00
|
|
|
import eu.siacs.conversations.utils.AccountUtils;
|
2014-12-21 20:43:58 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2021-01-23 08:25:34 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2014-12-21 20:43:58 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
2015-05-19 06:31:56 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-07-02 14:13:25 +00:00
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
public class StartConversationActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, CreatePrivateGroupChatDialog.CreateConferenceDialogListener, JoinConferenceDialog.JoinConferenceDialogListener, SwipeRefreshLayout.OnRefreshListener, CreatePublicChannelDialog.CreatePublicChannelDialogListener {
|
2014-06-30 18:39:15 +00:00
|
|
|
|
2018-10-09 17:35:33 +00:00
|
|
|
public static final String EXTRA_INVITE_URI = "eu.siacs.conversations.invite_uri";
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
private final int REQUEST_SYNC_CONTACTS = 0x28cf;
|
|
|
|
private final int REQUEST_CREATE_CONFERENCE = 0x39da;
|
2018-03-20 11:52:23 +00:00
|
|
|
private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
|
|
|
|
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
|
|
|
|
private final AtomicBoolean oneShotKeyboardSuppress = new AtomicBoolean();
|
2018-02-26 20:18:36 +00:00
|
|
|
public int conference_context_id;
|
|
|
|
public int contact_context_id;
|
|
|
|
private ListPagerAdapter mListPagerAdapter;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final List<ListItem> contacts = new ArrayList<>();
|
2018-02-26 20:18:36 +00:00
|
|
|
private ListItemAdapter mContactsAdapter;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final List<ListItem> conferences = new ArrayList<>();
|
2018-02-26 20:18:36 +00:00
|
|
|
private ListItemAdapter mConferenceAdapter;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final List<String> mActivatedAccounts = new ArrayList<>();
|
2018-02-26 20:18:36 +00:00
|
|
|
private EditText mSearchEditText;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
|
|
|
|
private final AtomicBoolean mOpenedFab = new AtomicBoolean(false);
|
2018-02-26 20:18:36 +00:00
|
|
|
private boolean mHideOfflineContacts = false;
|
2018-10-24 11:54:42 +00:00
|
|
|
private boolean createdByViewIntent = false;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
2018-02-26 20:18:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
|
|
|
mSearchEditText.post(() -> {
|
2018-04-24 14:45:37 +00:00
|
|
|
updateSearchViewHint();
|
2018-02-26 20:18:36 +00:00
|
|
|
mSearchEditText.requestFocus();
|
2018-03-20 11:52:23 +00:00
|
|
|
if (oneShotKeyboardSuppress.compareAndSet(true, false)) {
|
2018-03-18 08:31:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
2018-03-18 08:31:37 +00:00
|
|
|
if (imm != null) {
|
|
|
|
imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
});
|
2019-01-27 15:35:55 +00:00
|
|
|
if (binding.speedDial.isOpen()) {
|
|
|
|
binding.speedDial.close();
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
2018-04-25 18:25:28 +00:00
|
|
|
SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
|
2018-02-26 20:18:36 +00:00
|
|
|
mSearchEditText.setText("");
|
|
|
|
filter(null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2021-01-19 11:58:05 +00:00
|
|
|
private final TextWatcher mSearchTextWatcher = new TextWatcher() {
|
2018-02-26 20:18:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
|
|
|
filter(editable.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-18 08:31:37 +00:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private MenuItem mMenuSearchView;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() {
|
2018-02-26 20:18:36 +00:00
|
|
|
@Override
|
|
|
|
public void onTagClicked(String tag) {
|
|
|
|
if (mMenuSearchView != null) {
|
|
|
|
mMenuSearchView.expandActionView();
|
|
|
|
mSearchEditText.setText("");
|
|
|
|
mSearchEditText.append(tag);
|
|
|
|
filter(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private Pair<Integer, Intent> mPostponedActivityResult;
|
|
|
|
private Toast mToast;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
|
2018-02-26 20:18:36 +00:00
|
|
|
@Override
|
|
|
|
public void success(final Conversation conversation) {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
hideToast();
|
|
|
|
switchToConversation(conversation);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(final int errorCode, Conversation object) {
|
|
|
|
runOnUiThread(() -> replaceToast(getString(errorCode)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-26 15:40:05 +00:00
|
|
|
public void userInputRequired(PendingIntent pi, Conversation object) {
|
2018-02-26 20:18:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private ActivityStartConversationBinding binding;
|
2021-01-19 11:58:05 +00:00
|
|
|
private final TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
|
2018-03-20 11:52:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
int pos = binding.startConversationViewPager.getCurrentItem();
|
|
|
|
if (pos == 0) {
|
|
|
|
if (contacts.size() == 1) {
|
|
|
|
openConversationForContact((Contact) contacts.get(0));
|
|
|
|
return true;
|
2018-06-10 17:48:30 +00:00
|
|
|
} else if (contacts.size() == 0 && conferences.size() == 1) {
|
|
|
|
openConversationsForBookmark((Bookmark) conferences.get(0));
|
|
|
|
return true;
|
2018-03-20 11:52:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (conferences.size() == 1) {
|
|
|
|
openConversationsForBookmark((Bookmark) conferences.get(0));
|
|
|
|
return true;
|
2018-06-10 17:48:30 +00:00
|
|
|
} else if (conferences.size() == 0 && contacts.size() == 1) {
|
|
|
|
openConversationForContact((Contact) contacts.get(0));
|
|
|
|
return true;
|
2018-03-20 11:52:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-25 18:25:28 +00:00
|
|
|
SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
|
2018-03-20 11:52:23 +00:00
|
|
|
mListPagerAdapter.requestFocus(pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-02-26 20:18:36 +00:00
|
|
|
|
|
|
|
public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
|
|
|
|
if (accounts.size() > 0) {
|
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.simple_list_item, accounts);
|
|
|
|
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
|
|
|
spinner.setAdapter(adapter);
|
|
|
|
spinner.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
|
|
|
|
R.layout.simple_list_item,
|
2018-10-25 13:31:56 +00:00
|
|
|
Collections.singletonList(context.getString(R.string.no_accounts)));
|
2018-02-26 20:18:36 +00:00
|
|
|
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
|
|
|
spinner.setAdapter(adapter);
|
|
|
|
spinner.setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void launch(Context context) {
|
|
|
|
final Intent intent = new Intent(context, StartConversationActivity.class);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2018-03-20 11:52:23 +00:00
|
|
|
private static Intent createLauncherIntent(Context context) {
|
|
|
|
final Intent intent = new Intent(context, StartConversationActivity.class);
|
|
|
|
intent.setAction(Intent.ACTION_MAIN);
|
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isViewIntent(final Intent i) {
|
2018-10-09 17:35:33 +00:00
|
|
|
return i != null && (Intent.ACTION_VIEW.equals(i.getAction()) || Intent.ACTION_SENDTO.equals(i.getAction()) || i.hasExtra(EXTRA_INVITE_URI));
|
2018-03-20 11:52:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
protected void hideToast() {
|
|
|
|
if (mToast != null) {
|
|
|
|
mToast.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void replaceToast(String msg) {
|
|
|
|
hideToast();
|
|
|
|
mToast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
|
|
|
|
mToast.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRosterUpdate() {
|
|
|
|
this.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_start_conversation);
|
2021-01-23 08:25:34 +00:00
|
|
|
setSupportActionBar(binding.toolbar);
|
2018-03-18 08:30:22 +00:00
|
|
|
configureActionBar(getSupportActionBar());
|
2019-01-27 15:35:55 +00:00
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
binding.speedDial.inflate(R.menu.start_conversation_fab_submenu);
|
2019-01-27 15:35:55 +00:00
|
|
|
|
2018-03-18 08:47:52 +00:00
|
|
|
binding.tabLayout.setupWithViewPager(binding.startConversationViewPager);
|
2019-02-15 13:07:39 +00:00
|
|
|
binding.startConversationViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
|
|
|
updateSearchViewHint();
|
|
|
|
}
|
|
|
|
});
|
2018-02-26 20:18:36 +00:00
|
|
|
mListPagerAdapter = new ListPagerAdapter(getSupportFragmentManager());
|
|
|
|
binding.startConversationViewPager.setAdapter(mListPagerAdapter);
|
|
|
|
|
|
|
|
mConferenceAdapter = new ListItemAdapter(this, conferences);
|
|
|
|
mContactsAdapter = new ListItemAdapter(this, contacts);
|
|
|
|
mContactsAdapter.setOnTagClickedListener(this.mOnTagClickedListener);
|
2018-06-10 17:40:55 +00:00
|
|
|
|
|
|
|
final SharedPreferences preferences = getPreferences();
|
|
|
|
|
2018-10-28 11:34:17 +00:00
|
|
|
this.mHideOfflineContacts = QuickConversationsService.isConversations() && preferences.getBoolean("hide_offline", false);
|
2018-06-10 17:40:55 +00:00
|
|
|
|
|
|
|
final boolean startSearching = preferences.getBoolean("start_searching",getResources().getBoolean(R.bool.start_searching));
|
2018-02-26 20:18:36 +00:00
|
|
|
|
2018-03-20 11:52:23 +00:00
|
|
|
final Intent intent;
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
intent = getIntent();
|
|
|
|
} else {
|
2018-10-24 11:54:42 +00:00
|
|
|
createdByViewIntent = savedInstanceState.getBoolean("created_by_view_intent", false);
|
2018-03-20 11:52:23 +00:00
|
|
|
final String search = savedInstanceState.getString("search");
|
|
|
|
if (search != null) {
|
|
|
|
mInitialSearchValue.push(search);
|
|
|
|
}
|
|
|
|
intent = savedInstanceState.getParcelable("intent");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isViewIntent(intent)) {
|
|
|
|
pendingViewIntent.push(intent);
|
2018-10-24 11:54:42 +00:00
|
|
|
createdByViewIntent = true;
|
2018-03-20 11:52:23 +00:00
|
|
|
setIntent(createLauncherIntent(this));
|
2018-06-10 17:40:55 +00:00
|
|
|
} else if (startSearching && mInitialSearchValue.peek() == null) {
|
|
|
|
mInitialSearchValue.push("");
|
2018-03-20 11:52:23 +00:00
|
|
|
}
|
2018-11-08 18:04:07 +00:00
|
|
|
mRequestedContactsPermission.set(savedInstanceState != null && savedInstanceState.getBoolean("requested_contacts_permission",false));
|
2019-04-25 17:52:42 +00:00
|
|
|
mOpenedFab.set(savedInstanceState != null && savedInstanceState.getBoolean("opened_fab",false));
|
2019-01-27 15:35:55 +00:00
|
|
|
binding.speedDial.setOnActionSelectedListener(actionItem -> {
|
2019-02-06 13:45:51 +00:00
|
|
|
final String searchString = mSearchEditText != null ? mSearchEditText.getText().toString() : null;
|
|
|
|
final String prefilled;
|
|
|
|
if (isValidJid(searchString)) {
|
|
|
|
prefilled = Jid.ofEscaped(searchString).toEscapedString();
|
|
|
|
} else {
|
|
|
|
prefilled = null;
|
|
|
|
}
|
2019-01-27 15:35:55 +00:00
|
|
|
switch (actionItem.getId()) {
|
2019-03-31 15:12:01 +00:00
|
|
|
case R.id.discover_public_channels:
|
|
|
|
startActivity(new Intent(this, ChannelDiscoveryActivity.class));
|
|
|
|
break;
|
2019-02-06 13:45:51 +00:00
|
|
|
case R.id.join_public_channel:
|
|
|
|
showJoinConferenceDialog(prefilled);
|
2019-01-27 15:35:55 +00:00
|
|
|
break;
|
2019-02-06 13:45:51 +00:00
|
|
|
case R.id.create_private_group_chat:
|
|
|
|
showCreatePrivateGroupChatDialog();
|
|
|
|
break;
|
|
|
|
case R.id.create_public_channel:
|
|
|
|
showPublicChannelDialog();
|
|
|
|
break;
|
|
|
|
case R.id.create_contact:
|
|
|
|
showCreateContactDialog(prefilled,null);
|
2019-01-27 15:35:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2018-03-20 11:52:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
public static boolean isValidJid(String input) {
|
|
|
|
try {
|
|
|
|
Jid jid = Jid.ofEscaped(input);
|
|
|
|
return !jid.isDomainJid();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-20 11:52:23 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
|
|
Intent pendingIntent = pendingViewIntent.peek();
|
|
|
|
savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
|
2018-11-08 18:04:07 +00:00
|
|
|
savedInstanceState.putBoolean("requested_contacts_permission",mRequestedContactsPermission.get());
|
2019-04-25 17:52:42 +00:00
|
|
|
savedInstanceState.putBoolean("opened_fab",mOpenedFab.get());
|
2018-10-24 11:54:42 +00:00
|
|
|
savedInstanceState.putBoolean("created_by_view_intent",createdByViewIntent);
|
2018-03-20 11:52:23 +00:00
|
|
|
if (mMenuSearchView != null && mMenuSearchView.isActionViewExpanded()) {
|
|
|
|
savedInstanceState.putString("search", mSearchEditText != null ? mSearchEditText.getText().toString() : null);
|
|
|
|
}
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
recreate();
|
|
|
|
} else {
|
2018-03-30 13:57:44 +00:00
|
|
|
if (pendingViewIntent.peek() == null) {
|
2018-02-26 20:18:36 +00:00
|
|
|
askForContactsPermissions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mConferenceAdapter.refreshSettings();
|
|
|
|
mContactsAdapter.refreshSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-20 11:52:23 +00:00
|
|
|
public void onNewIntent(final Intent intent) {
|
2021-01-18 20:49:31 +00:00
|
|
|
super.onNewIntent(intent);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (xmppConnectionServiceBound) {
|
2018-03-20 11:52:23 +00:00
|
|
|
processViewIntent(intent);
|
2018-02-26 20:18:36 +00:00
|
|
|
} else {
|
2018-03-20 11:52:23 +00:00
|
|
|
pendingViewIntent.push(intent);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
2018-03-20 11:52:23 +00:00
|
|
|
setIntent(createLauncherIntent(this));
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void openConversationForContact(int position) {
|
|
|
|
Contact contact = (Contact) contacts.get(position);
|
|
|
|
openConversationForContact(contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void openConversationForContact(Contact contact) {
|
|
|
|
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
|
2018-04-25 18:25:28 +00:00
|
|
|
SoftKeyboardUtils.hideSoftKeyboard(this);
|
2018-02-26 20:18:36 +00:00
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void openConversationForBookmark(int position) {
|
|
|
|
Bookmark bookmark = (Bookmark) conferences.get(position);
|
|
|
|
openConversationsForBookmark(bookmark);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void shareBookmarkUri() {
|
|
|
|
shareBookmarkUri(conference_context_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void shareBookmarkUri(int position) {
|
|
|
|
Bookmark bookmark = (Bookmark) conferences.get(position);
|
2019-09-21 08:51:05 +00:00
|
|
|
shareAsChannel(this, bookmark.getJid().asBareJid().toEscapedString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void shareAsChannel(final Context context, final String address) {
|
2018-02-26 20:18:36 +00:00
|
|
|
Intent shareIntent = new Intent();
|
|
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
2019-09-21 08:51:05 +00:00
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + address + "?join");
|
2018-02-26 20:18:36 +00:00
|
|
|
shareIntent.setType("text/plain");
|
|
|
|
try {
|
2019-09-21 08:51:05 +00:00
|
|
|
context.startActivity(Intent.createChooser(shareIntent, context.getText(R.string.share_uri_with)));
|
2018-02-26 20:18:36 +00:00
|
|
|
} catch (ActivityNotFoundException e) {
|
2019-09-21 08:51:05 +00:00
|
|
|
Toast.makeText(context, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void openConversationsForBookmark(Bookmark bookmark) {
|
2018-11-10 16:33:24 +00:00
|
|
|
final Jid jid = bookmark.getFullJid();
|
2018-02-26 20:18:36 +00:00
|
|
|
if (jid == null) {
|
|
|
|
Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
|
|
|
|
bookmark.setConversation(conversation);
|
|
|
|
if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))) {
|
|
|
|
bookmark.setAutojoin(true);
|
2019-09-27 22:32:29 +00:00
|
|
|
xmppConnectionService.createBookmark(bookmark.getAccount(), bookmark);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
2018-04-25 18:25:28 +00:00
|
|
|
SoftKeyboardUtils.hideSoftKeyboard(this);
|
2018-02-26 20:18:36 +00:00
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void openDetailsForContact() {
|
|
|
|
int position = contact_context_id;
|
|
|
|
Contact contact = (Contact) contacts.get(position);
|
|
|
|
switchToContactDetails(contact);
|
|
|
|
}
|
|
|
|
|
2018-04-20 15:12:47 +00:00
|
|
|
protected void showQrForContact() {
|
|
|
|
int position = contact_context_id;
|
|
|
|
Contact contact = (Contact) contacts.get(position);
|
|
|
|
showQrCode("xmpp:"+contact.getJid().asBareJid().toEscapedString());
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
protected void toggleContactBlock() {
|
|
|
|
final int position = contact_context_id;
|
|
|
|
BlockContactDialog.show(this, (Contact) contacts.get(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void deleteContact() {
|
|
|
|
final int position = contact_context_id;
|
|
|
|
final Contact contact = (Contact) contacts.get(position);
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setTitle(R.string.action_delete_contact);
|
2018-10-06 15:03:12 +00:00
|
|
|
builder.setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()));
|
2018-03-18 08:47:52 +00:00
|
|
|
builder.setPositiveButton(R.string.delete, (dialog, which) -> {
|
|
|
|
xmppConnectionService.deleteContactOnServer(contact);
|
|
|
|
filter(mSearchEditText.getText().toString());
|
2018-02-26 20:18:36 +00:00
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void deleteConference() {
|
|
|
|
int position = conference_context_id;
|
|
|
|
final Bookmark bookmark = (Bookmark) conferences.get(position);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setTitle(R.string.delete_bookmark);
|
2018-10-06 15:03:12 +00:00
|
|
|
builder.setMessage(JidDialog.style(this, R.string.remove_bookmark_text, bookmark.getJid().toEscapedString()));
|
2018-03-18 08:47:52 +00:00
|
|
|
builder.setPositiveButton(R.string.delete, (dialog, which) -> {
|
|
|
|
bookmark.setConversation(null);
|
2019-09-28 00:23:15 +00:00
|
|
|
final Account account = bookmark.getAccount();
|
2019-09-27 22:32:29 +00:00
|
|
|
xmppConnectionService.deleteBookmark(account, bookmark);
|
2018-03-18 08:47:52 +00:00
|
|
|
filter(mSearchEditText.getText().toString());
|
2018-02-26 20:18:36 +00:00
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
|
2018-03-14 06:20:44 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2018-03-14 09:07:52 +00:00
|
|
|
Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
|
2018-03-14 06:20:44 +00:00
|
|
|
if (prev != null) {
|
|
|
|
ft.remove(prev);
|
|
|
|
}
|
|
|
|
ft.addToBackStack(null);
|
2018-03-12 11:12:51 +00:00
|
|
|
EnterJidDialog dialog = EnterJidDialog.newInstance(
|
2018-03-14 09:07:52 +00:00
|
|
|
mActivatedAccounts,
|
2019-02-06 13:45:51 +00:00
|
|
|
getString(R.string.add_contact),
|
2019-02-07 12:18:42 +00:00
|
|
|
getString(R.string.add),
|
2018-03-14 09:07:52 +00:00
|
|
|
prefilledJid,
|
2020-01-09 16:39:55 +00:00
|
|
|
invite == null ? null : invite.account,
|
2019-04-26 10:05:52 +00:00
|
|
|
invite == null || !invite.hasFingerprints(),
|
|
|
|
true
|
2018-02-26 20:18:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
|
|
|
|
if (!xmppConnectionServiceBound) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Account account = xmppConnectionService.findAccountByJid(accountJid);
|
|
|
|
if (account == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Contact contact = account.getRoster().getContact(contactJid);
|
|
|
|
if (invite != null && invite.getName() != null) {
|
|
|
|
contact.setServerName(invite.getName());
|
|
|
|
}
|
|
|
|
if (contact.isSelf()) {
|
2018-10-19 13:39:31 +00:00
|
|
|
switchToConversation(contact);
|
2018-02-26 20:18:36 +00:00
|
|
|
return true;
|
|
|
|
} else if (contact.showInRoster()) {
|
|
|
|
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
|
|
|
|
} else {
|
2018-03-13 15:55:25 +00:00
|
|
|
xmppConnectionService.createContact(contact, true);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (invite != null && invite.hasFingerprints()) {
|
|
|
|
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
|
|
|
|
}
|
2018-10-19 13:39:31 +00:00
|
|
|
switchToConversationDoNotAppend(contact, invite == null ? null : invite.getBody());
|
2018-02-26 20:18:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-03-14 09:07:52 +00:00
|
|
|
dialog.show(ft, FRAGMENT_TAG_DIALOG);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
protected void showJoinConferenceDialog(final String prefilledJid) {
|
2018-03-14 06:20:44 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2018-03-14 09:07:52 +00:00
|
|
|
Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
|
2018-03-14 06:20:44 +00:00
|
|
|
if (prev != null) {
|
|
|
|
ft.remove(prev);
|
|
|
|
}
|
|
|
|
ft.addToBackStack(null);
|
2018-03-14 09:07:52 +00:00
|
|
|
JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts);
|
|
|
|
joinConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
private void showCreatePrivateGroupChatDialog() {
|
2018-03-14 06:20:44 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2018-03-14 09:07:52 +00:00
|
|
|
Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
|
2018-03-14 06:20:44 +00:00
|
|
|
if (prev != null) {
|
|
|
|
ft.remove(prev);
|
|
|
|
}
|
|
|
|
ft.addToBackStack(null);
|
2019-02-06 13:45:51 +00:00
|
|
|
CreatePrivateGroupChatDialog createConferenceFragment = CreatePrivateGroupChatDialog.newInstance(mActivatedAccounts);
|
2018-03-14 09:07:52 +00:00
|
|
|
createConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
private void showPublicChannelDialog() {
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
|
|
|
|
if (prev != null) {
|
|
|
|
ft.remove(prev);
|
|
|
|
}
|
|
|
|
ft.addToBackStack(null);
|
|
|
|
CreatePublicChannelDialog dialog = CreatePublicChannelDialog.newInstance(mActivatedAccounts);
|
|
|
|
dialog.show(ft, FRAGMENT_TAG_DIALOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Account getSelectedAccount(Context context, Spinner spinner) {
|
|
|
|
if (spinner == null || !spinner.isEnabled()) {
|
2018-02-26 20:18:36 +00:00
|
|
|
return null;
|
|
|
|
}
|
2019-02-06 13:45:51 +00:00
|
|
|
if (context instanceof XmppActivity) {
|
|
|
|
Jid jid;
|
|
|
|
try {
|
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
2020-05-18 07:35:35 +00:00
|
|
|
jid = Jid.ofEscaped((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
|
2019-02-06 13:45:51 +00:00
|
|
|
} else {
|
2020-05-18 07:35:35 +00:00
|
|
|
jid = Jid.ofEscaped((String) spinner.getSelectedItem());
|
2019-02-06 13:45:51 +00:00
|
|
|
}
|
|
|
|
} catch (final IllegalArgumentException e) {
|
|
|
|
return null;
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
2019-02-06 13:45:51 +00:00
|
|
|
final XmppConnectionService service = ((XmppActivity) context).xmppConnectionService;
|
|
|
|
if (service == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return service.findAccountByJid(jid);
|
|
|
|
} else {
|
2018-02-26 20:18:36 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 13:39:31 +00:00
|
|
|
protected void switchToConversation(Contact contact) {
|
|
|
|
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
|
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void switchToConversationDoNotAppend(Contact contact, String body) {
|
|
|
|
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
|
|
|
|
switchToConversationDoNotAppend(conversation, body);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 08:31:37 +00:00
|
|
|
@Override
|
|
|
|
public void invalidateOptionsMenu() {
|
|
|
|
boolean isExpanded = mMenuSearchView != null && mMenuSearchView.isActionViewExpanded();
|
|
|
|
String text = mSearchEditText != null ? mSearchEditText.getText().toString() : "";
|
|
|
|
if (isExpanded) {
|
|
|
|
mInitialSearchValue.push(text);
|
|
|
|
oneShotKeyboardSuppress.set(true);
|
|
|
|
}
|
|
|
|
super.invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:45:37 +00:00
|
|
|
private void updateSearchViewHint() {
|
|
|
|
if (binding == null || mSearchEditText == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (binding.startConversationViewPager.getCurrentItem() == 0) {
|
|
|
|
mSearchEditText.setHint(R.string.search_contacts);
|
2020-08-31 15:12:31 +00:00
|
|
|
mSearchEditText.setContentDescription(getString(R.string.search_contacts));
|
2018-04-24 14:45:37 +00:00
|
|
|
} else {
|
2019-02-15 13:07:39 +00:00
|
|
|
mSearchEditText.setHint(R.string.search_bookmarks);
|
2020-08-31 15:12:31 +00:00
|
|
|
mSearchEditText.setContentDescription(getString(R.string.search_bookmarks));
|
2018-04-24 14:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.start_conversation, menu);
|
2018-10-17 20:50:34 +00:00
|
|
|
AccountUtils.showHideMenuItems(menu);
|
2018-02-26 20:18:36 +00:00
|
|
|
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
|
2018-03-14 07:21:49 +00:00
|
|
|
MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
|
|
|
|
qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable());
|
2018-10-25 13:31:56 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
menuHideOffline.setVisible(false);
|
|
|
|
} else {
|
|
|
|
menuHideOffline.setVisible(true);
|
|
|
|
menuHideOffline.setChecked(this.mHideOfflineContacts);
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
mMenuSearchView = menu.findItem(R.id.action_search);
|
|
|
|
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
|
|
|
|
View mSearchView = mMenuSearchView.getActionView();
|
|
|
|
mSearchEditText = mSearchView.findViewById(R.id.search_field);
|
|
|
|
mSearchEditText.addTextChangedListener(mSearchTextWatcher);
|
|
|
|
mSearchEditText.setOnEditorActionListener(mSearchDone);
|
2018-03-18 08:31:37 +00:00
|
|
|
String initialSearchValue = mInitialSearchValue.pop();
|
|
|
|
if (initialSearchValue != null) {
|
2018-03-06 21:45:18 +00:00
|
|
|
mMenuSearchView.expandActionView();
|
2018-03-18 08:31:37 +00:00
|
|
|
mSearchEditText.append(initialSearchValue);
|
|
|
|
filter(initialSearchValue);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
2018-04-24 14:45:37 +00:00
|
|
|
updateSearchViewHint();
|
2018-02-26 20:18:36 +00:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2018-03-18 22:32:30 +00:00
|
|
|
if (MenuDoubleTabUtil.shouldIgnoreTap()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
switch (item.getItemId()) {
|
2018-04-03 15:53:08 +00:00
|
|
|
case android.R.id.home:
|
|
|
|
navigateBack();
|
|
|
|
return true;
|
2018-02-26 20:18:36 +00:00
|
|
|
case R.id.action_scan_qr_code:
|
|
|
|
UriHandlerActivity.scan(this);
|
|
|
|
return true;
|
|
|
|
case R.id.action_hide_offline:
|
|
|
|
mHideOfflineContacts = !item.isChecked();
|
2018-10-25 13:31:56 +00:00
|
|
|
getPreferences().edit().putBoolean("hide_offline", mHideOfflineContacts).apply();
|
2018-02-26 20:18:36 +00:00
|
|
|
if (mSearchEditText != null) {
|
|
|
|
filter(mSearchEditText.getText().toString());
|
|
|
|
}
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_SEARCH && !event.isLongPress()) {
|
|
|
|
openSearch();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
int c = event.getUnicodeChar();
|
|
|
|
if (c > 32) {
|
|
|
|
if (mSearchEditText != null && !mSearchEditText.isFocused()) {
|
|
|
|
openSearch();
|
|
|
|
mSearchEditText.append(Character.toString((char) c));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openSearch() {
|
|
|
|
if (mMenuSearchView != null) {
|
|
|
|
mMenuSearchView.expandActionView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
this.mPostponedActivityResult = null;
|
|
|
|
if (requestCode == REQUEST_CREATE_CONFERENCE) {
|
|
|
|
Account account = extractAccount(intent);
|
2018-06-24 09:23:10 +00:00
|
|
|
final String name = intent.getStringExtra(ChooseContactActivity.EXTRA_GROUP_CHAT_NAME);
|
|
|
|
final List<Jid> jids = ChooseContactActivity.extractJabberIds(intent);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (account != null && jids.size() > 0) {
|
2018-06-24 09:23:10 +00:00
|
|
|
if (xmppConnectionService.createAdhocConference(account, name, jids, mAdhocConferenceCallback)) {
|
2018-02-26 20:18:36 +00:00
|
|
|
mToast = Toast.makeText(this, R.string.creating_conference, Toast.LENGTH_LONG);
|
|
|
|
mToast.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mPostponedActivityResult = new Pair<>(requestCode, intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onActivityResult(requestCode, requestCode, intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void askForContactsPermissions() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (mRequestedContactsPermission.compareAndSet(false, true)) {
|
|
|
|
if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.sync_with_contacts);
|
2018-11-08 18:04:07 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
builder.setMessage(Html.fromHtml(getString(R.string.sync_with_contacts_quicksy)));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(R.string.sync_with_contacts_long);
|
|
|
|
}
|
2018-09-06 13:55:54 +00:00
|
|
|
builder.setPositiveButton(R.string.next, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS));
|
|
|
|
builder.setOnDismissListener(dialog -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS));
|
2018-11-08 18:04:07 +00:00
|
|
|
builder.setCancelable(false);
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
dialog.setOnShowListener(dialogInterface -> {
|
|
|
|
final TextView tv = dialog.findViewById(android.R.id.message);
|
|
|
|
if (tv != null) {
|
|
|
|
tv.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show();
|
2018-02-26 20:18:36 +00:00
|
|
|
} else {
|
2018-09-06 13:55:54 +00:00
|
|
|
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-23 08:25:34 +00:00
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
2018-02-26 20:18:36 +00:00
|
|
|
if (grantResults.length > 0)
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
2018-03-13 15:55:25 +00:00
|
|
|
ScanActivity.onRequestPermissionResult(this, requestCode, grantResults);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
|
2018-11-08 18:04:07 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
setRefreshing(true);
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
xmppConnectionService.loadPhoneContacts();
|
2018-09-06 13:55:54 +00:00
|
|
|
xmppConnectionService.startContactObserver();
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 15:53:08 +00:00
|
|
|
private void configureHomeButton() {
|
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-24 11:54:42 +00:00
|
|
|
boolean openConversations = !createdByViewIntent && !xmppConnectionService.isConversationsListEmpty(null);
|
2018-04-03 15:53:08 +00:00
|
|
|
actionBar.setDisplayHomeAsUpEnabled(openConversations);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(openConversations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
@Override
|
|
|
|
protected void onBackendConnected() {
|
2018-11-08 18:04:07 +00:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
xmppConnectionService.getQuickConversationsService().considerSyncBackground(false);
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
if (mPostponedActivityResult != null) {
|
|
|
|
onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
|
|
|
|
this.mPostponedActivityResult = null;
|
|
|
|
}
|
|
|
|
this.mActivatedAccounts.clear();
|
2019-03-31 15:12:01 +00:00
|
|
|
this.mActivatedAccounts.addAll(AccountUtils.getEnabledAccounts(xmppConnectionService));
|
2018-04-03 15:53:08 +00:00
|
|
|
configureHomeButton();
|
2018-03-20 11:52:23 +00:00
|
|
|
Intent intent = pendingViewIntent.pop();
|
|
|
|
if (intent != null && processViewIntent(intent)) {
|
2018-02-26 20:18:36 +00:00
|
|
|
filter(null);
|
2018-03-20 11:52:23 +00:00
|
|
|
} else {
|
2018-02-26 20:18:36 +00:00
|
|
|
if (mSearchEditText != null) {
|
|
|
|
filter(mSearchEditText.getText().toString());
|
|
|
|
} else {
|
|
|
|
filter(null);
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 09:07:52 +00:00
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
|
2018-10-25 13:31:56 +00:00
|
|
|
if (fragment instanceof OnBackendConnected) {
|
2018-03-20 11:52:23 +00:00
|
|
|
Log.d(Config.LOGTAG, "calling on backend connected on dialog");
|
2018-03-14 09:07:52 +00:00
|
|
|
((OnBackendConnected) fragment).onBackendConnected();
|
|
|
|
}
|
2018-11-07 12:42:01 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
setRefreshing(xmppConnectionService.getQuickConversationsService().isSynchronizing());
|
|
|
|
}
|
2019-04-26 07:30:38 +00:00
|
|
|
if (QuickConversationsService.isConversations() && AccountUtils.hasEnabledAccounts(xmppConnectionService) && this.contacts.size() == 0 && this.conferences.size() == 0 && mOpenedFab.compareAndSet(false,true)) {
|
2019-04-25 17:52:42 +00:00
|
|
|
binding.speedDial.open();
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 13:57:44 +00:00
|
|
|
protected boolean processViewIntent(@NonNull Intent intent) {
|
2018-10-09 17:35:33 +00:00
|
|
|
final String inviteUri = intent.getStringExtra(EXTRA_INVITE_URI);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (inviteUri != null) {
|
2020-01-09 16:39:55 +00:00
|
|
|
final Invite invite = new Invite(inviteUri);
|
|
|
|
invite.account = intent.getStringExtra(EXTRA_ACCOUNT);
|
2020-01-10 11:51:04 +00:00
|
|
|
if (invite.isValidJid()) {
|
2018-02-26 20:18:36 +00:00
|
|
|
return invite.invite();
|
|
|
|
}
|
|
|
|
}
|
2018-04-20 09:32:50 +00:00
|
|
|
final String action = intent.getAction();
|
|
|
|
if (action == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (action) {
|
2018-02-26 20:18:36 +00:00
|
|
|
case Intent.ACTION_SENDTO:
|
|
|
|
case Intent.ACTION_VIEW:
|
|
|
|
Uri uri = intent.getData();
|
|
|
|
if (uri != null) {
|
2018-03-13 15:55:25 +00:00
|
|
|
Invite invite = new Invite(intent.getData(), intent.getBooleanExtra("scanned", false));
|
2020-01-09 16:39:55 +00:00
|
|
|
invite.account = intent.getStringExtra(EXTRA_ACCOUNT);
|
2019-09-24 15:29:34 +00:00
|
|
|
invite.forceDialog = intent.getBooleanExtra("force_dialog", false);
|
2018-02-26 20:18:36 +00:00
|
|
|
return invite.invite();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean handleJid(Invite invite) {
|
|
|
|
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
|
|
|
|
if (invite.isAction(XmppUri.ACTION_JOIN)) {
|
|
|
|
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
|
2019-09-24 15:29:34 +00:00
|
|
|
if (muc != null && !invite.forceDialog) {
|
2018-10-19 13:39:31 +00:00
|
|
|
switchToConversationDoNotAppend(muc, invite.getBody());
|
2018-02-26 20:18:36 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2020-05-15 16:21:45 +00:00
|
|
|
showJoinConferenceDialog(invite.getJid().asBareJid().toEscapedString());
|
2018-02-26 20:18:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-01-09 16:39:55 +00:00
|
|
|
} else if (contacts.size() == 0) {
|
2020-05-15 16:21:45 +00:00
|
|
|
showCreateContactDialog(invite.getJid().toEscapedString(), invite);
|
2018-02-26 20:18:36 +00:00
|
|
|
return false;
|
|
|
|
} else if (contacts.size() == 1) {
|
|
|
|
Contact contact = contacts.get(0);
|
|
|
|
if (!invite.isSafeSource() && invite.hasFingerprints()) {
|
|
|
|
displayVerificationWarningDialog(contact, invite);
|
|
|
|
} else {
|
|
|
|
if (invite.hasFingerprints()) {
|
|
|
|
if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
|
|
|
|
Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (invite.account != null) {
|
|
|
|
xmppConnectionService.getShortcutService().report(contact);
|
|
|
|
}
|
2018-10-19 13:39:31 +00:00
|
|
|
switchToConversationDoNotAppend(contact, invite.getBody());
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (mMenuSearchView != null) {
|
|
|
|
mMenuSearchView.expandActionView();
|
|
|
|
mSearchEditText.setText("");
|
2020-05-15 16:21:45 +00:00
|
|
|
mSearchEditText.append(invite.getJid().toEscapedString());
|
|
|
|
filter(invite.getJid().toEscapedString());
|
2018-02-26 20:18:36 +00:00
|
|
|
} else {
|
2020-05-15 16:21:45 +00:00
|
|
|
mInitialSearchValue.push(invite.getJid().toEscapedString());
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayVerificationWarningDialog(final Contact contact, final Invite invite) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.verify_omemo_keys);
|
|
|
|
View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null);
|
2018-03-18 08:47:52 +00:00
|
|
|
final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source);
|
|
|
|
TextView warning = view.findViewById(R.id.warning);
|
2018-10-06 15:03:12 +00:00
|
|
|
warning.setText(JidDialog.style(this, R.string.verifying_omemo_keys_trusted_source, contact.getJid().asBareJid().toEscapedString(), contact.getDisplayName()));
|
2018-02-26 20:18:36 +00:00
|
|
|
builder.setView(view);
|
|
|
|
builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
|
|
|
|
if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
|
|
|
|
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
|
|
|
|
}
|
2018-10-19 13:39:31 +00:00
|
|
|
switchToConversationDoNotAppend(contact, invite.getBody());
|
2018-02-26 20:18:36 +00:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.cancel, (dialog, which) -> StartConversationActivity.this.finish());
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
dialog.setOnCancelListener(dialog1 -> StartConversationActivity.this.finish());
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void filter(String needle) {
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
this.filterContacts(needle);
|
|
|
|
this.filterConferences(needle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void filterContacts(String needle) {
|
|
|
|
this.contacts.clear();
|
2018-08-30 16:45:22 +00:00
|
|
|
final List<Account> accounts = xmppConnectionService.getAccounts();
|
|
|
|
for (Account account : accounts) {
|
2018-02-26 20:18:36 +00:00
|
|
|
if (account.getStatus() != Account.State.DISABLED) {
|
|
|
|
for (Contact contact : account.getRoster().getContacts()) {
|
|
|
|
Presence.Status s = contact.getShownStatus();
|
2018-10-31 09:52:14 +00:00
|
|
|
if (contact.showInContactList() && contact.match(this, needle)
|
2018-02-26 20:18:36 +00:00
|
|
|
&& (!this.mHideOfflineContacts
|
|
|
|
|| (needle != null && !needle.trim().isEmpty())
|
|
|
|
|| s.compareTo(Presence.Status.OFFLINE) < 0)) {
|
|
|
|
this.contacts.add(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(this.contacts);
|
|
|
|
mContactsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void filterConferences(String needle) {
|
|
|
|
this.conferences.clear();
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (account.getStatus() != Account.State.DISABLED) {
|
|
|
|
for (Bookmark bookmark : account.getBookmarks()) {
|
|
|
|
if (bookmark.match(this, needle)) {
|
|
|
|
this.conferences.add(bookmark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(this.conferences);
|
|
|
|
mConferenceAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void OnUpdateBlocklist(final Status status) {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
if (mSearchEditText != null) {
|
|
|
|
filter(mSearchEditText.getText().toString());
|
|
|
|
}
|
2018-04-03 15:53:08 +00:00
|
|
|
configureHomeButton();
|
2018-11-07 12:42:01 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
setRefreshing(xmppConnectionService.getQuickConversationsService().isSynchronizing());
|
|
|
|
}
|
2018-04-03 15:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2019-01-27 15:35:55 +00:00
|
|
|
if (binding.speedDial.isOpen()) {
|
|
|
|
binding.speedDial.close();
|
|
|
|
return;
|
|
|
|
}
|
2018-04-03 15:53:08 +00:00
|
|
|
navigateBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void navigateBack() {
|
2018-10-24 11:54:42 +00:00
|
|
|
if (!createdByViewIntent && xmppConnectionService != null && !xmppConnectionService.isConversationsListEmpty(null)) {
|
2018-04-03 15:53:08 +00:00
|
|
|
Intent intent = new Intent(this, ConversationsActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
finish();
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 09:42:01 +00:00
|
|
|
@Override
|
2018-06-24 09:23:10 +00:00
|
|
|
public void onCreateDialogPositiveClick(Spinner spinner, String name) {
|
2018-03-12 09:42:01 +00:00
|
|
|
if (!xmppConnectionServiceBound) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-06 13:45:51 +00:00
|
|
|
final Account account = getSelectedAccount(this, spinner);
|
2018-03-12 09:42:01 +00:00
|
|
|
if (account == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
|
2018-06-24 09:23:10 +00:00
|
|
|
intent.putExtra(ChooseContactActivity.EXTRA_SHOW_ENTER_JID, false);
|
|
|
|
intent.putExtra(ChooseContactActivity.EXTRA_SELECT_MULTIPLE, true);
|
|
|
|
intent.putExtra(ChooseContactActivity.EXTRA_GROUP_CHAT_NAME, name.trim());
|
2020-05-20 18:14:13 +00:00
|
|
|
intent.putExtra(ChooseContactActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString());
|
2018-03-12 09:42:01 +00:00
|
|
|
intent.putExtra(ChooseContactActivity.EXTRA_TITLE_RES_ID, R.string.choose_participants);
|
|
|
|
startActivityForResult(intent, REQUEST_CREATE_CONFERENCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-24 15:29:34 +00:00
|
|
|
public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout layout, AutoCompleteTextView jid, boolean isBookmarkChecked) {
|
2018-03-12 09:42:01 +00:00
|
|
|
if (!xmppConnectionServiceBound) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-06 13:45:51 +00:00
|
|
|
final Account account = getSelectedAccount(this, spinner);
|
2018-03-12 09:42:01 +00:00
|
|
|
if (account == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-24 15:29:34 +00:00
|
|
|
final String input = jid.getText().toString();
|
|
|
|
Jid conferenceJid;
|
2018-03-12 09:42:01 +00:00
|
|
|
try {
|
2020-05-15 17:22:15 +00:00
|
|
|
conferenceJid = Jid.ofEscaped(input);
|
2018-03-12 09:42:01 +00:00
|
|
|
} catch (final IllegalArgumentException e) {
|
2019-09-24 15:29:34 +00:00
|
|
|
final XmppUri xmppUri = new XmppUri(input);
|
2020-01-10 11:51:04 +00:00
|
|
|
if (xmppUri.isValidJid() && xmppUri.isAction(XmppUri.ACTION_JOIN)) {
|
2019-09-24 15:29:34 +00:00
|
|
|
final Editable editable = jid.getEditableText();
|
|
|
|
editable.clear();
|
|
|
|
editable.append(xmppUri.getJid().toEscapedString());
|
|
|
|
conferenceJid = xmppUri.getJid();
|
|
|
|
} else {
|
|
|
|
layout.setError(getString(R.string.invalid_jid));
|
|
|
|
return;
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isBookmarkChecked) {
|
2020-02-16 15:04:42 +00:00
|
|
|
Bookmark bookmark = account.getBookmark(conferenceJid);
|
|
|
|
if (bookmark != null) {
|
|
|
|
dialog.dismiss();
|
|
|
|
openConversationsForBookmark(bookmark);
|
2018-03-12 09:42:01 +00:00
|
|
|
} else {
|
2020-02-16 15:04:42 +00:00
|
|
|
bookmark = new Bookmark(account, conferenceJid.asBareJid());
|
2018-06-23 07:29:29 +00:00
|
|
|
bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin));
|
2019-08-19 11:55:52 +00:00
|
|
|
final String nick = conferenceJid.getResource();
|
|
|
|
if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) {
|
2018-03-12 09:42:01 +00:00
|
|
|
bookmark.setNick(nick);
|
|
|
|
}
|
2019-09-27 22:32:29 +00:00
|
|
|
xmppConnectionService.createBookmark(account, bookmark);
|
2018-03-12 09:42:01 +00:00
|
|
|
final Conversation conversation = xmppConnectionService
|
|
|
|
.findOrCreateConversation(account, conferenceJid, true, true, true);
|
|
|
|
bookmark.setConversation(conversation);
|
|
|
|
dialog.dismiss();
|
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
final Conversation conversation = xmppConnectionService
|
|
|
|
.findOrCreateConversation(account, conferenceJid, true, true, true);
|
|
|
|
dialog.dismiss();
|
|
|
|
switchToConversation(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 07:27:16 +00:00
|
|
|
@Override
|
|
|
|
public void onConversationUpdate() {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:42:01 +00:00
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
|
|
|
Log.d(Config.LOGTAG,"user requested to refresh");
|
|
|
|
if (QuickConversationsService.isQuicksy() && xmppConnectionService != null) {
|
2018-11-07 14:44:39 +00:00
|
|
|
xmppConnectionService.getQuickConversationsService().considerSyncBackground(true);
|
2018-11-07 12:42:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setRefreshing(boolean refreshing) {
|
|
|
|
MyListFragment fragment = (MyListFragment) mListPagerAdapter.getItem(0);
|
|
|
|
if (fragment != null) {
|
|
|
|
fragment.setRefreshing(refreshing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
@Override
|
|
|
|
public void onCreatePublicChannel(Account account, String name, Jid address) {
|
|
|
|
mToast = Toast.makeText(this, R.string.creating_channel, Toast.LENGTH_LONG);
|
|
|
|
mToast.show();
|
|
|
|
xmppConnectionService.createPublicChannel(account, name, address, new UiCallback<Conversation>() {
|
|
|
|
@Override
|
|
|
|
public void success(Conversation conversation) {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
hideToast();
|
|
|
|
switchToConversation(conversation);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int errorCode, Conversation conversation) {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
replaceToast(getString(errorCode));
|
|
|
|
switchToConversation(conversation);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-26 15:40:05 +00:00
|
|
|
public void userInputRequired(PendingIntent pi, Conversation object) {
|
2019-02-06 13:45:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:42:01 +00:00
|
|
|
public static class MyListFragment extends SwipeRefreshListFragment {
|
2018-02-26 20:18:36 +00:00
|
|
|
private AdapterView.OnItemClickListener mOnItemClickListener;
|
|
|
|
private int mResContextMenu;
|
|
|
|
|
|
|
|
public void setContextMenu(final int res) {
|
|
|
|
this.mResContextMenu = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
|
|
|
if (mOnItemClickListener != null) {
|
|
|
|
mOnItemClickListener.onItemClick(l, v, position, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnListItemClickListener(AdapterView.OnItemClickListener l) {
|
|
|
|
this.mOnItemClickListener = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
registerForContextMenu(getListView());
|
|
|
|
getListView().setFastScrollEnabled(true);
|
|
|
|
getListView().setDivider(null);
|
|
|
|
getListView().setDividerHeight(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-24 09:23:10 +00:00
|
|
|
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
|
2018-02-26 20:18:36 +00:00
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
final StartConversationActivity activity = (StartConversationActivity) getActivity();
|
|
|
|
if (activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity.getMenuInflater().inflate(mResContextMenu, menu);
|
|
|
|
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
|
|
|
if (mResContextMenu == R.menu.conference_context) {
|
|
|
|
activity.conference_context_id = acmi.position;
|
2020-02-16 16:30:54 +00:00
|
|
|
final Bookmark bookmark = (Bookmark) activity.conferences.get(acmi.position);
|
|
|
|
final Conversation conversation = bookmark.getConversation();
|
|
|
|
final MenuItem share = menu.findItem(R.id.context_share_uri);
|
|
|
|
share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
|
2018-02-26 20:18:36 +00:00
|
|
|
} else if (mResContextMenu == R.menu.contact_context) {
|
|
|
|
activity.contact_context_id = acmi.position;
|
|
|
|
final Contact contact = (Contact) activity.contacts.get(acmi.position);
|
|
|
|
final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
|
|
|
|
final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
|
2018-08-31 09:04:45 +00:00
|
|
|
final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
|
2018-02-26 20:18:36 +00:00
|
|
|
if (contact.isSelf()) {
|
|
|
|
showContactDetailsItem.setVisible(false);
|
|
|
|
}
|
2018-11-08 11:20:46 +00:00
|
|
|
deleteContactMenuItem.setVisible(contact.showInRoster() && !contact.getOption(Contact.Options.SYNCED_VIA_OTHER));
|
2020-02-16 16:30:54 +00:00
|
|
|
final XmppConnection xmpp = contact.getAccount().getXmppConnection();
|
2018-02-26 20:18:36 +00:00
|
|
|
if (xmpp != null && xmpp.getFeatures().blocking() && !contact.isSelf()) {
|
|
|
|
if (contact.isBlocked()) {
|
|
|
|
blockUnblockItem.setTitle(R.string.unblock_contact);
|
|
|
|
} else {
|
|
|
|
blockUnblockItem.setTitle(R.string.block_contact);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
blockUnblockItem.setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(final MenuItem item) {
|
|
|
|
StartConversationActivity activity = (StartConversationActivity) getActivity();
|
|
|
|
if (activity == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.context_contact_details:
|
|
|
|
activity.openDetailsForContact();
|
|
|
|
break;
|
2018-04-20 15:12:47 +00:00
|
|
|
case R.id.context_show_qr:
|
|
|
|
activity.showQrForContact();
|
|
|
|
break;
|
2018-02-26 20:18:36 +00:00
|
|
|
case R.id.context_contact_block_unblock:
|
|
|
|
activity.toggleContactBlock();
|
|
|
|
break;
|
|
|
|
case R.id.context_delete_contact:
|
|
|
|
activity.deleteContact();
|
|
|
|
break;
|
|
|
|
case R.id.context_share_uri:
|
|
|
|
activity.shareBookmarkUri();
|
|
|
|
break;
|
|
|
|
case R.id.context_delete_conference:
|
|
|
|
activity.deleteConference();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ListPagerAdapter extends PagerAdapter {
|
2018-11-08 11:20:46 +00:00
|
|
|
private final FragmentManager fragmentManager;
|
|
|
|
private final MyListFragment[] fragments;
|
2018-02-26 20:18:36 +00:00
|
|
|
|
2018-10-25 13:31:56 +00:00
|
|
|
ListPagerAdapter(FragmentManager fm) {
|
2018-02-26 20:18:36 +00:00
|
|
|
fragmentManager = fm;
|
|
|
|
fragments = new MyListFragment[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void requestFocus(int pos) {
|
|
|
|
if (fragments.length > pos) {
|
|
|
|
fragments[pos].getListView().requestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
|
|
|
FragmentTransaction trans = fragmentManager.beginTransaction();
|
|
|
|
trans.remove(fragments[position]);
|
|
|
|
trans.commit();
|
|
|
|
fragments[position] = null;
|
|
|
|
}
|
|
|
|
|
2018-10-03 09:53:02 +00:00
|
|
|
@NonNull
|
2018-02-26 20:18:36 +00:00
|
|
|
@Override
|
|
|
|
public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
|
2018-11-17 11:59:19 +00:00
|
|
|
final Fragment fragment = getItem(position);
|
|
|
|
final FragmentTransaction trans = fragmentManager.beginTransaction();
|
2018-02-26 20:18:36 +00:00
|
|
|
trans.add(container.getId(), fragment, "fragment:" + position);
|
2018-11-17 11:59:19 +00:00
|
|
|
try {
|
|
|
|
trans.commit();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
//ignore
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return fragments.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object fragment) {
|
|
|
|
return ((Fragment) fragment).getView() == view;
|
|
|
|
}
|
|
|
|
|
2018-03-18 08:30:22 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public CharSequence getPageTitle(int position) {
|
|
|
|
switch (position) {
|
|
|
|
case 0:
|
|
|
|
return getResources().getString(R.string.contacts);
|
|
|
|
case 1:
|
2019-02-06 13:45:51 +00:00
|
|
|
return getResources().getString(R.string.bookmarks);
|
2018-03-18 08:30:22 +00:00
|
|
|
default:
|
|
|
|
return super.getPageTitle(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 09:53:02 +00:00
|
|
|
Fragment getItem(int position) {
|
2018-02-26 20:18:36 +00:00
|
|
|
if (fragments[position] == null) {
|
|
|
|
final MyListFragment listFragment = new MyListFragment();
|
|
|
|
if (position == 1) {
|
|
|
|
listFragment.setListAdapter(mConferenceAdapter);
|
|
|
|
listFragment.setContextMenu(R.menu.conference_context);
|
|
|
|
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
|
|
|
|
} else {
|
|
|
|
listFragment.setListAdapter(mContactsAdapter);
|
|
|
|
listFragment.setContextMenu(R.menu.contact_context);
|
|
|
|
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
|
2018-11-07 12:42:01 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
|
|
|
listFragment.setOnRefreshListener(StartConversationActivity.this);
|
|
|
|
}
|
2018-02-26 20:18:36 +00:00
|
|
|
}
|
|
|
|
fragments[position] = listFragment;
|
|
|
|
}
|
|
|
|
return fragments[position];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:35:33 +00:00
|
|
|
public static void addInviteUri(Intent to, Intent from) {
|
|
|
|
if (from != null && from.hasExtra(EXTRA_INVITE_URI)) {
|
2020-01-09 14:49:49 +00:00
|
|
|
final String invite = from.getStringExtra(EXTRA_INVITE_URI);
|
|
|
|
to.putExtra(EXTRA_INVITE_URI, invite);
|
2018-10-09 17:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
private class Invite extends XmppUri {
|
|
|
|
|
|
|
|
public String account;
|
|
|
|
|
2020-01-09 14:49:49 +00:00
|
|
|
boolean forceDialog = false;
|
2019-09-24 15:29:34 +00:00
|
|
|
|
2018-02-26 20:18:36 +00:00
|
|
|
|
2020-01-09 14:49:49 +00:00
|
|
|
Invite(final String uri) {
|
2018-02-26 20:18:36 +00:00
|
|
|
super(uri);
|
|
|
|
}
|
|
|
|
|
2020-01-09 14:49:49 +00:00
|
|
|
Invite(Uri uri, boolean safeSource) {
|
2018-02-26 20:18:36 +00:00
|
|
|
super(uri, safeSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean invite() {
|
2020-01-10 11:51:04 +00:00
|
|
|
if (!isValidJid()) {
|
2018-02-26 20:18:36 +00:00
|
|
|
Toast.makeText(StartConversationActivity.this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getJid() != null) {
|
|
|
|
return handleJid(this);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 18:39:15 +00:00
|
|
|
}
|