From 25ec6be9ce373e941ebad9ff254d7cb9fc5962aa Mon Sep 17 00:00:00 2001
From: Philippe Auriach
Date: Wed, 9 Aug 2017 10:13:18 +0200
Subject: [PATCH 1/5] added get item by id method
---
.../chatkit/dialogs/DialogsListAdapter.java | 38 +++++++++++++++----
1 file changed, 31 insertions(+), 7 deletions(-)
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 9638ff7e..697ad343 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
@@ -19,6 +19,7 @@
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.LayoutRes;
+import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -245,6 +246,29 @@ public void updateItemById(DIALOG item) {
}
}
+ /**
+ * Find an item by its id
+ *
+ * @param id the wanted item's id
+ * @return the found item, or null
+ */
+ @Nullable
+ public DIALOG getItemById(String id) {
+ if (items == null) {
+ items = new ArrayList<>();
+ }
+ for (DIALOG item : items) {
+ if (item.getId() == null) {
+ if (id == null) {
+ return item;
+ }
+ } else if (item.getId().equals(id)) {
+ return item;
+ }
+ }
+ return null;
+ }
+
/**
* Update last message in dialog and swap item to top of list.
*
@@ -297,6 +321,13 @@ public void sort(Comparator