# HG changeset patch # User Vincent Veronis # Date 1253829461 -7200 # Node ID be426243b24f6c3f5438262992f1dc54e38e1d06 # Parent 166db9c933351cef7b84ba24ed092255e9c8897d Bug. diff -r 166db9c93335 -r be426243b24f src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Sep 24 23:54:11 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Thu Sep 24 23:57:41 2009 +0200 @@ -1,7 +1,9 @@ package com.beem.project.beem.ui; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -54,12 +56,14 @@ private static final int REQUEST_CODE = 1; private BeemContactList mAdapter; private IRoster mRoster; - private List mListContact; + private List mListContact = new ArrayList(); private List mListGroup; - private Map> mContactOnGroup; + private Map> mContactOnGroup = new HashMap>(); + private String mCurGroup; private Handler mHandler; private IXmppFacade mXmppFacade; private final ServiceConnection mServConn = new BeemServiceConnection(); + private BroadcastReceiver mReceiver; /** * Constructor. @@ -74,8 +78,19 @@ setContentView(R.layout.contactlist); mAdapter = new BeemContactList(this); mHandler = new Handler(); - this.registerReceiver(new BeemBroadcastReceiver(), new IntentFilter(XmppConnectionAdapter.BEEM_CONNECTION_CLOSED)); + mReceiver = new BeemBroadcastReceiver(); + } + @Override + protected void onResume() { + super.onResume(); + this.registerReceiver(mReceiver, new IntentFilter(XmppConnectionAdapter.BEEM_CONNECTION_CLOSED)); + } + + @Override + protected void onPause() { + super.onPause(); + this.unregisterReceiver(mReceiver); } /** @@ -191,23 +206,20 @@ * @param listContact Contact list. * @param listGroup Group list. */ - private void buildContactList(List listContact, List listGroup) { - mListGroup = listGroup; - Collections.sort(mListGroup); - if (mListContact != null) - mListContact.clear(); - for (Contact c : listContact) { - if (c.getGroups().contains(listGroup.get(0))) { - mListContact.add(c); - } + private void buildContactList() { + + if (mCurGroup != null) { + mListContact = mContactOnGroup.get(mCurGroup); } - sortBeemContactList(); ListView listView = (ListView) findViewById(R.id.contactlist); listView.setOnItemClickListener(new BeemContactListOnClick()); listView.setOnItemLongClickListener(new BeemContactListOnLongClick()); listView.setAdapter(mAdapter); + } + + private void buildBanner() { Gallery g = (Gallery) findViewById(R.id.gallery); - g.setOnItemClickListener(new OnSelectedGroupName()); + g.setOnItemClickListener(new OnItemClickGroupName()); g.setAdapter(new BeemBanner(this)); } @@ -261,13 +273,13 @@ /** * Event on middle groupe name. */ - private class OnSelectedGroupName implements OnItemClickListener { + private class OnItemClickGroupName implements OnItemClickListener { @Override - public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { - /* - * TODO: Afficher la liste selon le group - */ + public void onItemClick(AdapterView arg0, View v, int i, long l) { + buildContactList(); + mCurGroup = mListGroup.get(i); + Log.i("OO", "!!"); } } @@ -347,22 +359,10 @@ } @Override -<<<<<<< local public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException { -======= - public void onEntryDeleteFromGroup(String group, String jid) - throws RemoteException { ->>>>>>> other // TODO Auto-generated method stub -<<<<<<< local -======= + } ->>>>>>> other - } -<<<<<<< local - -======= ->>>>>>> other /** * {@inheritDoc} */ @@ -393,11 +393,6 @@ } } } -<<<<<<< local -======= - - ->>>>>>> other } /** @@ -582,7 +577,27 @@ mRoster = mXmppFacade.getRoster(); if (mRoster != null) { mRoster.addRosterListener(mBeemRosterListener); - buildContactList(mRoster.getContactList(), mRoster.getGroupsNames()); + List tmpContactList = mRoster.getContactList(); + List tmpGroupList = mRoster.getGroupsNames(); + Collections.sort(tmpGroupList); + mListGroup = tmpGroupList; + if (tmpGroupList.size() > 0) { + for (String s : tmpGroupList) { + List tmpList = new ArrayList(); + for (Contact c : tmpContactList) { + if (c.getGroups().contains(s)) { + tmpList.add(c); + } + } + mContactOnGroup.put(s, tmpList); + } + mCurGroup = tmpGroupList.get(0); + } else { + mCurGroup = null; + mListContact = tmpContactList; + } + buildBanner(); + buildContactList(); } } catch (RemoteException e) { e.printStackTrace();