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 comparator) { notifyDataSetChanged(); } + /** + * @return registered image loader + */ + public ImageLoader getImageLoader() { + return imageLoader; + } + /** * Register a callback to be invoked when image need to load. * @@ -306,13 +337,6 @@ public void setImageLoader(ImageLoader imageLoader) { this.imageLoader = imageLoader; } - /** - * @return registered image loader - */ - public ImageLoader getImageLoader() { - return imageLoader; - } - /** * @return the item click callback. */ From b80f3a336a2702eb56191f206592e613b28420d0 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 10:38:49 +0200 Subject: [PATCH 2/5] allow moving an item from position x to position y --- .../stfalcon/chatkit/dialogs/DialogsListAdapter.java | 11 +++++++++++ 1 file changed, 11 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 697ad343..4fcad21e 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -214,6 +214,17 @@ public void addItem(int position, DIALOG dialog) { notifyItemInserted(position); } + /** + * Move an item + * @param fromPosition the actual position of the item + * @param toPosition the new position of the item + */ + public void moveItem(int fromPosition, int toPosition) { + DIALOG dialog = items.remove(fromPosition); + items.add(toPosition, dialog); + notifyItemMoved(fromPosition, toPosition); + } + /** * Update dialog by position in dialogs list * From f2e5cc7ce237130799b365ddd705448fe07b877e Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 11:24:42 +0200 Subject: [PATCH 3/5] test jitpack compile --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index f0f8043a..111c8fe5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':sample', ':chatkit' +include 'chatkit' From f906bb2db76ce8bfe0ac6b6c06342eda937e7cc2 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 11:26:55 +0200 Subject: [PATCH 4/5] Revert "test jitpack compile" This reverts commit f2e5cc7ce237130799b365ddd705448fe07b877e. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 111c8fe5..f0f8043a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'chatkit' +include ':sample', ':chatkit' From f268da6959a9081165a763bc9735cb73066755e2 Mon Sep 17 00:00:00 2001 From: Philippe Auriach Date: Wed, 9 Aug 2017 14:49:42 +0200 Subject: [PATCH 5/5] please codebeat --- .../com/stfalcon/chatkit/dialogs/DialogsListAdapter.java | 8 +++----- 1 file changed, 3 insertions(+), 5 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 4fcad21e..78636868 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -269,11 +269,9 @@ public DIALOG getItemById(String id) { items = new ArrayList<>(); } for (DIALOG item : items) { - if (item.getId() == null) { - if (id == null) { - return item; - } - } else if (item.getId().equals(id)) { + if (item.getId() == null && id == null) { + return item; + } else if (item.getId() != null && item.getId().equals(id)) { return item; } }