# HG changeset patch # User J. Da Silva # Date 1246001959 -7200 # Node ID 9236b57675c9560e2290bebd248c1a764dbca808 # Parent 78ce8be73f4727cc9a0ebaa4e919d06a017a6b6b# Parent 5427deeda4e0ce3dcc264b9e56dca63e4db623f6 Merge diff -r 78ce8be73f47 -r 9236b57675c9 AndroidManifest.xml --- a/AndroidManifest.xml Thu Jun 25 12:24:16 2009 +0200 +++ b/AndroidManifest.xml Fri Jun 26 09:39:19 2009 +0200 @@ -35,6 +35,6 @@ - + diff -r 78ce8be73f47 -r 9236b57675c9 src/com/beem/project/beem/service/Contact.java diff -r 78ce8be73f47 -r 9236b57675c9 src/com/beem/project/beem/service/RosterAdapter.java --- a/src/com/beem/project/beem/service/RosterAdapter.java Thu Jun 25 12:24:16 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Fri Jun 26 09:39:19 2009 +0200 @@ -3,11 +3,10 @@ */ package com.beem.project.beem.service; + import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.RosterEntry; @@ -33,8 +32,6 @@ private Roster mAdaptee; private RemoteCallbackList mRemoteRosListeners = new RemoteCallbackList(); - private Map mContacts = new HashMap(); - private RosterListenerAdapter mRosterListener = new RosterListenerAdapter(); /** @@ -44,13 +41,6 @@ public RosterAdapter(final Roster roster) { mAdaptee = roster; roster.addRosterListener(mRosterListener); - for (RosterEntry entry : roster.getEntries()) { - String user = StringUtils.parseBareAddress(entry.getUser()); - if (!mContacts.containsKey(user)) { - Contact c = getContactFromRosterEntry(entry); - mContacts.put(user, c); - } - } } /** @@ -67,20 +57,13 @@ */ @Override public Contact addContact(String user, String name, String[] groups) throws RemoteException { - Contact res = null; RosterEntry contact = mAdaptee.getEntry(user); - if (contact != null) { - res = mContacts.get(user); - } else { - try { - mAdaptee.createEntry(user, name, groups); - contact = mAdaptee.getEntry(user); - res = new Contact(user); - mContacts.put(user, res); - } catch (XMPPException e) { - Log.e(TAG, "Error while adding new contact", e); - return null; - } + try { + mAdaptee.createEntry(user, name, groups); + contact = mAdaptee.getEntry(user); + } catch (XMPPException e) { + Log.e(TAG, "Error while adding new contact", e); + return null; } if (groups != null) { for (String groupStr : groups) { @@ -92,11 +75,11 @@ group.addEntry(contact); } catch (XMPPException e) { e.printStackTrace(); + return null; } - res.addGroup(groupStr); } } - return res; + return getContactFromRosterEntry(contact); } /** @@ -107,10 +90,8 @@ try { RosterEntry entry = mAdaptee.getEntry(contact.getJID()); if (entry.getGroups().size() == 0) { - mContacts.remove(contact.getJID()); mAdaptee.removeEntry(entry); } else { - mContacts.get(contact.getJID()).delGroup(group); mAdaptee.getGroup(group).removeEntry(entry); mRosterListener.onEntryDeleteFromGroup(group, contact.getJID()); } @@ -124,8 +105,11 @@ */ @Override public void createGroup(String groupname) throws RemoteException { - if (!mAdaptee.contains(groupname)) + try { mAdaptee.createGroup(groupname); + } catch (IllegalArgumentException e) { + //pas grave, plus simple a gerer comme ca. + } } /** @@ -133,7 +117,9 @@ */ @Override public Contact getContact(String jid) throws RemoteException { - return mContacts.get(jid); + if (mAdaptee.contains(jid)) + return getContactFromRosterEntry(mAdaptee.getEntry(jid)); + return null; } /** @@ -141,9 +127,11 @@ */ @Override public List getContactList() throws RemoteException { - List res = new ArrayList(); - res.addAll(mContacts.values()); - return res; + List coList= new ArrayList (mAdaptee.getEntries().size()); + for(RosterEntry entry: mAdaptee.getEntries()){ + coList.add(getContactFromRosterEntry(entry)); + } + return coList; } /** @@ -173,7 +161,6 @@ */ @Override public void setContactName(String jid, String name) throws RemoteException { - mContacts.get(jid).setName(name); mAdaptee.getEntry(jid).setName(name); } @@ -287,16 +274,6 @@ @Override public void presenceChanged(Presence presence) { Log.i(TAG, "presence Changed"); - String user = StringUtils.parseBareAddress(presence.getFrom()); - Contact c = mContacts.get(StringUtils.parseBareAddress(user)); - if (c == null) { - c = new Contact(user); - mContacts.put(user, c); - } - c.addRes(StringUtils.parseResource(presence.getFrom())); - c.setStatus(mAdaptee.getPresence(presence.getFrom())); - c.setMsgState(presence.getStatus()); - c.setName(mAdaptee.getEntry(user).getName()); /* redispatch vers les IBeemRosterListener */ final int n = mRemoteRosListeners.beginBroadcast(); diff -r 78ce8be73f47 -r 9236b57675c9 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Jun 25 12:24:16 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Fri Jun 26 09:39:19 2009 +0200 @@ -171,15 +171,17 @@ @Override public void onEntriesAdded(List addresses) throws RemoteException { - Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED()"); + Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED()"+ addresses.size()); for (String str : addresses) { Contact curContact = mRoster.getContact(str); + Log.d("CONTACTLIST", "DEBUG - ONENTRIESADDED() group size " + curContact.getGroups().size() ); for (String group : curContact.getGroups()) { if (!groupMap.containsKey(group)) { groupMap.put(group, new ArrayList()); groupName.add(group); } try { + Log.d("CONTACTLIST", "DEBUG - ONENTRIESADD"); groupMap.get(group).add(curContact); } catch (NullPointerException e) { Log.e(TAG, "Failed to find group in groupMap", e); @@ -215,6 +217,7 @@ if (!groupMap.containsKey(group)) { groupMap.put(group, new ArrayList()); groupName.add(group); + Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() found"); groupMap.get(group).add(curContact); } else { boolean found = false; @@ -224,8 +227,10 @@ break; } } - if (!found) + if (!found) { + Log.d("CONTACTLIST", "DEBUG - ONENTRIESUPDATED() not found"); groupMap.get(group).add(curContact); + } } } } @@ -352,13 +357,18 @@ break; default: imageDrawable = getResources().getDrawable(R.drawable.error); - break; + break; } imgV.setImageDrawable(imageDrawable); - - if (v != null) { - v.setText(curContact.getName()); + + String mContactName = curContact.getName(); + if ("".equals(mContactName)) { + mContactName = curContact.getJID(); + mContactName = StringUtils.parseName(mContactName); + if ("".equals(mContactName)) + mContactName = curContact.getJID(); } + v.setText(mContactName); v = (TextView) view.findViewById(R.id.contactlistmsgperso); if (v != null) {