aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui/StartConversation.java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-07-07 09:32:10 +0200
committeriNPUTmice <daniel@gultsch.de>2014-07-10 00:53:44 +0200
commit3bdf84b6a0170264a20795e7956a68421f312fa3 (patch)
tree68960dec005e33dbae93ec7b7600e1c3ed1b93fa /src/eu/siacs/conversations/ui/StartConversation.java
parent7c3f3b2a3e878b1b1cfdcca102a38efe033dc6b7 (diff)
filter contacts and starting confercenes
Diffstat (limited to 'src/eu/siacs/conversations/ui/StartConversation.java')
-rw-r--r--src/eu/siacs/conversations/ui/StartConversation.java171
1 files changed, 156 insertions, 15 deletions
diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java
index ba603819..3cf09a97 100644
--- a/src/eu/siacs/conversations/ui/StartConversation.java
+++ b/src/eu/siacs/conversations/ui/StartConversation.java
@@ -1,44 +1,71 @@
package eu.siacs.conversations.ui;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
+import android.content.Context;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.MenuItem.OnActionExpandListener;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.SearchView;
+import android.widget.SearchView.OnQueryTextListener;
+import android.widget.TextView;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Contact;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.ListItem;
+import eu.siacs.conversations.utils.UIHelper;
public class StartConversation extends XmppActivity {
private Tab mContactsTab;
private Tab mConferencesTab;
private ViewPager mViewPager;
- private ListFragment mContactsListFragment = new ListFragment();
- private ListFragment mConferenceListFragment = new ListFragment();
+ private SearchView mSearchView;
+
+ private MyListFragment mContactsListFragment = new MyListFragment();
+ private List<ListItem> contacts = new ArrayList<ListItem>();
+ private ArrayAdapter<ListItem> mContactsAdapter;
+
+ private MyListFragment mConferenceListFragment = new MyListFragment();
+ private List<ListItem> conferences = new ArrayList<ListItem>();
+ private ArrayAdapter<ListItem> mConferenceAdapter;
private TabListener mTabListener = new TabListener() {
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
- // TODO Auto-generated method stub
-
+ return;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
- invalidateOptionsMenu();
+ onTabChanged();
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
- // TODO Auto-generated method stub
-
+ return;
}
};
@@ -46,7 +73,33 @@ public class StartConversation extends XmppActivity {
@Override
public void onPageSelected(int position) {
getActionBar().setSelectedNavigationItem(position);
+ onTabChanged();
+ }
+ };
+ private OnQueryTextListener mOnQueryTextListener = new OnQueryTextListener() {
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ return true;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ filterContacts(newText);
+ return true;
+ }
+ };
+ private OnActionExpandListener mOnSearchActionExpandListener = new OnActionExpandListener() {
+
+ @Override
+ public boolean onMenuItemActionExpand(MenuItem item) {
+ return true;
+ }
+
+ @Override
+ public boolean onMenuItemActionCollapse(MenuItem item) {
invalidateOptionsMenu();
+ return true;
}
};
@@ -65,18 +118,17 @@ public class StartConversation extends XmppActivity {
actionBar.addTab(mContactsTab);
actionBar.addTab(mConferencesTab);
-
mViewPager.setOnPageChangeListener(mOnPageChangeListener);
mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
-
+
@Override
public int getCount() {
return 2;
}
-
+
@Override
public Fragment getItem(int position) {
- if (position==0) {
+ if (position == 0) {
return mContactsListFragment;
} else {
return mConferenceListFragment;
@@ -84,18 +136,44 @@ public class StartConversation extends XmppActivity {
}
});
+ mConferenceAdapter = new ListItemAdapter(conferences);
+ mConferenceListFragment.setListAdapter(mConferenceAdapter);
+
+ mContactsAdapter = new ListItemAdapter(contacts);
+ mContactsListFragment.setListAdapter(mContactsAdapter);
+ mContactsListFragment
+ .setOnListItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1,
+ int position, long arg3) {
+ Contact contact = (Contact) contacts.get(position);
+ Conversation conversation = xmppConnectionService
+ .findOrCreateConversation(contact.getAccount(),
+ contact.getJid(), false);
+ switchToConversation(conversation, null, false);
+ }
+ });
+
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.start_conversation, menu);
- MenuItem menuCreateContact = (MenuItem) menu.findItem(R.id.action_create_contact);
- MenuItem menuCreateConference = (MenuItem) menu.findItem(R.id.action_create_conference);
+ MenuItem menuCreateContact = (MenuItem) menu
+ .findItem(R.id.action_create_contact);
+ MenuItem menuCreateConference = (MenuItem) menu
+ .findItem(R.id.action_create_conference);
+ MenuItem menuSearch = (MenuItem) menu.findItem(R.id.action_search);
if (getActionBar().getSelectedNavigationIndex() == 0) {
menuCreateConference.setVisible(false);
} else {
menuCreateContact.setVisible(false);
}
+ mSearchView = (SearchView) menuSearch.getActionView();
+ mSearchView.setOnQueryTextListener(this.mOnQueryTextListener);
+ menuSearch
+ .setOnActionExpandListener(this.mOnSearchActionExpandListener);
return true;
}
@@ -110,8 +188,71 @@ public class StartConversation extends XmppActivity {
@Override
void onBackendConnected() {
- // TODO Auto-generated method stub
+ filterContacts(null);
+ }
+
+ protected void filterContacts(String needle) {
+ this.contacts.clear();
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (account.getStatus() != Account.STATUS_DISABLED) {
+ for (Contact contact : account.getRoster().getContacts()) {
+ if (contact.showInRoster() && contact.match(needle)) {
+ this.contacts.add(contact);
+ }
+ }
+ }
+ }
+ Collections.sort(this.contacts);
+ mContactsAdapter.notifyDataSetChanged();
+ }
+
+ private void onTabChanged() {
+ if (mSearchView == null || mSearchView.isIconified()) {
+ invalidateOptionsMenu();
+ }
+ }
+
+ private class ListItemAdapter extends ArrayAdapter<ListItem> {
+
+ public ListItemAdapter(List<ListItem> objects) {
+ super(getApplicationContext(), 0, objects);
+ }
+ @Override
+ public View getView(int position, View view, ViewGroup parent) {
+ LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ ListItem item = getItem(position);
+ if (view == null) {
+ view = (View) inflater.inflate(R.layout.contact, null);
+ }
+ TextView name = (TextView) view
+ .findViewById(R.id.contact_display_name);
+ TextView jid = (TextView) view.findViewById(R.id.contact_jid);
+ ImageView picture = (ImageView) view
+ .findViewById(R.id.contact_photo);
+
+ jid.setText(item.getJid());
+ name.setText(item.getDisplayName());
+ picture.setImageBitmap(UIHelper.getContactPicture(item, 48,
+ this.getContext(), false));
+ return view;
+ }
+
+ }
+
+ public static class MyListFragment extends ListFragment {
+ private AdapterView.OnItemClickListener mOnItemClickListener;
+
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ if (mOnItemClickListener != null) {
+ mOnItemClickListener.onItemClick(l, v, position, id);
+ }
+ }
+
+ public void setOnListItemClickListener(AdapterView.OnItemClickListener l) {
+ this.mOnItemClickListener = l;
+ }
}
}