private int findAppropIndex(DirectMessage msg) { int toReturn = 0; ArrayList<DirectMessage> itemCache = messages; for (DirectMessage t : itemCache) { if (t.getCreatedAt().after(msg.getCreatedAt())) break; toReturn++; } return toReturn; }
private boolean contains(DirectMessage toFind) { Boolean found = false; ArrayList<DirectMessage> itemCache = messages; for (DirectMessage msg : itemCache) { if (msg.getId() == toFind.getId()) { found = true; break; } } return found; }
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); }