AdapterDelegates icon indicating copy to clipboard operation
AdapterDelegates copied to clipboard

SpanSizeLookup and ItemDecoration

Open AlexBlokh opened this issue 8 years ago • 2 comments

Different SpanSizeLookup's and ItemDecoration's(mostly margins for pre/post-lollipop CardViews) is pretty widespreaded business issue, and as long as these guys are the part of RecyclerView gang bang, we should cover them.

I'd like to contribute, as long as I definitely gonna use your lib.

As of ItemDecoration I'd suggest to build something like:

public class ItemDecorationManager extends RecyclerView.ItemDecoration {
    // ... similar stuff to what you got in AbsDelegationAdapter.class

    @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
        RecyclerView.State state) {
      super.getItemOffsets(outRect, view, parent, state);

      for (ItemDecorationDelegate delegate : delegates) {
        if(delegate.isForViewType(...)) delegate.decorate(....);
      }
    }
  }

  public interface ItemDecorationDelegate<T> {
    void decorate(Rect outRect, View view, RecyclerView parent, RecyclerView.State state);
    boolean isForViewType(T item, int position);
  }
}

and then just:

    ItemDecorationManager manager = new ItemDecorationManager();
    manager.addDelegate(delegate1);
    manager.addDelegate(delegate2);
    manager.addDelegate(delegate3);
    manager.addDelegate(delegate4);

    recyclerView.addItemDecoration(manager);  //or we can call it Wrapper

for SpanSizeLookup I'd follow the same approach.

The con of such approach is that we duplicate isForViewType(), so I'd suggest to decouple that logic.

I'd like to talk about the issue, pick the concept and then contribute!

Cheers!

AlexBlokh avatar Oct 09 '16 20:10 AlexBlokh

Hi, I'm glad you want to contribute. Contribution is very welcome!

Regarding: ItemDecorationManager I thought about adding this too, but wasn't sure how to do that best. The question is: Since it's not the responsibility of an adapter does they really belong into this library?

For the SpanSizeLookup, I'm not sure whether or not a simple switch statement is enough (instead of SpanSizeManager and SpanSizeDelegate)

sockeqwe avatar Oct 10 '16 07:10 sockeqwe

I played around in a forked branch and really really like that concept when we have adapter, decorator and spans size lookup built in library, cause now it feels complete. I'm not sure if this is an argument, but.. If there is no such API provided by your library means that people gonna have to implement it by their own or smbdy gonna have to make a SpanSizeLookup / ItemDecoration delegates libraries

AlexBlokh avatar Oct 17 '16 12:10 AlexBlokh