# HG changeset patch # User Da Risk # Date 1274726731 -7200 # Node ID 151841f2b1a165f8686128056dc54ed3a517e6b0 # Parent ea83164648a47587ced90cd716680d76823da2b8 Better implementation of Presence change listener diff -r ea83164648a4 -r 151841f2b1a1 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Mon May 24 20:44:56 2010 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Mon May 24 20:45:31 2010 +0200 @@ -551,25 +551,23 @@ public void onPresenceChanged(PresenceAdapter presence) throws RemoteException { String from = presence.getFrom(); boolean resfound = false; - for (Contact curContact : mListContact) { - if (curContact.getJID().equals(StringUtils.parseBareAddress(from))) { - String pres = StringUtils.parseResource(from); - for (String res : curContact.getMRes()) { - if (res.equals(pres)) { - resfound = true; - break; - } - } - curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom()))); - int status = presence.getStatus(); - if (!resfound && !Status.statusOnline(status)) - curContact.addRes(pres); - else if (resfound && Status.statusOnline(status)) - curContact.delRes(pres); - mHandler.post(new RunnableChange()); - return; + int foundIdx = 0; + boolean found = false; + Contact contact = mRoster.getContact(StringUtils.parseBareAddress(from)); + for (int i = 0; i < mListContact.size(); i++) { + Contact curContact = mListContact.get(i); + if (curContact.getJID().equals(contact.getJID())) { + found = true; + foundIdx = i; + break; } } + if (found){ + mListContact.set(foundIdx, contact); + } else { + mListContact.add(contact); + } + mHandler.post(new RunnableChange()); } }