Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
sample vide and usage info
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Feb 21, 2018
1 parent e9d89a6 commit 7716fe1
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 45 deletions.
38 changes: 38 additions & 0 deletions README.md
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.
Binary file added images/small_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions stickyheader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

ext {
bintrayRepo = 'StickyHeader'
bintrayName = 'stickyheader'

publishedGroupId = 'com.shuhart.stickyheader'
libraryName = 'stickyheader'
artifact = 'stickyheader'

libraryDescription = 'A simple lightweight sticky header ItemDecorator for RecyclerView'

siteUrl = 'https://github.com/shuhart/StickyHeader'
gitUrl = 'https://github.com/shuhart/StickyHeader.git'

libraryVersion = '1.0'

developerId = 'shuhart'
developerName = 'Redrick Shuhart'
developerEmail = 'kornev.b@gmail.com'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

android {
compileSdkVersion 27
Expand Down Expand Up @@ -30,3 +66,86 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}


group = publishedGroupId
version = libraryVersion

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

// Add your description here
name libraryName
description libraryDescription
url siteUrl

// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl

}
}
}
}
}

if (project.hasProperty("android")) { // Android libraries
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
}

artifacts {
archives sourcesJar
}

// Bintray
File localProps = project.rootProject.file('local.properties')

if (localProps.exists()) {
Properties properties = new Properties()
properties.load(localProps.newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
version {
name = libraryVersion
desc = libraryDescription
}
}
}
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,49 +157,4 @@ public void onGlobalLayout() {
}
});
}

/**
* View types for a sticky header are not supported.
*/
public abstract static 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);
}
}

0 comments on commit 7716fe1

Please sign in to comment.