ListItem.java revision 4e832ea4269fff1780e0726c16bc37584957ba10
1package androidx.car.widget;
2
3import android.support.v7.widget.RecyclerView;
4
5import java.util.function.Function;
6
7/**
8 * Definition of items that can be inserted into {@link ListItemAdapter}.
9 *
10 * @param  ViewHolder.
11 */
12public abstract class ListItem<VH extends RecyclerView.ViewHolder> {
13
14    /**
15     * Classes that extends {@code ListItem} should register its view type in
16     * {@link ListItemAdapter#registerListItemViewType(int, int, Function)}.
17     *
18     * @return type of this ListItem.
19     */
20    abstract int getViewType();
21
22    /**
23     * Called when ListItem is bound to its ViewHolder.
24     */
25    public abstract void bind(VH viewHolder);
26
27    /**
28     * @return whether the divider that comes after this ListItem should be hidden. Defaults to
29     *         false.
30     */
31    public boolean shouldHideDivider() {
32        return false;
33    };
34
35    /**
36     * Functional interface to provide a way to interact with views in {@code ViewHolder}.
37     * {@code ListItem} calls all added ViewBinders when it {@code bind}s to {@code ViewHolder}.
38     *
39     * @param  extends {@link RecyclerView.ViewHolder}.
40     */
41    public interface ViewBinder<VH extends RecyclerView.ViewHolder> {
42        /**
43         * Provides a way to interact with views in view holder.
44         */
45        void bind(VH viewHolder);
46    }
47}
48