@ -76,14 +76,17 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
protected ViewHolder getHeader ( RecyclerView parent , StickyHeaderAdapter adapter , int position ) {
protected ViewHolder getHeader ( RecyclerView parent , StickyHeaderAdapter adapter , int position ) {
final long key = adapter . getHeaderId ( position ) ;
final long key = adapter . getHeaderId ( position ) ;
if ( headerCache . containsKey ( key ) ) {
ViewHolder headerHolder = headerCache . get ( key ) ;
return headerCache . get ( key ) ;
if ( headerHolder = = null ) {
} else {
headerHolder = adapter . onCreateHeaderViewHolder ( parent ) ;
final ViewHolder holder = adapter . onCreateHeaderViewHolder ( parent ) ;
final View header = holder . itemView ;
//noinspection unchecked
//noinspection unchecked
adapter . onBindHeaderViewHolder ( holder , position ) ;
adapter . onBindHeaderViewHolder ( headerHolder , position ) ;
headerCache . put ( key , headerHolder ) ;
}
final View header = headerHolder . itemView ;
int widthSpec = View . MeasureSpec . makeMeasureSpec ( parent . getWidth ( ) , View . MeasureSpec . EXACTLY ) ;
int widthSpec = View . MeasureSpec . makeMeasureSpec ( parent . getWidth ( ) , View . MeasureSpec . EXACTLY ) ;
int heightSpec = View . MeasureSpec . makeMeasureSpec ( parent . getHeight ( ) , View . MeasureSpec . UNSPECIFIED ) ;
int heightSpec = View . MeasureSpec . makeMeasureSpec ( parent . getHeight ( ) , View . MeasureSpec . UNSPECIFIED ) ;
@ -96,10 +99,7 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
header . measure ( childWidth , childHeight ) ;
header . measure ( childWidth , childHeight ) ;
header . layout ( 0 , 0 , header . getMeasuredWidth ( ) , header . getMeasuredHeight ( ) ) ;
header . layout ( 0 , 0 , header . getMeasuredWidth ( ) , header . getMeasuredHeight ( ) ) ;
headerCache . put ( key , holder ) ;
return headerHolder ;
return holder ;
}
}
}
/ * *
/ * *
@ -180,10 +180,6 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
( ( LinearLayoutManager ) parent . getLayoutManager ( ) ) . getReverseLayout ( ) ;
( ( LinearLayoutManager ) parent . getLayoutManager ( ) ) . getReverseLayout ( ) ;
}
}
public void invalidateLayouts ( ) {
headerCache . clear ( ) ;
}
/ * *
/ * *
* The adapter to assist the { @link StickyHeaderDecoration } in creating and binding the header views .
* The adapter to assist the { @link StickyHeaderDecoration } in creating and binding the header views .
*
*