2014-07-16 22:03:37 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.AdapterView;
|
2014-12-21 20:43:58 +00:00
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2014-07-16 22:03:37 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.ListItem;
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-12-21 20:43:58 +00:00
|
|
|
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
2014-07-16 22:03:37 +00:00
|
|
|
@Override
|
2014-12-21 20:43:58 +00:00
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
2014-07-16 22:03:37 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2014-12-21 20:43:58 +00:00
|
|
|
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
2014-07-16 22:03:37 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-21 20:43:58 +00:00
|
|
|
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(),
|
2014-07-16 22:03:37 +00:00
|
|
|
InputMethodManager.HIDE_IMPLICIT_ONLY);
|
2014-12-21 20:43:58 +00:00
|
|
|
final Intent request = getIntent();
|
|
|
|
final Intent data = new Intent();
|
|
|
|
final ListItem mListItem = getListItems().get(position);
|
2014-11-06 19:45:38 +00:00
|
|
|
data.putExtra("contact", mListItem.getJid().toString());
|
2014-09-02 13:51:20 +00:00
|
|
|
String account = request.getStringExtra("account");
|
2014-09-08 21:58:37 +00:00
|
|
|
if (account == null && mListItem instanceof Contact) {
|
2014-11-09 15:57:22 +00:00
|
|
|
account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
|
2014-09-02 13:51:20 +00:00
|
|
|
}
|
|
|
|
data.putExtra("account", account);
|
2014-08-31 14:28:21 +00:00
|
|
|
data.putExtra("conversation",
|
|
|
|
request.getStringExtra("conversation"));
|
2014-07-16 22:03:37 +00:00
|
|
|
setResult(RESULT_OK, data);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-16 22:03:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 20:43:58 +00:00
|
|
|
protected void filterContacts(final String needle) {
|
|
|
|
getListItems().clear();
|
|
|
|
for (final Account account : xmppConnectionService.getAccounts()) {
|
2014-11-15 16:09:02 +00:00
|
|
|
if (account.getStatus() != Account.State.DISABLED) {
|
2014-12-21 20:43:58 +00:00
|
|
|
for (final Contact contact : account.getRoster().getContacts()) {
|
2014-07-16 22:03:37 +00:00
|
|
|
if (contact.showInRoster() && contact.match(needle)) {
|
2014-12-21 20:43:58 +00:00
|
|
|
getListItems().add(contact);
|
2014-07-16 22:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-21 20:43:58 +00:00
|
|
|
Collections.sort(getListItems());
|
|
|
|
getListItemAdapter().notifyDataSetChanged();
|
2014-07-16 22:03:37 +00:00
|
|
|
}
|
|
|
|
}
|