@Test public void testShouldUpdateUserPresence() throws Exception { ContactsAdapter adapter = new ContactsAdapter(application, true); final AccountData ad = getAccountData1(); final List<User> contacts = ad.getContacts(); final Map<User, ContactListItem> contactListItems = new HashMap<User, ContactListItem>(); for (User contact : contacts) { contactListItems.put(contact, ContactListItem.loadContactListItem(contact)); } adapter.addAll(contactListItems.values()); final List<User> expectedContacts = new ArrayList<User>(contacts.size()); for (User contact : contacts) { expectedContacts.add(contact.cloneWithNewStatus(!contact.isOnline())); } adapter.onEvent(contacts_presence_changed.newEvent(ad.getAccount().getUser(), expectedContacts)); for (User expectedContact : expectedContacts) { final ContactListItem li = contactListItems.get(expectedContact); assertTrue(areEqual(expectedContact, li.getContact(), new UserSameEqualizer())); } }
public void onEvent(@Nonnull ChatEvent event) { final Chat eventChat = event.getChat(); switch (event.getType()) { case last_message_changed: if (recentContacts && eventChat.isPrivate()) { final Message lastMessage = event.getDataAsMessage(); final DateTime lastMessageDate = lastMessage.getSendDate(); final Entity participant = eventChat.getSecondUser(); final ContactListItem listItem = findInAllElements(newEmptyUser(participant)); if (listItem != null) { listItem.onLastMessageDataChanged(lastMessageDate); sort(getComparator()); } else { final int count = getCount(); if (count > 0) { final ContactListItem lastItem = getItem(count - 1); if (compareSendDatesLatestFirst(lastItem.getData().getLastMessageDate(), lastMessageDate) <= 0) { addListItem(participant, lastMessageDate); } } else { addListItem(participant, lastMessageDate); } } } break; } }
ContactsAdapter extends BaseContactsAdapter { public void onEvent(@Nonnull ChatEvent event) { final Chat eventChat = event.getChat(); switch (event.getType()) { case last_message_changed: if (recentContacts && eventChat.isPrivate()) { final Message lastMessage = event.getDataAsMessage(); final DateTime lastMessageDate = lastMessage.getSendDate(); final Entity participant = eventChat.getSecondUser(); final ContactListItem listItem = findInAllElements(newEmptyUser(participant)); if (listItem != null) { listItem.onLastMessageDataChanged(lastMessageDate); sort(getComparator()); } else { final int count = getCount(); if (count > 0) { final ContactListItem lastItem = getItem(count - 1); if (compareSendDatesLatestFirst(lastItem.getData().getLastMessageDate(), lastMessageDate) <= 0) { addListItem(participant, lastMessageDate); } } else { addListItem(participant, lastMessageDate); } } } break; } } }
ContactsAdapter extends BaseContactsAdapter { public void onEvent(@Nonnull ChatEvent event) { final Chat eventChat = event.getChat(); switch (event.getType()) { case last_message_changed: if (recentContacts && eventChat.isPrivate()) { final Message lastMessage = event.getDataAsMessage(); final DateTime lastMessageDate = lastMessage.getSendDate(); final Entity participant = eventChat.getSecondUser(); final ContactListItem listItem = findInAllElements(newEmptyUser(participant)); if (listItem != null) { listItem.onLastMessageDataChanged(lastMessageDate); sort(getComparator()); } else { final int count = getCount(); if (count > 0) { final ContactListItem lastItem = getItem(count - 1); if (compareSendDatesLatestFirst(lastItem.getData().getLastMessageDate(), lastMessageDate) <= 0) { addListItem(participant, lastMessageDate); } } else { addListItem(participant, lastMessageDate); } } } break; } } ContactsAdapter(@Nonnull Context context, boolean recentContacts); }
ContactsAdapter extends BaseContactsAdapter { public void onEvent(@Nonnull ChatEvent event) { final Chat eventChat = event.getChat(); switch (event.getType()) { case last_message_changed: if (recentContacts && eventChat.isPrivate()) { final Message lastMessage = event.getDataAsMessage(); final DateTime lastMessageDate = lastMessage.getSendDate(); final Entity participant = eventChat.getSecondUser(); final ContactListItem listItem = findInAllElements(newEmptyUser(participant)); if (listItem != null) { listItem.onLastMessageDataChanged(lastMessageDate); sort(getComparator()); } else { final int count = getCount(); if (count > 0) { final ContactListItem lastItem = getItem(count - 1); if (compareSendDatesLatestFirst(lastItem.getData().getLastMessageDate(), lastMessageDate) <= 0) { addListItem(participant, lastMessageDate); } } else { addListItem(participant, lastMessageDate); } } } break; } } ContactsAdapter(@Nonnull Context context, boolean recentContacts); void setRecentContacts(boolean recentContacts); void onEvent(@Nonnull ChatEvent event); }
ContactsAdapter extends BaseContactsAdapter { public void onEvent(@Nonnull ChatEvent event) { final Chat eventChat = event.getChat(); switch (event.getType()) { case last_message_changed: if (recentContacts && eventChat.isPrivate()) { final Message lastMessage = event.getDataAsMessage(); final DateTime lastMessageDate = lastMessage.getSendDate(); final Entity participant = eventChat.getSecondUser(); final ContactListItem listItem = findInAllElements(newEmptyUser(participant)); if (listItem != null) { listItem.onLastMessageDataChanged(lastMessageDate); sort(getComparator()); } else { final int count = getCount(); if (count > 0) { final ContactListItem lastItem = getItem(count - 1); if (compareSendDatesLatestFirst(lastItem.getData().getLastMessageDate(), lastMessageDate) <= 0) { addListItem(participant, lastMessageDate); } } else { addListItem(participant, lastMessageDate); } } } break; } } ContactsAdapter(@Nonnull Context context, boolean recentContacts); void setRecentContacts(boolean recentContacts); void onEvent(@Nonnull ChatEvent event);  }