aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java125
1 files changed, 20 insertions, 105 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
index e7254933..70b353c6 100644
--- a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
@@ -1,101 +1,33 @@
package eu.siacs.conversations.ui;
-import java.util.ArrayList;
-import java.util.Collections;
-
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.ListView;
-import eu.siacs.conversations.R;
+
+import java.util.Collections;
+
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.ListItem;
-import eu.siacs.conversations.ui.adapter.ListItemAdapter;
-
-public class ChooseContactActivity extends XmppActivity {
-
- private ListView mListView;
- private ArrayList<ListItem> contacts = new ArrayList<>();
- private ArrayAdapter<ListItem> mContactsAdapter;
-
- private EditText mSearchEditText;
-
- private TextWatcher mSearchTextWatcher = new TextWatcher() {
-
- @Override
- public void afterTextChanged(Editable editable) {
- filterContacts(editable.toString());
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before,
- int count) {
- }
- };
-
- private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
-
- @Override
- public boolean onMenuItemActionExpand(MenuItem item) {
- mSearchEditText.post(new Runnable() {
-
- @Override
- public void run() {
- mSearchEditText.requestFocus();
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(mSearchEditText,
- InputMethodManager.SHOW_IMPLICIT);
- }
- });
-
- return true;
- }
-
- @Override
- public boolean onMenuItemActionCollapse(MenuItem item) {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(),
- InputMethodManager.HIDE_IMPLICIT_ONLY);
- mSearchEditText.setText("");
- filterContacts(null);
- return true;
- }
- };
+public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override
- public void onCreate(Bundle savedInstanceState) {
+ public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_choose_contact);
- mListView = (ListView) findViewById(R.id.choose_contact_list);
- mListView.setFastScrollEnabled(true);
- mContactsAdapter = new ListItemAdapter(this, contacts);
- mListView.setAdapter(mContactsAdapter);
- mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int position, long arg3) {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(),
+ public void onItemClick(final AdapterView<?> parent, final View view,
+ final int position, final long id) {
+ final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(),
InputMethodManager.HIDE_IMPLICIT_ONLY);
- Intent request = getIntent();
- Intent data = new Intent();
- ListItem mListItem = contacts.get(position);
+ final Intent request = getIntent();
+ final Intent data = new Intent();
+ final ListItem mListItem = getListItems().get(position);
data.putExtra("contact", mListItem.getJid().toString());
String account = request.getStringExtra("account");
if (account == null && mListItem instanceof Contact) {
@@ -108,38 +40,21 @@ public class ChooseContactActivity extends XmppActivity {
finish();
}
});
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.choose_contact, menu);
- MenuItem menuSearchView = menu.findItem(R.id.action_search);
- View mSearchView = menuSearchView.getActionView();
- mSearchEditText = (EditText) mSearchView
- .findViewById(R.id.search_field);
- mSearchEditText.addTextChangedListener(mSearchTextWatcher);
- menuSearchView.setOnActionExpandListener(mOnActionExpandListener);
- return true;
}
- @Override
- void onBackendConnected() {
- filterContacts(null);
- }
-
- protected void filterContacts(String needle) {
- this.contacts.clear();
- for (Account account : xmppConnectionService.getAccounts()) {
+ protected void filterContacts(final String needle) {
+ getListItems().clear();
+ for (final Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
- for (Contact contact : account.getRoster().getContacts()) {
+ for (final Contact contact : account.getRoster().getContacts()) {
if (contact.showInRoster() && contact.match(needle)) {
- this.contacts.add(contact);
+ getListItems().add(contact);
}
}
}
}
- Collections.sort(this.contacts);
- mContactsAdapter.notifyDataSetChanged();
+ Collections.sort(getListItems());
+ getListItemAdapter().notifyDataSetChanged();
}
-
}