This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
207 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# StickyHeader | ||
The ItemDecorator is used to display sticky headers. For performance reason a header view is created only once. View types are not supported. | ||
However, you can customize this view via supplied adapter when a sticky header replaces the previous one. | ||
|
||
<img src="/images/small_demo.gif" alt="Sample" width="300px" /> | ||
|
||
Usage | ||
----- | ||
|
||
1. Add jcenter() to repositories block in your gradle file. | ||
2. Add `implementation 'com.shuhart.stickyheader:stickyheader:1.0'` to your dependencies. | ||
3. Look into the sample for additional details on how to use and configure the library. | ||
|
||
You should provide an adapter that extends [StickyAdapter](https://github.com/shuhart/StickyHeader/blob/master/stickyheader/src/main/java/com/shuhart/stickyheader/StickyAdapter.java) to the StickyHeaderItemDecorator that is used to create and bind sticky headers. | ||
|
||
|
||
After that just attach it to the RecyclerView: | ||
|
||
```java | ||
StickyHeaderItemDecorator decorator = new StickyHeaderItemDecorator(adapter); | ||
decorator.attachToRecyclerView(recyclerView); | ||
``` | ||
License | ||
======= | ||
|
||
Copyright 2018 Bogdan Kornev. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
stickyheader/src/main/java/com/shuhart/stickyheader/StickyAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.shuhart.stickyheader; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* 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 item in the adapter. | ||
*/ | ||
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. | ||
*/ | ||
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) | ||
*/ | ||
abstract SVH onCreateHeaderViewHolder(ViewGroup parent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters