This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
/
StickyAdapter.java
52 lines (46 loc) · 2.24 KB
/
StickyAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.shuhart.stickyheader;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
/**
* View types for a sticky header are not supported.
*/
public abstract class StickyAdapter<SVH extends RecyclerView.ViewHolder,
VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
/**
* This method gets called by {@link StickyHeaderItemDecorator} to fetch
* the position of the header item in the adapter that is used for
* (represents) item at specified position.
*
* @param itemPosition int. Adapter's position of the item for which to do
* the search of the position of the header item.
* @return int. Position of the header for an item in the adapter or
* (-1) if an item has no header.
*/
public abstract int getHeaderPositionForItem(int itemPosition);
/**
* This method gets called by {@link StickyHeaderItemDecorator} to setup the header View.
*
* @param holder RecyclerView.ViewHolder. Holder to bind the data on.
* @param headerPosition int. Position of the header item in the adapter.
*/
public abstract void onBindHeaderViewHolder(SVH holder, int headerPosition);
/**
* Called only twice when {@link StickyHeaderItemDecorator} needs
* a new {@link RecyclerView.ViewHolder} to represent a sticky header item.
* Those two instances will be cached and used to represent a current top sticky header
* and the moving one.
* <p>
* You can either create a new View manually or inflate it from an XML layout file.
* <p>
* The new ViewHolder will be used to display items of the adapter using
* {@link #onBindHeaderViewHolder(RecyclerView.ViewHolder, int)}. Since it will be re-used to display
* different items in the data set, it is a good idea to cache references to sub views of
* the View to avoid unnecessary {@link View#findViewById(int)} calls.
*
* @param parent The ViewGroup to resolve a layout params.
* @return A new ViewHolder that holds a View of the given view type.
* @see #onBindHeaderViewHolder(RecyclerView.ViewHolder, int)
*/
public abstract SVH onCreateHeaderViewHolder(ViewGroup parent);
}