There is a sqlite database containing a table with messages, which is periodically synchronized with the global database.
Sampling is made from it.
Cursor loadInBackground(){ Log.d("[MESSAGES QUERY]", MessagesTable.STATUS + sortByStatus + " AND " + MessagesTable.DATE + sortByDate); return helper.getReadableDatabase().query(MessagesTable.TABLE_NAME, new String[]{MessagesTable.ID, MessagesTable.BODY, MessagesTable.DATE, MessagesTable.FROM, MessagesTable.TO, MessagesTable.STATUS}, MessagesTable.STATUS + sortByStatus + " AND " + MessagesTable.DATE + sortByDate, null, null, null, null); and loaded into the ListView using the CursorAdapter
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { adapter.changeCursor(data); } The program displays a list of messages. By clicking on any item in the list, the user enters the chat.
And now, in fact, the idea is ripe to display not the entire list of messages, but the list of dialogues - only the last one for each interlocutor.
Actually the question is how best to implement it?
Is it possible to sample the last message by date for each unique interlocutor id, if the number and id of interlocutors are unknown in advance? But even when a new message arrives, the desired list item should be deleted and added updated at the top of the list. How do you do this? I really do not want to invent a five-wheeled bicycle, a task like the typical one.