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 8234133b..419ff49d 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; @@ -213,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 * @@ -245,6 +257,27 @@ 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 && id == null) { + return item; + } else if (item.getId() != null && item.getId().equals(id)) { + return item; + } + } + return null; + } + /** * Update last message in dialog and swap item to top of list. * @@ -297,6 +330,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 +346,6 @@ public void setImageLoader(ImageLoader imageLoader) { this.imageLoader = imageLoader; } - /** - * @return registered image loader - */ - public ImageLoader getImageLoader() { - return imageLoader; - } - /** * @return the item click callback. */