Skip to content

Commit

Permalink
Resolved #281 - Delegate spanSize to IFlexible item
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed Feb 13, 2017
1 parent f156c4c commit 5bc79ac
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,8 @@ protected GridLayoutManager createNewGridLayoutManager() {
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
// NOTE: If you use simple integers to identify the ViewType,
// here, you should use them and not Layout integers
switch (mAdapter.getItemViewType(position)) {
case R.layout.recycler_scrollable_usecase_item:
case R.layout.recycler_scrollable_header_item:
case R.layout.recycler_scrollable_footer_item:
case R.layout.recycler_scrollable_layout_item:
case R.layout.recycler_scrollable_uls_item:
case R.layout.recycler_header_item:
case R.layout.recycler_expandable_header_item:
return mColumnCount;
default:
return 1;
}
//noinspection ConstantConditions
return mAdapter.getItem(position).getSpanSize(mColumnCount, position);
}
});
return gridLayoutManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public void addSubItem(int position, SubItem subItem) {
addSubItem(subItem);
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_expandable_header_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_header_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public ScrollableFooterItem(String id) {
super(id);
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_scrollable_footer_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public ScrollableLayoutItem(String id) {
super(id);
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_scrollable_layout_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public ScrollableULSItem(String id) {
super(id);
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_scrollable_uls_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public ScrollableUseCaseItem(String title, String subTitle) {
setSubtitle(subTitle);
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_scrollable_usecase_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public void setTitle(String title) {
this.title = title;
}

@Override
public int getSpanSize(int spanCount, int position) {
return spanCount;
}

@Override
public int getLayoutRes() {
return R.layout.recycler_staggered_header_item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public void setHidden(boolean hidden) {
mHidden = hidden;
}

@Override
public int getSpanSize(int spanCount, int position) {
return 1;
}

/*--------------------*/
/* SELECTABLE METHODS */
/*--------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public interface IFlexible<VH extends RecyclerView.ViewHolder> {
*/
void setHidden(boolean hidden);

/**
* Individual item's span size.
*
* @param spanCount current column count
* @param position the adapter position of the item
* @return the number of span occupied by the item at position.
*/
int getSpanSize(int spanCount, int position);

/*--------------------*/
/* SELECTABLE METHODS */
/*--------------------*/
Expand All @@ -92,7 +101,6 @@ public interface IFlexible<VH extends RecyclerView.ViewHolder> {
/*-------------------*/
/* TOUCHABLE METHODS */
/*-------------------*/
//TODO: All these methods could be deprecated in favour of the same methods in FlexibleViewHolder

boolean isDraggable();

Expand Down

0 comments on commit 5bc79ac

Please # to comment.