cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

A few proposals to improve this library #3

Closed Zeliret closed 8 years ago

Zeliret commented 9 years ago
  1. add swapAdapter() functionality;
  2. setSwipeToDismissCallback() throws a null pointer exception if there is no adapter set;
  3. add getAdapter() method (useful thing);
  4. when no data in the adapter it would be great to show an empty view =)
slidenerd commented 9 years ago

Some from my end as well 1) a swipe to refresh at the bottom , probably instead of the load more,. testgif

2)this effect when you try to do swipe to refresh at the top where you are able to drag the recycler to a bit and then it bounces back to its original place

cymcsg commented 9 years ago

@Zeliret Thank you very much for giving advice.

I think the 2,3,4 suggestions are very useful and I try to add these in next version of the library. I'm a little confused about the first suggestion.What the function swapAdapter() do?

Thanks.

cymcsg commented 9 years ago

@slidenerd Thank you very much. In fact, the suggestion 2 is what I am doing now as I said in the ReadMe Colorful style of Swipe to refresh so I think you will see the feature in 0.3.0 of UltimateRecyclerview.

However,for the suggestion 1 which said a swipe to refresh at the bottom , probably instead of the load more I think the loading more has more situations to be used than swiping to refresh at the bottom. So I don't think it is a good idea to instead of loading but I can manage to set it as a option to choose.

Zeliret commented 9 years ago

@cymcsg There are two methods (setAdapter and swapAdapter) in the RecyclerView. They both call the same internal method but with one little exception. With swapAdapter u can change current adapter with a new one without recreating viewholders if they both are compatible (instances of the same class). When u do this the RecyclerView will animate all changes between both adapters. Actually the swapAdapter method is a better way to change all data at once. Instead of using something like clear+add(array[]) u can just create a new adapter and set it =)

slidenerd commented 9 years ago

There is one thing though, the SwipeToDismiss listener may often be used to delete an item say from a database or a cloud store, if the deletion in the backend is successful then the swipe to dismiss in the front end makes sense, but if in the backend, the delete operation fails for some reason, is it possible to bring the item back in the front end, perhaps a simpe callback that will be triggered where the item is restored and the user can do something about it?

cymcsg commented 9 years ago

@Zeliret OK. As I thought you mean more than the default method so I want to know more about this.Now I see what you mean. I'll add this method in next version.Thank you.

Zeliret commented 9 years ago

@cymcsg Thank you! I'll look forward to it.

cymcsg commented 9 years ago

@slidenerd Good idea! I'll try to achieve the effect but maybe a little longer time. So if you like you can help to implement.

cymcsg commented 9 years ago

Thank you for giving these useful advise. But I wonder why do you deleted them.

2015-03-19 22:45 GMT+08:00 Artem Shalaev notifications@github.com:

Hi @cymcsg https://github.com/cymcsg! A few additions from me:

  1. Proxy method for addOnItemTouchListener. It is a little bit ugly to use myList.mRecyclerView.addOnItemTouchListener =)
  2. Helper methods for the UltimateViewAdapter for example:

public abstract class SimpleAdapter extends UltimateViewAdapter { protected final ArrayList items = new ArrayList<>();

public void add(final T item) {
    int index = items.size();
    items.add(item);
    notifyItemInserted(index);
}

public void remove(final int position) {
    items.remove(position);
    notifyItemRemoved(position);
}

public void remove(final T item) {
    int position = items.indexOf(item);
    remove(position);
}

public void replace(final T[] newItems) {
    clear();
    items.addAll(Arrays.asList(newItems));
    notifyItemRangeInserted(0, newItems.length);
}

public void clear() {
    int count = items.size();
    items.clear();
    notifyItemRangeRemoved(0, count);
}

public T get(final int position) {
    return items.get(position);
}

@Override
public int getAdapterItemCount() {
    return items.size();
}

}

— Reply to this email directly or view it on GitHub https://github.com/cymcsg/UltimateRecyclerView/issues/3#issuecomment-83613153 .

Zeliret commented 9 years ago

@cymcsg Well I wasn't sure enough about second part of my suggestion. Your adapter already has insert, remove and so on method. But if you think that my post was useful I am glad to hear it =) Thank you =)

jjhesk commented 9 years ago

@cymcsg lets add this on the 0.4 milestone