Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpanSizeLookup and ItemDecoration #25

Open
AlexBlokh opened this issue Oct 9, 2016 · 2 comments
Open

SpanSizeLookup and ItemDecoration #25

AlexBlokh opened this issue Oct 9, 2016 · 2 comments

Comments

@AlexBlokh
Copy link

AlexBlokh commented Oct 9, 2016

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!

@sockeqwe
Copy link
Owner

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)

@AlexBlokh
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants