public int add(final DirectMessage[] msges) { int before = items.size(); int added = 0; for (DirectMessage msg : msges) { boolean foundConvo = false; for (DMConversation convo : items) { if (msg.getSenderId() == AccountService.getCurrentAccount().getId()) { if (msg.getRecipientId() == convo.getToId()) foundConvo = true; } else if (msg.getSenderId() == convo.getToId()) foundConvo = true; if (foundConvo) { added++; for (DirectMessage m : convo.getMessages()) { if (m.getId() == msg.getId()) continue; } convo.add(msg); break; } } if (!foundConvo) { long toId = msg.getSenderId(); String toName = msg.getSender().getName(); String toScreen = msg.getSender().getScreenName(); if (toId == AccountService.getCurrentAccount().getId()) { toId = msg.getRecipientId(); toName = msg.getRecipient().getName(); toScreen = msg.getRecipient().getScreenName(); } items.add(new DMConversation(toId, toName, toScreen, msg)); } notifyDataSetChanged(); } if (before == 0) return added; else if (added == before) return 0; else return (items.size() - before); }
public void remove(DMConversation convo) { for (int i = 0; i < items.size(); i++) { if (items.get(i).getToId() == convo.getToId()) { items.remove(i); notifyDataSetChanged(); break; } } }
public boolean update(DMConversation convo) { boolean found = false; for (int i = 0; i < items.size(); i++) { if (items.get(i).getToId() == convo.getToId()) { found = true; items.set(i, convo); notifyDataSetChanged(); break; } } return found; }