Skip to content

Commit

Permalink
Merge pull request #70 from philippeauriach/allow-moving-item
Browse files Browse the repository at this point in the history
Allow moving Dialog item and get Dialog by id
  • Loading branch information
bevzaanton authored Jul 10, 2018
2 parents fe3d1af + f268da6 commit 0bef64c
Showing 1 changed file with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -297,6 +330,13 @@ public void sort(Comparator<DIALOG> comparator) {
notifyDataSetChanged();
}

/**
* @return registered image loader
*/
public ImageLoader getImageLoader() {
return imageLoader;
}

/**
* Register a callback to be invoked when image need to load.
*
Expand All @@ -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.
*/
Expand Down

0 comments on commit 0bef64c

Please sign in to comment.