Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Apr 9, 2016
2 parents ab0a1f0 + b566d82 commit f816325
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class SectionedRecyclerViewAdapter<VH extends RecyclerView.ViewH
private final ArrayMap<Integer, Integer> mHeaderLocationMap;
private GridLayoutManager mLayoutManager;
private ArrayMap<Integer, Integer> mSpanMap;
private boolean mShowHeadersForEmptySections;

public SectionedRecyclerViewAdapter() {
mHeaderLocationMap = new ArrayMap<>();
Expand All @@ -38,6 +39,15 @@ public final boolean isHeader(int position) {
return mHeaderLocationMap.get(position) != null;
}

/**
* Instructs the list view adapter to whether show headers for empty sections or not.
*
* @param show flag indicating whether headers for empty sections ought to be shown.
*/
public final void shouldShowHeadersForEmptySections(boolean show) {
mShowHeadersForEmptySections = show;
}

public final void setLayoutManager(@Nullable GridLayoutManager lm) {
mLayoutManager = lm;
if (lm == null) return;
Expand Down Expand Up @@ -80,7 +90,7 @@ public final int getItemCount() {
mHeaderLocationMap.clear();
for (int s = 0; s < getSectionCount(); s++) {
int itemCount = getItemCount(s);
if (itemCount > 0) {
if (mShowHeadersForEmptySections || (itemCount > 0)) {
mHeaderLocationMap.put(count, s);
count += itemCount + 1;
}
Expand Down Expand Up @@ -156,4 +166,4 @@ else if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager
public final void onBindViewHolder(VH holder, int position, List<Object> payloads) {
super.onBindViewHolder(holder, position, payloads);
}
}
}

0 comments on commit f816325

Please sign in to comment.