From 22545932c710e06e089e01fe8a9d526c4abbfd36 Mon Sep 17 00:00:00 2001 From: Mathieu Rul Date: Tue, 28 Aug 2018 10:18:40 +0200 Subject: [PATCH] Add upsert method to dialogs list --- .../chatkit/dialogs/DialogsListAdapter.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java index eaa8b47f..2ebdbfa7 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -257,6 +257,26 @@ public void updateItemById(DIALOG item) { } } + /** + * Upsert dialog in dialogs list or add it to then end of dialogs list + * + * @param item dialog item + */ + public void upsertItem(DIALOG item) { + boolean updated = false; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getId().equals(item.getId())) { + items.set(i, item); + notifyItemChanged(i); + updated = true; + break; + } + } + if (!updated) { + addItem(item); + } + } + /** * Find an item by its id *